annotate src/test-AnalysisModules/test-AnalysisModules.R @ 0:e0b5980139d9

maaslin
author george-weingart
date Tue, 13 May 2014 22:00:40 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
1 c_strDir <- file.path(getwd( ),"..")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
2
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
3 source(file.path(c_strDir,"lib","Constants.R"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
4 source(file.path(c_strDir,"lib","Utility.R"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
5
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
6 #Test Utilities
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
7 context("Test funcGetLMResults")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
8 context("Test funcGetStepPredictors")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
9
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
10 context("Test funcMakeContrasts")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
11 covX1 = c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
12 covX2 = c(144.4, 245.9, 141.9, 253.3, 144.7, 244.1, 150.7, 245.2, 160.1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
13 covX3 = as.factor(c(1,2,3,1,2,3,1,2,3))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
14 covX4 = as.factor(c(1,1,1,1,2,2,2,2,2))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
15 covX5 = as.factor(c(1,2,1,2,1,2,1,2,1))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
16 covY = c(.26, .31, .25, .50, .36, .40, .52, .28, .38)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
17 frmeTmp = data.frame(Covariate1=covX1, Covariate2=covX2, Covariate3=covX3, Covariate4=covX4, Covariate5=covX5, adCur= covY)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
18 iTaxon = 6
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
19 #Add in updating QC errors
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
20 #Add in random covariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
21 strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
22 strRandomFormula = NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
23 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
24 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
25 lsSig[[1]]$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
26 lsSig[[1]]$orig = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
27 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
28 lsSig[[1]]$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
29 lsSig[[1]]$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
30 lsSig[[1]]$metadata = covX1
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
31 vdCoef = c(Covariate1=0.6)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
32 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
33 lsSig[[1]]$std = sd(covX1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
34 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
35 ret1 = funcMakeContrasts(strFormula=strFormula, strRandomFormula=strRandomFormula, frmeTmp=frmeTmp, iTaxon=iTaxon,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
36 functionContrast=function(x,adCur,dfData)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
37 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
38 retList = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
39 ret = cor.test(as.formula(paste("~",x,"+ adCur")), data=dfData, method="spearman", na.action=c_strNA_Action)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
40 #Returning rho for the coef in a named vector
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
41 vdCoef = c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
42 vdCoef[[x]]=ret$estimate
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
43 retList[[1]]=list(p.value=ret$p.value,SD=sd(dfData[[x]]),name=x,coef=vdCoef)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
44 return(retList)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
45 }, lsQCCounts=list())
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
46 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
47 test_that("1. Test that the funcMakeContrasts works on a continuous variable.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
48 expect_equal(ret1,list(adP=round(c(0.09679784),5),lsSig=lsSig,lsQCCounts=list()))})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
49
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
50 strFormula = "adCur ~ Covariate1 + Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
51 strRandomFormula = NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
52 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
53 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
54 lsSig[[1]]$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
55 lsSig[[1]]$orig = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
56 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
57 lsSig[[1]]$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
58 lsSig[[1]]$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
59 lsSig[[1]]$metadata = covX1
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
60 vdCoef = c(Covariate1=0.6)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
61 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
62 lsSig[[1]]$std = sd(covX1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
63 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
64 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
65 lsSig[[2]]$name = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
66 lsSig[[2]]$orig = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
67 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
68 lsSig[[2]]$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
69 lsSig[[2]]$factors = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
70 lsSig[[2]]$metadata = covX2
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
71 vdCoef = c(Covariate2=0.46666667)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
72 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
73 lsSig[[2]]$std = sd(covX2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
74 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
75 ret1 = funcMakeContrasts(strFormula=strFormula, strRandomFormula=strRandomFormula, frmeTmp=frmeTmp, iTaxon=iTaxon,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
76 functionContrast=function(x,adCur,dfData)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
77 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
78 retList = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
79 ret = cor.test(as.formula(paste("~",x,"+ adCur")), data=dfData, method="spearman", na.action=c_strNA_Action)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
80 #Returning rho for the coef in a named vector
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
81 vdCoef = c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
82 vdCoef[[x]]=ret$estimate
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
83 retList[[1]]=list(p.value=ret$p.value,SD=sd(dfData[[x]]),name=x,coef=vdCoef)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
84 return(retList)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
85 }, lsQCCounts=list())
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
86 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
87 test_that("Test that the funcMakeContrasts works on 2 continuous variables.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
88 expect_equal(ret1,list(adP=round(c(0.09679784,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
89
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
90 strFormula = "adCur ~ Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
91 strRandomFormula = NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
92 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
93 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
94 lsSig[[1]]$name = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
95 lsSig[[1]]$orig = "Covariate42"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
96 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
97 lsSig[[1]]$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
98 lsSig[[1]]$factors = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
99 lsSig[[1]]$metadata = covX4 #update
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
100 vdCoef = c(Covariate42=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
101 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
102 lsSig[[1]]$std = sd(covX4) #update
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
103 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
104 # Get return
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
105 rets = funcMakeContrasts(strFormula=strFormula, strRandomFormula=strRandomFormula, frmeTmp=frmeTmp, iTaxon=iTaxon,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
106 functionContrast=function(x,adCur,dfData)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
107 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
108 retList = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
109 lmodKW = kruskal(adCur,dfData[[x]],group=FALSE,p.adj="holm")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
110 asLevels = levels(dfData[[x]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
111 # The names of the generated comparisons, sometimes the control is first sometimes it is not so
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
112 # We will just check which is in the names and use that
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
113 asComparisons = row.names(lmodKW$comparisons)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
114 #Get the comparison with the control
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
115 for(sLevel in asLevels[2:length(asLevels)])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
116 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
117 sComparison = intersect(c(paste(asLevels[1],sLevel,sep=" - "),paste(sLevel,asLevels[1],sep=" - ")),asComparisons)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
118 #Returning NA for the coef in a named vector
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
119 vdCoef = c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
120 vdCoef[[paste(x,sLevel,sep="")]]=NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
121 retList[[length(retList)+1]]=list(p.value=lmodKW$comparisons[sComparison,"p.value"],SD=NA,name=paste(x,sLevel,sep=""),coef=vdCoef)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
122 }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
123 return(retList)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
124 }, lsQCCounts=list())
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
125 rets$adP=round(rets$adP,digits=5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
126 test_that("Test that the funcMakeContrasts works on 1 factor covariate with 2 levels.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
127 expect_equal(rets,list(adP=round(c(0.24434),5),lsSig=lsSig,lsQCCounts=list()))})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
128
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
129 strFormula = "adCur ~ Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
130 strRandomFormula = NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
131 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
132 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
133 lsSig[[1]]$name = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
134 lsSig[[1]]$orig = "Covariate32"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
135 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
136 lsSig[[1]]$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
137 lsSig[[1]]$factors = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
138 lsSig[[1]]$metadata = covX3 #update
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
139 vdCoef = c(Covariate32=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
140 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
141 lsSig[[1]]$std = sd(covX3) #update
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
142 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
143 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
144 lsSig[[2]]$name = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
145 lsSig[[2]]$orig = "Covariate33"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
146 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
147 lsSig[[2]]$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
148 lsSig[[2]]$factors = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
149 lsSig[[2]]$metadata = covX3 #update
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
150 vdCoef = c(Covariate33=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
151 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
152 lsSig[[2]]$std = sd(covX3) #update
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
153 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
154 ret1 = funcMakeContrasts(strFormula=strFormula, strRandomFormula=strRandomFormula, frmeTmp=frmeTmp, iTaxon=iTaxon,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
155 functionContrast=function(x,adCur,dfData)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
156 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
157 retList = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
158 lmodKW = kruskal(adCur,dfData[[x]],group=FALSE,p.adj="holm")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
159 asLevels = levels(dfData[[x]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
160 # The names of the generated comparisons, sometimes the control is first sometimes it is not so
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
161 # We will just check which is in the names and use that
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
162 asComparisons = row.names(lmodKW$comparisons)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
163 #Get the comparison with the control
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
164 for(sLevel in asLevels[2:length(asLevels)])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
165 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
166 sComparison = intersect(c(paste(asLevels[1],sLevel,sep=" - "),paste(sLevel,asLevels[1],sep=" - ")),asComparisons)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
167 #Returning NA for the coef in a named vector
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
168 vdCoef = c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
169 vdCoef[[paste(x,sLevel,sep="")]]=NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
170 retList[[length(retList)+1]]=list(p.value=lmodKW$comparisons[sComparison,"p.value"],SD=NA,name=paste(x,sLevel,sep=""),coef=vdCoef)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
171 }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
172 return(retList)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
173 }, lsQCCounts=list())
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
174 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
175 test_that("Test that the funcMakeContrasts works on 1 factor covariate with 3 levels.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
176 expect_equal(ret1,list(adP=c(1.0,1.0),lsSig=lsSig,lsQCCounts=list()))})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
177
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
178 strFormula = "adCur ~ Covariate4 + Covariate5"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
179 strRandomFormula = NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
180 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
181 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
182 lsSig[[1]]$name = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
183 lsSig[[1]]$orig = "Covariate42"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
184 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
185 lsSig[[1]]$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
186 lsSig[[1]]$factors = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
187 lsSig[[1]]$metadata = covX4 #update
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
188 vdCoef = c(Covariate42=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
189 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
190 lsSig[[1]]$std = sd(covX4) #update
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
191 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
192 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
193 lsSig[[2]]$name = "Covariate5"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
194 lsSig[[2]]$orig = "Covariate52"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
195 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
196 lsSig[[2]]$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
197 lsSig[[2]]$factors = "Covariate5"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
198 lsSig[[2]]$metadata = covX5 #update
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
199 vdCoef = c(Covariate52=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
200 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
201 lsSig[[2]]$std = sd(covX5) #update
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
202 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
203 ret1 = funcMakeContrasts(strFormula=strFormula, strRandomFormula=strRandomFormula, frmeTmp=frmeTmp, iTaxon=iTaxon,
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
204 functionContrast=function(x,adCur,dfData)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
205 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
206 retList = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
207 lmodKW = kruskal(adCur,dfData[[x]],group=FALSE,p.adj="holm")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
208 asLevels = levels(dfData[[x]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
209 # The names of the generated comparisons, sometimes the control is first sometimes it is not so
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
210 # We will just check which is in the names and use that
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
211 asComparisons = row.names(lmodKW$comparisons)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
212 #Get the comparison with the control
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
213 for(sLevel in asLevels[2:length(asLevels)])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
214 {
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
215 sComparison = intersect(c(paste(asLevels[1],sLevel,sep=" - "),paste(sLevel,asLevels[1],sep=" - ")),asComparisons)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
216 #Returning NA for the coef in a named vector
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
217 vdCoef = c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
218 vdCoef[[paste(x,sLevel,sep="")]]=NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
219 retList[[length(retList)+1]]=list(p.value=lmodKW$comparisons[sComparison,"p.value"],SD=NA,name=paste(x,sLevel,sep=""),coef=vdCoef)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
220 }
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
221 return(retList)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
222 }, lsQCCounts=list())
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
223 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
224 test_that("1. Test that the funcMakeContrasts works on 2 factor covariate with 2 levels.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
225 expect_equal(ret1,list(adP=round(c(0.24434,0.655852),5),lsSig=lsSig,lsQCCounts=list()))})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
226
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
227
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
228 #Test Model selection
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
229
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
230
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
231 context("Test funcBoostModel")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
232 context("Test funcForwardModel")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
233 context("Test funcBackwardsModel")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
234
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
235
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
236 #Test Univariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
237 context("Test funcSpearman")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
238 strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
239 adCur = c(.26, .31, .25, .50, .36, .40, .52, .28, .38)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
240 x = c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
241 frmeTmp = data.frame(Covariate1=x, adCur=adCur)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
242 iTaxon = 2
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
243 lsQCCounts = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
244 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
245 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
246 lsSig[[1]]$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
247 lsSig[[1]]$orig = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
248 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
249 lsSig[[1]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
250 lsSig[[1]]$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
251 lsSig[[1]]$metadata = x
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
252 vdCoef = c(Covariate1=0.6)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
253 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
254 lsSig[[1]]$std = sd(x)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
255 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
256 ret1 = funcSpearman(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsQCCounts=lsQCCounts,strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
257 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
258 test_that("Test that the spearman test has the correct results for 1 covariate.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
259 expect_equal(ret1,list(adP=round(c(0.09679784),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
260 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
261
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
262 strFormula = "adCur ~ Covariate1 + Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
263 frmeTmp = data.frame(Covariate1=x, Covariate2=x, adCur=adCur)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
264 iTaxon = 3
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
265 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
266 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
267 lsSig[[1]]$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
268 lsSig[[1]]$orig = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
269 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
270 lsSig[[1]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
271 lsSig[[1]]$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
272 lsSig[[1]]$metadata = x
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
273 vdCoef = c(Covariate1=0.6)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
274 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
275 lsSig[[1]]$std = sd(x)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
276 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
277 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
278 lsSig[[2]]$name = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
279 lsSig[[2]]$orig = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
280 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
281 lsSig[[2]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
282 lsSig[[2]]$factors = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
283 lsSig[[2]]$metadata = x
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
284 vdCoef = c(Covariate2=0.6)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
285 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
286 lsSig[[2]]$std = sd(x)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
287 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
288 lsQCCounts = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
289 ret1 = funcSpearman(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsQCCounts=lsQCCounts,strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
290 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
291 test_that("Test that the spearman test has the correct results for 2 covariates.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
292 expect_equal(ret1,list(adP=round(c(0.09679784,0.09679784),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
293 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
294
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
295
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
296 context("Test funcWilcoxon")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
297 strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
298 x = c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,FALSE)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
299 frmeTmp = data.frame(Covariate1=x, adCur=adCur)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
300 iTaxon = 2
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
301 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
302 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
303 lsSig[[1]]$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
304 lsSig[[1]]$orig = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
305 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
306 lsSig[[1]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
307 lsSig[[1]]$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
308 lsSig[[1]]$metadata = x
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
309 vdCoef = c(Covariate1=13)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
310 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
311 lsSig[[1]]$std = sd(x)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
312 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
313 lsQCCounts = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
314 ret1 = funcWilcoxon(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsQCCounts=lsQCCounts,strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
315 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
316 test_that("Test that the wilcoxon test has the correct results for 1 covariate.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
317 expect_equal(ret1,list(adP=round(c(0.55555556),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
318 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
319
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
320
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
321 context("Test funcKruskalWallis")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
322 strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
323 x = as.factor(c("one","two","three","one","one","three","two","three","two"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
324 frmeTmp = data.frame(Covariate1=x, adCur=adCur)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
325 iTaxon = 2
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
326 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
327 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
328 lsSig[[1]]$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
329 lsSig[[1]]$orig = "Covariate1three"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
330 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
331 lsSig[[1]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
332 lsSig[[1]]$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
333 lsSig[[1]]$metadata = x
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
334 vdCoef = c(Covariate1three=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
335 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
336 lsSig[[1]]$std = sd(x)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
337 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
338 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
339 lsSig[[2]]$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
340 lsSig[[2]]$orig = "Covariate1two"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
341 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
342 lsSig[[2]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
343 lsSig[[2]]$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
344 lsSig[[2]]$metadata = x
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
345 vdCoef = c(Covariate1two=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
346 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
347 lsSig[[2]]$std = sd(x)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
348 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
349 lsQCCounts = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
350 ret1 = funcKruskalWallis(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsQCCounts=lsQCCounts,strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
351 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
352 test_that("Test that the Kruskal Wallis (Nonparameteric anova) has the correct results for 1 covariate.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
353 expect_equal(ret1,list(adP=c(1.0,1.0),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
354 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
355
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
356
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
357 context("test funcDoUnivariate")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
358 covX1 = c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
359 covX2 = c(144.4, 245.9, 141.9, 253.3, 144.7, 244.1, 150.7, 245.2, 160.1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
360 covX3 = as.factor(c(1,2,3,1,2,3,1,2,3))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
361 covX4 = as.factor(c(1,1,1,1,2,2,2,2,2))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
362 covX5 = as.factor(c(1,2,1,2,1,2,1,2,1))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
363 covX6 = as.factor(c("one","two","three","one","one","three","two","three","two"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
364 covY = c(.26, .31, .25, .50, .36, .40, .52, .28, .38)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
365 frmeTmp = data.frame(Covariate1=covX1, Covariate2=covX2, Covariate3=covX3, Covariate4=covX4, Covariate5=covX5, Covariate6=covX6, adCur= covY)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
366 iTaxon = 7
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
367 # 1 cont answer
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
368 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
369 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
370 lsSig[[1]]$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
371 lsSig[[1]]$orig = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
372 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
373 lsSig[[1]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
374 lsSig[[1]]$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
375 lsSig[[1]]$metadata = frmeTmp[["Covariate1"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
376 vdCoef = c(Covariate1=0.6)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
377 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
378 lsSig[[1]]$std = sd(frmeTmp[["Covariate1"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
379 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
380 lsHistory = list(adP=c(), lsSig=c(),lsQCCounts=list())
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
381 ret1 = funcDoUnivariate(strFormula="adCur ~ Covariate1",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
382 ret2 = funcDoUnivariate(strFormula=NULL,frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate1")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
383 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
384 ret2$adP = round(ret2$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
385 print("ret1")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
386 print(ret1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
387 print("list(adP=round(c(0.09679784),5),lsSig=lsSig,lsQCCounts=list())")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
388 print(list(adP=round(c(0.09679784),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
389 test_that("2. Test that the funcMakeContrasts works on a continuous variable.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
390 expect_equal(ret1,list(adP=round(c(0.09679784),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
391 expect_equal(ret2,list(adP=round(c(0.09679784),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
392 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
393 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
394 lsSig[[2]]$name = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
395 lsSig[[2]]$orig = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
396 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
397 lsSig[[2]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
398 lsSig[[2]]$factors = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
399 lsSig[[2]]$metadata = frmeTmp[["Covariate2"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
400 vdCoef = c(Covariate2=0.46666667)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
401 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
402 lsSig[[2]]$std = sd(frmeTmp[["Covariate2"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
403 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
404 ret1 = funcDoUnivariate(strFormula="adCur ~ Covariate1 + Covariate2",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory,strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
405 ret2 = funcDoUnivariate(strFormula=NULL,frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate1 + 1|Covariate2")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
406 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
407 ret2$adP = round(ret2$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
408 test_that("Test that the funcMakeContrasts works on 2 continuous variables.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
409 expect_equal(ret1,list(adP=round(c(0.09679784,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
410 expect_equal(ret2,list(adP=round(c(0.09679784,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
411 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
412 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
413 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
414 lsSig[[1]]$name = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
415 lsSig[[1]]$orig = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
416 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
417 lsSig[[1]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
418 lsSig[[1]]$factors = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
419 lsSig[[1]]$metadata = frmeTmp[["Covariate4"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
420 vdCoef = c(Covariate4=5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
421 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
422 lsSig[[1]]$std = sd(frmeTmp[["Covariate4"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
423 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
424 ret1 = funcDoUnivariate(strFormula="adCur ~ Covariate4",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory,strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
425 ret2 = funcDoUnivariate(strFormula=NULL,frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate4")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
426 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
427 ret2$adP = round(ret2$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
428 test_that("Test that the funcMakeContrasts works on 1 factor covariate with 2 levels.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
429 expect_equal(ret1,list(adP=round(c(0.2857143),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
430 expect_equal(ret2,list(adP=round(c(0.2857143),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
431 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
432 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
433 lsSig[[2]]$name = "Covariate5"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
434 lsSig[[2]]$orig = "Covariate5"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
435 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
436 lsSig[[2]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
437 lsSig[[2]]$factors = "Covariate5"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
438 lsSig[[2]]$metadata = frmeTmp[["Covariate5"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
439 vdCoef = c(Covariate5=8)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
440 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
441 lsSig[[2]]$std = sd(frmeTmp[["Covariate5"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
442 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
443 ret1 = funcDoUnivariate(strFormula="adCur ~ Covariate4 + Covariate5",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
444 ret2 = funcDoUnivariate(strFormula=NULL,frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate4 + 1|Covariate5")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
445 ret3 = funcDoUnivariate(strFormula="adCur ~ Covariate4",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate5")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
446 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
447 ret2$adP = round(ret2$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
448 ret3$adP = round(ret3$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
449 test_that("2. Test that the funcMakeContrasts works on 2 factor covariate with 2 levels.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
450 expect_equal(ret1,list(adP=round(c(0.2857143,0.73016),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
451 expect_equal(ret2,list(adP=round(c(0.2857143,0.73016),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
452 expect_equal(ret3,list(adP=round(c(0.2857143,0.73016),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
453 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
454 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
455 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
456 lsSig[[1]]$name = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
457 lsSig[[1]]$orig = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
458 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
459 lsSig[[1]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
460 lsSig[[1]]$factors = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
461 lsSig[[1]]$metadata = frmeTmp[["Covariate4"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
462 vdCoef = c(Covariate4=5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
463 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
464 lsSig[[1]]$std = sd(frmeTmp[["Covariate4"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
465 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
466 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
467 lsSig[[2]]$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
468 lsSig[[2]]$orig = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
469 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
470 lsSig[[2]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
471 lsSig[[2]]$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
472 lsSig[[2]]$metadata = frmeTmp[["Covariate1"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
473 vdCoef = c(Covariate1=0.6)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
474 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
475 lsSig[[2]]$std = sd(frmeTmp[["Covariate1"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
476 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
477 ret1 = funcDoUnivariate(strFormula="adCur ~ Covariate4 + Covariate1",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
478 ret2 = funcDoUnivariate(strFormula=NULL,frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate4 + 1|Covariate1")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
479 ret3 = funcDoUnivariate(strFormula="adCur ~ Covariate4",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate1")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
480 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
481 ret2$adP = round(ret2$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
482 ret3$adP = round(ret3$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
483 test_that("Test that the funcMakeContrasts works on 1 factor covariate with 2 levels and a continuous variable.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
484 expect_equal(ret1,list(adP=round(c(0.2857143,0.09679784),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
485 expect_equal(ret2,list(adP=round(c(0.2857143,0.09679784),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
486 expect_equal(ret3,list(adP=round(c(0.2857143,0.09679784),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
487 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
488 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
489 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
490 lsSig[[1]]$name = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
491 lsSig[[1]]$orig = "Covariate32"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
492 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
493 lsSig[[1]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
494 lsSig[[1]]$factors = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
495 lsSig[[1]]$metadata = frmeTmp[["Covariate3"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
496 vdCoef = c(Covariate32=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
497 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
498 lsSig[[1]]$std = sd(frmeTmp[["Covariate3"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
499 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
500 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
501 lsSig[[2]]$name = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
502 lsSig[[2]]$orig = "Covariate33"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
503 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
504 lsSig[[2]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
505 lsSig[[2]]$factors = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
506 lsSig[[2]]$metadata = frmeTmp[["Covariate3"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
507 vdCoef = c(Covariate33=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
508 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
509 lsSig[[2]]$std = sd(frmeTmp[["Covariate3"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
510 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
511 lsSig[[3]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
512 lsSig[[3]]$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
513 lsSig[[3]]$orig = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
514 lsSig[[3]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
515 lsSig[[3]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
516 lsSig[[3]]$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
517 lsSig[[3]]$metadata = frmeTmp[["Covariate1"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
518 vdCoef = c(Covariate1=0.6)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
519 lsSig[[3]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
520 lsSig[[3]]$std = sd(frmeTmp[["Covariate1"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
521 lsSig[[3]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
522 lsSig[[4]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
523 lsSig[[4]]$name = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
524 lsSig[[4]]$orig = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
525 lsSig[[4]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
526 lsSig[[4]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
527 lsSig[[4]]$factors = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
528 lsSig[[4]]$metadata = frmeTmp[["Covariate2"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
529 vdCoef = c(Covariate2=0.46666667)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
530 lsSig[[4]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
531 lsSig[[4]]$std = sd(frmeTmp[["Covariate2"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
532 lsSig[[4]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
533 ret1 = funcDoUnivariate(strFormula="adCur ~ Covariate3 + Covariate1 + Covariate2",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
534 ret2 = funcDoUnivariate(strFormula=NULL,frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate3 + 1|Covariate1 + 1|Covariate2")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
535 ret3 = funcDoUnivariate(strFormula="adCur ~ Covariate3 + Covariate1",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate2")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
536 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
537 ret2$adP = round(ret2$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
538 ret3$adP = round(ret3$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
539 test_that("Test that the funcMakeContrasts works on 1 factor covariate with 3 levels and 2 continuous variables.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
540 expect_equal(ret1,list(adP=round(c(1.0,1.0,0.09679784,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
541 expect_equal(ret2,list(adP=round(c(1.0,1.0,0.09679784,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
542 expect_equal(ret3,list(adP=round(c(1.0,1.0,0.09679784,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
543 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
544 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
545 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
546 lsSig[[1]]$name = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
547 lsSig[[1]]$orig = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
548 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
549 lsSig[[1]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
550 lsSig[[1]]$factors = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
551 lsSig[[1]]$metadata = frmeTmp[["Covariate4"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
552 vdCoef = c(Covariate4=5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
553 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
554 lsSig[[1]]$std = sd(frmeTmp[["Covariate4"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
555 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
556 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
557 lsSig[[2]]$name = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
558 lsSig[[2]]$orig = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
559 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
560 lsSig[[2]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
561 lsSig[[2]]$factors = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
562 lsSig[[2]]$metadata = frmeTmp[["Covariate2"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
563 vdCoef = c(Covariate2=0.46666667)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
564 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
565 lsSig[[2]]$std = sd(frmeTmp[["Covariate2"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
566 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
567 ret1 = funcDoUnivariate(strFormula="adCur ~ Covariate4 + Covariate2",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
568 ret2 = funcDoUnivariate(strFormula=NULL,frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate4 + 1|Covariate2")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
569 ret3 = funcDoUnivariate(strFormula= "adCur ~ Covariate4",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate2")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
570 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
571 ret2$adP = round(ret2$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
572 ret3$adP = round(ret3$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
573 test_that("3. Test that the funcMakeContrasts works on 2 factor covariate with 2 levels and a continuous variable.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
574 expect_equal(ret1,list(adP=round(c(0.2857143,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
575 expect_equal(ret2,list(adP=round(c(0.2857143,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
576 expect_equal(ret3,list(adP=round(c(0.2857143,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
577 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
578 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
579 lsSig[[1]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
580 lsSig[[1]]$name = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
581 lsSig[[1]]$orig = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
582 lsSig[[1]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
583 lsSig[[1]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
584 lsSig[[1]]$factors = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
585 lsSig[[1]]$metadata = frmeTmp[["Covariate4"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
586 vdCoef = c(Covariate4=5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
587 lsSig[[1]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
588 lsSig[[1]]$std = sd(frmeTmp[["Covariate4"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
589 lsSig[[1]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
590 lsSig[[2]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
591 lsSig[[2]]$name = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
592 lsSig[[2]]$orig = "Covariate32"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
593 lsSig[[2]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
594 lsSig[[2]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
595 lsSig[[2]]$factors = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
596 lsSig[[2]]$metadata = frmeTmp[["Covariate3"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
597 vdCoef = c(Covariate32=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
598 lsSig[[2]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
599 lsSig[[2]]$std = sd(frmeTmp[["Covariate3"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
600 lsSig[[2]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
601 lsSig[[3]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
602 lsSig[[3]]$name = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
603 lsSig[[3]]$orig = "Covariate33"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
604 lsSig[[3]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
605 lsSig[[3]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
606 lsSig[[3]]$factors = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
607 lsSig[[3]]$metadata = frmeTmp[["Covariate3"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
608 vdCoef = c(Covariate33=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
609 lsSig[[3]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
610 lsSig[[3]]$std = sd(frmeTmp[["Covariate3"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
611 lsSig[[3]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
612 lsSig[[4]] = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
613 lsSig[[4]]$name = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
614 lsSig[[4]]$orig = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
615 lsSig[[4]]$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
616 lsSig[[4]]$data = adCur
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
617 lsSig[[4]]$factors = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
618 lsSig[[4]]$metadata = frmeTmp[["Covariate2"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
619 vdCoef = c(Covariate2=0.46666667)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
620 lsSig[[4]]$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
621 lsSig[[4]]$std = sd(frmeTmp[["Covariate2"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
622 lsSig[[4]]$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
623 ret1 = funcDoUnivariate(strFormula="adCur ~ Covariate4 + Covariate3 + Covariate2",frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula=NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
624 ret2 = funcDoUnivariate(strFormula=NULL,frmeTmp=frmeTmp,iTaxon=iTaxon, lsHistory=lsHistory, strRandomFormula="adCur ~ 1|Covariate4 +1|Covariate3 + 1|Covariate2")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
625 ret1$adP = round(ret1$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
626 ret2$adP = round(ret2$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
627 test_that("Test that the funcMakeContrasts works on 1 factor covariate with 2 levels , 1 factor with 3 levels, and a continuous variable.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
628 expect_equal(ret1,list(adP=round(c(0.2857143,1.0,1.0,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
629 expect_equal(ret2,list(adP=round(c(0.2857143,1.0,1.0,0.21252205),5),lsSig=lsSig,lsQCCounts=list()))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
630 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
631
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
632 #Test multivariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
633 context("Test funcLasso")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
634
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
635
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
636 context("Test funcLM")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
637 #This test just makes sure the statistical method is being called correctly for one covariate with the correct return
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
638 strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
639 strRandomFormula = NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
640 x = c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
641 x2 = c(34.2, 32.5, 22.4, 43, 3.25, 6.4, 7, 87, 9)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
642 xf1 = c(1,1,2,2,1,2,1,1,2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
643 xf2 = c(1,1,1,1,2,2,2,2,2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
644 frmeTmp = data.frame(Covariate1=x, Covariate2=x2, FCovariate3=xf1, FCovariate4=xf2, adCur=adCur)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
645 iTaxon = 5
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
646 lmRet = lm(as.formula(strFormula), data=frmeTmp, na.action = c_strNA_Action)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
647 test_that("Test that the lm has the correct results for 1 covariate.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
648 expect_equal(funcLM(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
649 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
650 #Test for correct call for 2 covariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
651 strFormula = "adCur ~ Covariate1 + Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
652 lmRet = lm(as.formula(strFormula), data=frmeTmp, na.action = c_strNA_Action)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
653 test_that("Test that the lm has the correct results for 2 covariates.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
654 expect_equal(funcLM(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
655 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
656 ##Test for correct call with 1 random and one fixed covariate
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
657 #strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
658 #strRandomFormula = "~1|FCovariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
659 #lmRet = glmmPQL(fixed=as.formula(strFormula), random=as.formula(strRandomFormula), family=gaussian(link="identity"), data=frmeTmp)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
660 #test_that("Test that the lm has the correct results for 1 random and one fixed covariate.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
661 # expect_equal(funcLM(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
662 #})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
663 ##Test for correct call with 1 random and 2 fixed covariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
664 #strFormula = "adCur ~ Covariate1 + Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
665 #strRandomFormula = "~1|FCovariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
666 #lmRet = glmmPQL(fixed=as.formula(strFormula), random=as.formula(strRandomFormula), family=gaussian(link="identity"), data=frmeTmp)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
667 #test_that("Test that the lm has the correct results for 1 random and 2 fixed covariates.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
668 # expect_equal(funcLM(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
669 #})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
670 ##Test for correct call with 2 random and 1 fixed covariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
671 #strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
672 #strRandomFormula = "~1|FCovariate4+1|FCovariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
673 #lmRet = glmmPQL(fixed=as.formula(strFormula), random=as.formula(strRandomFormula), family=gaussian(link="identity"), data=frmeTmp)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
674 #test_that("Test that the lm has the correct results for 2 random and 1 fixed covariates.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
675 # expect_equal(funcLM(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
676 #})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
677
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
678
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
679 context("Test funcBinomialMult")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
680 strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
681 strRandomFormula = NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
682 x = c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
683 x2 = c(34.2, 32.5, 22.4, 43, 3.25, 6.4, 7, 87, 9)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
684 xf1 = c(1,1,2,2,1,2,1,1,2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
685 xf2 = c(1,1,1,1,2,2,2,2,2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
686 frmeTmp = data.frame(Covariate1=x, Covariate2=x2, FCovariate3=xf1, FCovariate4=xf2, adCur=adCur)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
687 iTaxon = 5
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
688 lmRet = glm(as.formula(strFormula), family=binomial(link=logit), data=frmeTmp, na.action=c_strNA_Action)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
689 test_that("Test that the neg binomial regression has the correct results for 1 covariate.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
690 expect_equal(funcBinomialMult(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
691 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
692 #Test for correct call for 2 covariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
693 strFormula = "adCur ~ Covariate1 + Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
694 iTaxon = 5
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
695 lmRet = glm(as.formula(strFormula), family=binomial(link=logit), data=frmeTmp, na.action=c_strNA_Action)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
696 test_that("Test that the neg binomial regression has the correct results for 2 covariates.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
697 expect_equal(funcBinomialMult(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
698 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
699 ##Test for correct call with 1 random and one fixed covariate
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
700 #strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
701 #strRandomFormula = "~1|FCovariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
702 #lmRet = glmmPQL(fixed=as.formula(strFormula), random=as.formula(strRandomFormula), family=binomial(link=logit), data=frmeTmp)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
703 #test_that("Test that the lm has the correct results for 1 random and one fixed covariate.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
704 # expect_equal(funcBinomialMult(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
705 #})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
706 ##Test for correct call with 1 random and 2 fixed covariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
707 #strFormula = "adCur ~ Covariate1 + Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
708 #strRandomFormula = "~1|FCovariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
709 #lmRet = glmmPQL(fixed=as.formula(strFormula), random=as.formula(strRandomFormula), family=binomial(link=logit), data=frmeTmp)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
710 #test_that("Test that the lm has the correct results for 1 random and 2 fixed covariates.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
711 # expect_equal(funcBinomialMult(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
712 #})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
713 ##Test for correct call with 2 random and 1 fixed covariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
714 #strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
715 #strRandomFormula = "~1|FCovariate4+1|FCovariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
716 #lmRet = glmmPQL(fixed=as.formula(strFormula), random=as.formula(strRandomFormula), family=binomial(link=logit), data=frmeTmp)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
717 #test_that("Test that the lm has the correct results for 2 random and 1 fixed covariates.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
718 # expect_equal(funcBinomialMult(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
719 #})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
720
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
721
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
722 context("Test funcQuasiMult")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
723 strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
724 strRandomFormula = NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
725 x = c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1,44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
726 x2 = c(34.2, 32.5, 22.4, 43, 3.25, 6.4, 7, 87, 9,34.2, 32.5, 22.4, 43, 3.25, 6.4, 7, 87, 9)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
727 xf1 = c(1,1,2,2,1,1,2,2,2,1,1,2,2,1,1,2,2,2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
728 xf2 = c(1,1,1,1,2,2,2,2,2,1,1,1,1,2,2,2,2,2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
729 frmeTmp = data.frame(Covariate1=x, Covariate2=x2, FCovariate3=xf1, FCovariate4=xf2, adCur=adCur)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
730 iTaxon = 5
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
731 lmRet = glm(as.formula(strFormula), family=quasipoisson, data=frmeTmp, na.action=c_strNA_Action)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
732 test_that("Test that the quasi poisson has the correct results for 1 covariate.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
733 expect_equal(funcQuasiMult(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
734 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
735 #Test for correct call for 2 covariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
736 strFormula = "adCur ~ Covariate1 + Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
737 iTaxon = 5
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
738 lmRet = glm(as.formula(strFormula), family=quasipoisson, data=frmeTmp, na.action=c_strNA_Action)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
739 test_that("Test that the quasi poisson has the correct results for 2 covariates.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
740 expect_equal(funcQuasiMult(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
741 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
742 ##Test for correct call with 1 random and one fixed covariate
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
743 #strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
744 #strRandomFormula = "~1|FCovariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
745 #lmRet = glmmPQL(fixed=as.formula(strFormula), random=as.formula(strRandomFormula), family=quasipoisson, data=frmeTmp)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
746 #test_that("Test that the lm has the correct results for 1 random and one fixed covariate.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
747 # expect_equal(funcQuasiMult(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
748 #})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
749 ##Test for correct call with 1 random and 2 fixed covariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
750 #strFormula = "adCur ~ Covariate1 + Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
751 #strRandomFormula = "~1|FCovariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
752 #lmRet = glmmPQL(fixed=as.formula(strFormula), random=as.formula(strRandomFormula), family=quasipoisson, data=frmeTmp)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
753 #test_that("Test that the lm has the correct results for 1 random and 2 fixed covariates.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
754 # expect_equal(funcQuasiMult(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
755 #})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
756 ##Test for correct call with 2 random and 1 fixed covariates
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
757 #strFormula = "adCur ~ Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
758 #strRandomFormula = "~1|FCovariate4+1|FCovariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
759 #lmRet = glmmPQL(fixed=as.formula(strFormula), random=as.formula(strRandomFormula), family=quasipoisson, data=frmeTmp)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
760 #test_that("Test that the lm has the correct results for 2 random and 1 fixed covariates.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
761 # expect_equal(funcQuasiMult(strFormula=strFormula,frmeTmp=frmeTmp,iTaxon=iTaxon,lsHistory=lsHistory,strRandomFormula=strRandomFormula),lmRet)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
762 #})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
763
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
764
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
765 #Test transforms
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
766 context("Test funcNoTransform")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
767 aTest1 = c(NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
768 aTest2 = c(NULL)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
769 aTest3 = c(0.5,1.4,2.4,3332.4,0.0,0.0000003)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
770 aTest4 = c(0.1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
771 test_that("Test that no transform does not change the data.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
772 expect_equal(funcNoTransform(aTest1), aTest1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
773 expect_equal(funcNoTransform(aTest2), aTest2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
774 expect_equal(funcNoTransform(aTest3), aTest3)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
775 expect_equal(funcNoTransform(aTest4), aTest4)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
776 })
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
777
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
778
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
779 context("Test funcArcsinSqrt")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
780 aTest1 = c(NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
781 aTest2 = c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
782 aTest3 = c(0.000001)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
783 test_that("Test that funcArcsinSqrt performs the transform correctly.",{
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
784 expect_equal(funcArcsinSqrt(NA), as.numeric(NA))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
785 expect_equal(funcArcsinSqrt(aTest1), asin(sqrt(aTest1)))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
786 expect_equal(funcArcsinSqrt(aTest2), asin(sqrt(aTest2)))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
787 expect_equal(funcArcsinSqrt(aTest3), asin(sqrt(aTest3)))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
788 })