comparison maaslin-4450aa4ecc84/src/test-AnalysisModules/test-AnalysisModules.R @ 1:a87d5a5f2776

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