annotate src/test-BoostGLM/test-BoostGLM.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 source(file.path(c_strDir,"lib","AnalysisModules.R"))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
6
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
7 # General setup
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
8 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
9 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
10 covX3 = as.factor(c(1,2,3,1,2,3,1,2,3))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
11 covX4 = as.factor(c(1,1,1,1,2,2,2,2,2))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
12 covX5 = as.factor(c(1,2,1,2,1,2,1,2,1))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
13 covY = c(.26, .31, .25, .50, .36, .40, .52, .28, .38)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
14 frmeTmp = data.frame(Covariate1=covX1, Covariate2=covX2, Covariate3=covX3, Covariate4=covX4, Covariate5=covX5, adCur= covY)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
15 iTaxon = 6
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
16
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
17 lsCov1 = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
18 lsCov1$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
19 lsCov1$orig = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
20 lsCov1$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
21 lsCov1$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
22 lsCov1$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
23 lsCov1$metadata = covX1
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
24 vdCoef = c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
25 vdCoef["(Intercept)"]=round(0.0345077486,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
26 vdCoef["Covariate1"]= round(0.0052097355,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
27 vdCoef["Covariate2"]= round(0.0005806568,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
28 vdCoef["Covariate32"]=round(-0.1333421874,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
29 vdCoef["Covariate33"]=round(-0.1072006419,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
30 vdCoef["Covariate42"]=round(0.0849198280,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
31 lsCov1$value = c(Covariate1=round(0.005209736,5))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
32 lsCov1$std = round(0.0063781728,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
33 lsCov1$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
34 lsCov2 = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
35 lsCov2$name = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
36 lsCov2$orig = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
37 lsCov2$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
38 lsCov2$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
39 lsCov2$factors = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
40 lsCov2$metadata = covX2
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
41 lsCov2$value = c(Covariate2=round(0.0005806568,5))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
42 lsCov2$std = round(0.0006598436,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
43 lsCov2$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
44 lsCov3 = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
45 lsCov3$name = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
46 lsCov3$orig = "Covariate32"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
47 lsCov3$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
48 lsCov3$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
49 lsCov3$factors = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
50 lsCov3$metadata = covX3
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
51 lsCov3$value = c(Covariate32=round(-0.1333422,5))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
52 lsCov3$std = round(0.0895657826,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
53 lsCov3$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
54 lsCov4 = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
55 lsCov4$name = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
56 lsCov4$orig = "Covariate33"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
57 lsCov4$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
58 lsCov4$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
59 lsCov4$factors = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
60 lsCov4$metadata = covX3
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
61 lsCov4$value = c(Covariate33=round(-0.1072006,5))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
62 lsCov4$std = round(0.0792209541,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
63 lsCov4$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
64 lsCov5 = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
65 lsCov5$name = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
66 lsCov5$orig = "Covariate42"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
67 lsCov5$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
68 lsCov5$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
69 lsCov5$factors = "Covariate4"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
70 lsCov5$metadata = covX4
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
71 lsCov5$value = c(Covariate42=round(0.08491983,5))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
72 lsCov5$std = round(0.0701018621,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
73 lsCov5$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
74
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
75 context("Test funcClean")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
76
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
77 context("Test funcBugHybrid")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
78 # multiple covariates, one call lm
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
79 aiMetadata = c(1:5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
80 aiData = c(iTaxon)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
81 dFreq = 0.5 / length( aiMetadata )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
82 dSig = 0.25
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
83 dMinSamp = 0.1
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
84 adP = c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
85 lsSig = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
86 funcReg = NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
87 funcAnalysis = funcLM
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
88 funcGetResult = funcGetLMResults
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
89 lsData = list(frmeData=frmeTmp, aiMetadata=aiMetadata, aiData=aiData, lsQCCounts=list())
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
90 lsData$astrMetadata = names(frmeTmp)[aiMetadata]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
91
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
92 adPExpected = round(c(0.4738687,0.4436566,0.4665972,0.5378693,0.3124672),5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
93 QCExpected = list(iLms=numeric(0))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
94 lsSigExpected = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
95 lsSigExpected[[1]] = lsCov1
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
96 lsSigExpected[[2]] = lsCov2
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
97 lsSigExpected[[3]] = lsCov3
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
98 lsSigExpected[[4]] = lsCov4
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
99 lsSigExpected[[5]] = lsCov5
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
100 expectedReturn = list(adP=adPExpected,lsSig=lsSigExpected,lsQCCounts=QCExpected)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
101 receivedReturn = funcBugHybrid(iTaxon=iTaxon,frmeData=frmeTmp,lsData=lsData,aiMetadata=aiMetadata,dFreq=dFreq,dSig=dSig,dMinSamp=dMinSamp,adP=adP,lsSig=lsSig, strLog=NA,funcReg=funcReg,lsNonPenalizedPredictors=NULL,funcAnalysis=funcAnalysis,lsRandomCovariates=NULL,funcGetResult=funcGetResult)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
102 receivedReturn$adP = round(receivedReturn$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
103
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
104 vCoefs=receivedReturn$lsSig[[1]]$allCoefs
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
105 vCoefs[1]=round(vCoefs[1],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
106 vCoefs[2]=round(vCoefs[2],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
107 vCoefs[3]=round(vCoefs[3],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
108 vCoefs[4]=round(vCoefs[4],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
109 vCoefs[5]=round(vCoefs[5],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
110 vCoefs[6]=round(vCoefs[6],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
111 receivedReturn$lsSig[[1]]$allCoefs=vCoefs
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
112 receivedReturn$lsSig[[2]]$allCoefs=vCoefs
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
113 receivedReturn$lsSig[[3]]$allCoefs=vCoefs
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
114 receivedReturn$lsSig[[4]]$allCoefs=vCoefs
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
115 receivedReturn$lsSig[[5]]$allCoefs=vCoefs
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
116 vValue=c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
117 vValue[receivedReturn$lsSig[[1]]$orig]=round(receivedReturn$lsSig[[1]]$value[[1]],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
118 receivedReturn$lsSig[[1]]$value=vValue
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
119 vValue=c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
120 vValue[receivedReturn$lsSig[[2]]$orig]=round(receivedReturn$lsSig[[2]]$value[[1]],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
121 receivedReturn$lsSig[[2]]$value=vValue
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
122 vValue=c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
123 vValue[receivedReturn$lsSig[[3]]$orig]=round(receivedReturn$lsSig[[3]]$value[[1]],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
124 receivedReturn$lsSig[[3]]$value=vValue
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
125 vValue=c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
126 vValue[receivedReturn$lsSig[[4]]$orig]=round(receivedReturn$lsSig[[4]]$value[[1]],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
127 receivedReturn$lsSig[[4]]$value=vValue
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
128 vValue=c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
129 vValue[receivedReturn$lsSig[[5]]$orig]=round(receivedReturn$lsSig[[5]]$value[[1]],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
130 receivedReturn$lsSig[[5]]$value=vValue
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
131 receivedReturn$lsSig[[1]]$std=round(receivedReturn$lsSig[[1]]$std,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
132 receivedReturn$lsSig[[2]]$std=round(receivedReturn$lsSig[[2]]$std,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
133 receivedReturn$lsSig[[3]]$std=round(receivedReturn$lsSig[[3]]$std,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
134 receivedReturn$lsSig[[4]]$std=round(receivedReturn$lsSig[[4]]$std,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
135 receivedReturn$lsSig[[5]]$std=round(receivedReturn$lsSig[[5]]$std,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
136 test_that("funcBugHybrid works with the lm option with multiple covariates.",{expect_equal(receivedReturn,expectedReturn)})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
137
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
138
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
139 # single covariate, single call lm
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
140 aiMetadata = c(1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
141 dFreq = 0.5 / length( aiMetadata )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
142 lsData$astrMetadata = names(frmeTmp)[aiMetadata]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
143 adPExpected = round(c(0.1081731),5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
144 QCExpected = list(iLms=numeric(0))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
145 lsSigExpected = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
146 lsSigExpected[[1]] = lsCov1
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
147 lsSigExpected[[1]]$std=round(0.005278468,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
148 vdCoef = c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
149 vdCoef["(Intercept)"]=round(-0.102410716,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
150 vdCoef["Covariate1"]= round(0.009718095,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
151 lsSigExpected[[1]]$allCoefs= vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
152 lsSigExpected[[1]]$value = c(Covariate1=round(0.009718095,5))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
153
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
154 expectedReturn = list(adP=adPExpected,lsSig=lsSigExpected,lsQCCounts=QCExpected)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
155 receivedReturn = funcBugHybrid(iTaxon=iTaxon,frmeData=frmeTmp,lsData=lsData,aiMetadata=aiMetadata,dFreq=dFreq,dSig=dSig,dMinSamp=dMinSamp,adP=adP,lsSig=lsSig, strLog=NA,funcReg=funcReg,lsNonPenalizedPredictors=NULL,funcAnalysis=funcAnalysis,lsRandomCovariates=NULL,funcGetResult=funcGetResult)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
156 receivedReturn$adP = round(receivedReturn$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
157
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
158 vCoefs=receivedReturn$lsSig[[1]]$allCoefs
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
159 vCoefs[1]=round(vCoefs[1],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
160 vCoefs[2]=round(vCoefs[2],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
161 receivedReturn$lsSig[[1]]$allCoefs=vCoefs
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
162 vValue=c()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
163 vValue[receivedReturn$lsSig[[1]]$orig]=round(receivedReturn$lsSig[[1]]$value[[1]],5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
164 receivedReturn$lsSig[[1]]$value=vValue
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
165 receivedReturn$lsSig[[1]]$std=round(0.005278468,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
166 test_that("funcBugHybrid works with the lm option with 1 covariates.",{expect_equal(receivedReturn,expectedReturn)})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
167
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
168
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
169 # multiple covariate, single call univariate
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
170 funcReg = NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
171 funcAnalysis = funcDoUnivariate
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
172 funcGetResult = NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
173 aiMetadata = c(3,1,2)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
174 dFreq = 0.5 / length( aiMetadata )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
175 lsData$astrMetadata = names(frmeTmp)[aiMetadata]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
176 adPExpected = round(c(1.0,1.0,0.09679784,0.21252205),5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
177 QCExpected = list(iLms=numeric(0))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
178 lsSigExpected = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
179 lsCov1 = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
180 lsCov1$name = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
181 lsCov1$orig = "Covariate32"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
182 lsCov1$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
183 lsCov1$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
184 lsCov1$factors = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
185 lsCov1$metadata = frmeTmp[["Covariate3"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
186 vdCoef = c(Covariate32=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
187 lsCov1$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
188 lsCov1$std = sd(frmeTmp[["Covariate3"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
189 lsCov1$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
190 lsCov2 = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
191 lsCov2$name = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
192 lsCov2$orig = "Covariate33"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
193 lsCov2$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
194 lsCov2$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
195 lsCov2$factors = "Covariate3"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
196 lsCov2$metadata = frmeTmp[["Covariate3"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
197 vdCoef = c(Covariate33=NA)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
198 lsCov2$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
199 lsCov2$std = sd(frmeTmp[["Covariate3"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
200 lsCov2$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
201 lsCov3 = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
202 lsCov3$name = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
203 lsCov3$orig = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
204 lsCov3$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
205 lsCov3$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
206 lsCov3$factors = "Covariate1"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
207 lsCov3$metadata = frmeTmp[["Covariate1"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
208 vdCoef = c(Covariate1=0.6)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
209 lsCov3$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
210 lsCov3$std = sd(frmeTmp[["Covariate1"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
211 lsCov3$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
212 lsCov4 = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
213 lsCov4$name = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
214 lsCov4$orig = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
215 lsCov4$taxon = "adCur"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
216 lsCov4$data = covY
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
217 lsCov4$factors = "Covariate2"
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
218 lsCov4$metadata = frmeTmp[["Covariate2"]]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
219 vdCoef = c(Covariate2=0.46666667)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
220 lsCov4$value = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
221 lsCov4$std = sd(frmeTmp[["Covariate2"]])
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
222 lsCov4$allCoefs = vdCoef
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
223
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
224 lsSigExpected = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
225 lsSigExpected[[1]] = lsCov1
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
226 lsSigExpected[[2]] = lsCov2
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
227 lsSigExpected[[3]] = lsCov3
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
228 lsSigExpected[[4]] = lsCov4
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
229
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
230 expectedReturn = list(adP=adPExpected,lsSig=lsSigExpected,lsQCCounts=QCExpected)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
231 receivedReturn = funcBugHybrid(iTaxon=iTaxon,frmeData=frmeTmp,lsData=lsData,aiMetadata=aiMetadata,dFreq=dFreq,dSig=dSig,dMinSamp=dMinSamp,adP=adP,lsSig=lsSig, strLog=NA,funcReg=funcReg,lsNonPenalizedPredictors=NULL,funcAnalysis=funcAnalysis,lsRandomCovariates=NULL,funcGetResult=funcGetResult)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
232 receivedReturn$adP = round(receivedReturn$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
233 test_that("funcBugHybrid works with the univariate option with 3 covariates.",{expect_equal(receivedReturn,expectedReturn)})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
234
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
235
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
236 # single covariate, single call univariate
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
237 funcReg = NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
238 funcAnalysis = funcDoUnivariate
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
239 funcGetResult = NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
240 aiMetadata = c(1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
241 dFreq = 0.5 / length( aiMetadata )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
242 lsData$astrMetadata = names(frmeTmp)[aiMetadata]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
243 adPExpected = round(c(0.09679784),5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
244 QCExpected = list(iLms=numeric(0))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
245 lsSigExpected = list()
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
246 lsSigExpected[[1]] = lsCov3
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
247
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
248 expectedReturn = list(adP=adPExpected,lsSig=lsSigExpected,lsQCCounts=QCExpected)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
249 receivedReturn = funcBugHybrid(iTaxon=iTaxon,frmeData=frmeTmp,lsData=lsData,aiMetadata=aiMetadata,dFreq=dFreq,dSig=dSig,dMinSamp=dMinSamp,adP=adP,lsSig=lsSig, strLog=NA,funcReg=funcReg,lsNonPenalizedPredictors=NULL,funcAnalysis=funcAnalysis,lsRandomCovariates=NULL,funcGetResult=funcGetResult)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
250 receivedReturn$adP = round(receivedReturn$adP,5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
251 test_that("funcBugHybrid works with the univariate option with 1 covariates.",{expect_equal(receivedReturn,expectedReturn)})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
252
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
253
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
254 context("Test funcBugs")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
255 #One LM run
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
256 frmeData=frmeTmp
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
257 aiMetadata=c(1)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
258 aiData=c(iTaxon)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
259 strData=NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
260 dFreq= 0.5 / length( aiMetadata )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
261 dSig=0.25
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
262 dMinSamp=0.1
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
263 strDirOut=NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
264 funcReg=NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
265 lsNonPenalizedPredictors=NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
266 lsRandomCovariates=NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
267 funcAnalysis=funcLM
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
268 funcGetResults=funcGetLMResults
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
269 fDoRPlot=FALSE
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
270 lsData = list(frmeData=frmeData, aiMetadata=aiMetadata, aiData=aiData, lsQCCounts=list())
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
271 lsData$astrMetadata = names(frmeTmp)[aiMetadata]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
272 QCExpected = list(iLms=numeric(0))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
273
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
274 expectedReturn = list(aiReturnBugs=aiData,lsQCCounts=QCExpected)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
275 receivedReturn = funcBugs(frmeData=frmeData, lsData=lsData, aiMetadata=aiMetadata, aiData=aiData, strData=strData, dFreq=dFreq, dSig=dSig, dMinSamp=dMinSamp,strDirOut=strDirOut, funcReg=funcReg,lsNonPenalizedPredictors=lsNonPenalizedPredictors,funcAnalysis=funcAnalysis,lsRandomCovariates=lsRandomCovariates,funcGetResults=funcGetResults,fDoRPlot=fDoRPlot)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
276
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
277 test_that("funcBugs works with the lm option with 1 covariate.",{expect_equal(receivedReturn,expectedReturn)})
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
278
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
279 #multiple LM run
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
280 frmeData=frmeTmp
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
281 aiMetadata=c(1:5)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
282 aiData=c(iTaxon)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
283 strData=NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
284 dFreq= 0.5 / length( aiMetadata )
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
285 dSig=0.25
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
286 dMinSamp=0.1
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
287 strDirOut=NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
288 funcReg=NA
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
289 lsNonPenalizedPredictors=NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
290 lsRandomCovariates=NULL
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
291 funcAnalysis=funcLM
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
292 funcGetResults=funcGetLMResults
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
293 fDoRPlot=FALSE
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
294 lsData = list(frmeData=frmeData, aiMetadata=aiMetadata, aiData=aiData, lsQCCounts=list())
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
295 lsData$astrMetadata = names(frmeTmp)[aiMetadata]
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
296 QCExpected = list(iLms=numeric(0))
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
297
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
298 expectedReturn = list(aiReturnBugs=aiData,lsQCCounts=QCExpected)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
299 receivedReturn = funcBugs(frmeData=frmeData, lsData=lsData, aiMetadata=aiMetadata, aiData=aiData, strData=strData, dFreq=dFreq, dSig=dSig, dMinSamp=dMinSamp,strDirOut=strDirOut, funcReg=funcReg,lsNonPenalizedPredictors=lsNonPenalizedPredictors,funcAnalysis=funcAnalysis,lsRandomCovariates=lsRandomCovariates,funcGetResults=funcGetResults,fDoRPlot=fDoRPlot)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
300
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
301 print("START START")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
302 print(expectedReturn)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
303 print("RECEIVED")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
304 print(receivedReturn)
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
305 print("STOP STOP")
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
306
e0b5980139d9 maaslin
george-weingart
parents:
diff changeset
307 test_that("funcBugs works with the lm option with multiple covariates.",{expect_equal(receivedReturn,expectedReturn)})