Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial, not working, placeholder #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions shinyApp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# shinytw2

Shiny App for TW2
https://github.com/alekseyenko/Tw2

96 changes: 96 additions & 0 deletions shinyApp/Tw2copy.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
is.dist = function(x) any(class(x)=='dist')

WT.mean = function(dm, f){
if(nlevels(f) != 2) return(NULL)
lev = levels(f)
ns = summary(f)
N = sum(ns)
dd = as.matrix(dm)
dd[upper.tri(dd)]=0 ##
SST = sum(dd^2)/N
SSW1 = sum(dd[f==lev[1],f==lev[1]]^2)/ns[1]
SSW2 = sum(dd[f==lev[2],f==lev[2]]^2)/ns[2]
SSW = SSW1 + SSW2

(sqrt((ns[1]+ns[2])/(ns[1]*ns[2])))*sqrt(SST-SSW)
}


dist.sigma2 = function(dm){
dd = as.matrix(dm)
dd[upper.tri(dd)]=0 ##
sum(dd^2)/nrow(dm)/(nrow(dm)-1)
}

dist.cohen.d = function(dm, f){
mean.diff = sqrt(WT.mean(dm, f))
lev = levels(f)
s1 = dist.sigma2(as.matrix(dm)[f==lev[1], f == lev[1]])
s2 = dist.sigma2(as.matrix(dm)[f==lev[1], f == lev[1]])
ns=table(f)
mean.diff/sqrt(((ns[1]-1)*s1 + (ns[2]-1)*s2)/(sum(ns)-2))
}

# dist.cohen.d.strata = function(dm, f, strata){
# p = unlist(tapply(f,strata,sample))
# p2 = unlist(tapply(1:length(f), strata, identity))
# # mean.diff = sqrt(WT.mean(dm, f))
# mean.diff.strata = sqrt(WT.mean(dm, f[p[p2]]))
# lev = levels(f)
# s1 = dist.sigma2(as.matrix(dm)[f==lev[1], f == lev[1]])
# s2 = dist.sigma2(as.matrix(dm)[f==lev[1], f == lev[1]])
# ns=table(f)
# mean.diff.strata/sqrt(((ns[1]-1)*s1 + (ns[2]-1)*s2)/(sum(ns)-2))
# }

WT = function(dm, f){
if(nlevels(f) != 2) return(NULL)
lev = levels(f)
ns = summary(f)
N = sum(ns)
dd = as.matrix(dm)
dd[upper.tri(dd)]=0 ##
SST = sum(dd^2)/N
SSW1 = sum(dd[f==lev[1],f==lev[1]]^2)/ns[1]
SSW2 = sum(dd[f==lev[2],f==lev[2]]^2)/ns[2]
SSW = SSW1 + SSW2

s1 = SSW1/(ns[1]-1)
s2 = SSW2/(ns[2]-1)

t.stat = (sqrt((ns[1]+ns[2])/(ns[1]*ns[2])))*sqrt(SST-SSW)/sqrt(s1/ns[1] + s2/ns[2])
if(is.na(t.stat)){ ## SST - SSW must be negative
t.stat = 0
}
t.stat
}

# WT.test = function(dm, f, nrep=999){
# stats = c(WT(dm, f), replicate(nrep, WT(dm, f[sample(length(f))])))
# p.value = sum(stats>=stats[1])/(nrep+1)
# t.stat = stats[1]
# list(p.value = p.value, t.stat = t.stat, nrep=nrep)
# }

strata.permute = function(f, strata){
p = unlist(tapply(f,strata,sample))
p2 = unlist(tapply(1:length(f), strata, identity))
f[p[p2]]
}

WT.test = function(dm, f, strata, nrep=999){
stats = c(WT(dm, f),
replicate(nrep,
WT(dm, strata.permute(f, strata))
)
)
p.value = sum(stats>=stats[1])/(nrep+1)
t.stat = stats[1]
list(p.value = p.value, t.stat = t.stat, nrep=nrep)
}

#Wstar.test=function(dm, f, nrep=999){
## This method is not currently implemented.
## The function is provided as a placeholder.
# list(p.value = 1, Wstar = "Unimplemented", nrep=nrep)
#}
2,401 changes: 2,401 additions & 0 deletions shinyApp/data/raw_count.csv

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions shinyApp/data/sample_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"","id_full","id","TreatmentGroup","trimester3_1","ethnicity_all","ethnicity_HispVSNonhisp","ethnicity_CaucVSAA","ethnicity_CaucVSHisp","bmi_class_all","bmi_normalvsow","bmi_normalvsobese","parity_all","parity_0vs1","parity_0vs2","iom_weight"
"1","5248-1",5248,"early",0,"Cau","non-Hispanic","Caucasian","Caucasian","underweight/normal","underweight/normal","underweight/normal","1","one previous birth",NA,"inadequate weight gain"
"2","5248-2",5248,"late",1,"Cau","non-Hispanic","Caucasian","Caucasian","underweight/normal","underweight/normal","underweight/normal","1","one previous birth",NA,"inadequate weight gain"
"3","5278-1",5278,"early",0,"Cau","non-Hispanic","Caucasian","Caucasian","overweight","overweight",NA,"0","no previous births","no previous births","excessive weight gain"
"4","5278-2",5278,"late",1,"Cau","non-Hispanic","Caucasian","Caucasian","overweight","overweight",NA,"0","no previous births","no previous births","excessive weight gain"
"5","5285-1",5285,"early",0,"Cau","non-Hispanic","Caucasian","Caucasian","underweight/normal","underweight/normal","underweight/normal","2+",NA,"two or more previous birth","inadequate weight gain"
"6","5285-2",5285,"late",1,"Cau","non-Hispanic","Caucasian","Caucasian","underweight/normal","underweight/normal","underweight/normal","2+",NA,"two or more previous birth","inadequate weight gain"
"9","5294-1",5294,"early",0,"Cau","non-Hispanic","Caucasian","Caucasian","obese",NA,"obese","1","one previous birth",NA,"inadequate weight gain"
"10","5294-2",5294,"late",1,"Cau","non-Hispanic","Caucasian","Caucasian","obese",NA,"obese","1","one previous birth",NA,"inadequate weight gain"
"11","5301-1",5301,"early",0,"Hisp","Hispanic",NA,"Hispanic","underweight/normal","underweight/normal","underweight/normal","1","one previous birth",NA,"inadequate weight gain"
"12","5301-2",5301,"late",1,"Hisp","Hispanic",NA,"Hispanic","underweight/normal","underweight/normal","underweight/normal","1","one previous birth",NA,"inadequate weight gain"
12 changes: 12 additions & 0 deletions shinyApp/global.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
library(phyloseq)
library(tidyverse)
library(shiny)
library(shinydashboard)
library(shinyjs)
library(DT)

#source("https://raw.githubusercontent.com/alekseyenko/Tw2/master/code/Tw2.R")
source("Tw2copy.R")

distance_choices <- phyloseq::distanceMethodList

2 changes: 2 additions & 0 deletions shinyApp/install.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source("https://raw.githubusercontent.com/joey711/phyloseq/master/inst/scripts/installer.R",
local = TRUE)
Binary file added shinyApp/phy.rds
Binary file not shown.
Loading