-
Notifications
You must be signed in to change notification settings - Fork 23
/
test-smk-ds.glmSLMA.R
190 lines (173 loc) · 9.94 KB
/
test-smk-ds.glmSLMA.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#-------------------------------------------------------------------------------
# Copyright (c) 2019-2020 University of Newcastle upon Tyne. All rights reserved.
#
# This program and the accompanying materials
# are made available under the terms of the GNU Public License v3.0.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
#
# Set up
#
context("ds.glmSLMA::smk::setup")
connect.studies.dataset.cnsim(list("LAB_TSC", "LAB_TRIG", "DIS_AMI", "DIS_DIAB", "GENDER"))
test_that("setup", {
ds_expect_variables(c("D"))
})
#
# Tests
#
context("ds.glmSLMA::smk::gaussian")
test_that("simple glmSLMA, gaussian", {
glmSLMA.res <- ds.glmSLMA('D$LAB_TSC~D$LAB_TRIG', family="gaussian")
expect_length(glmSLMA.res, 7)
expect_equal(glmSLMA.res$num.valid.studies, 3)
expect_true("matrix" %in% class(glmSLMA.res$betamatrix.all))
expect_true("matrix" %in% class(glmSLMA.res$sematrix.all))
expect_true("matrix" %in% class(glmSLMA.res$betamatrix.valid))
expect_true("matrix" %in% class(glmSLMA.res$sematrix.valid))
expect_true("matrix" %in% class(glmSLMA.res$SLMA.pooled.ests.matrix))
expect_length(glmSLMA.res$output.summary, 5)
expect_true("matrix" %in% class(glmSLMA.res$output.summary$input.beta.matrix.for.SLMA))
expect_true("matrix" %in% class(glmSLMA.res$output.summary$input.se.matrix.for.SLMA))
expect_length(glmSLMA.res$output.summary$study1, 29)
expect_true("family" %in% class(glmSLMA.res$output.summary$study1$family))
expect_true("matrix" %in% class(glmSLMA.res$output.summary$study1$coefficients))
expect_equal(glmSLMA.res$output.summary$study1$rank, 2)
expect_equal(glmSLMA.res$output.summary$study1$aic, 5460.549, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study1$iter, 2)
expect_equal(glmSLMA.res$output.summary$study1$contrasts, NULL)
expect_equal(glmSLMA.res$output.summary$study1$dispersion, 1.211496, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study1$Ntotal, 2163)
expect_equal(glmSLMA.res$output.summary$study1$Nvalid, 1801)
expect_equal(glmSLMA.res$output.summary$study1$Nmissing, 362)
expect_length(glmSLMA.res$output.summary$study2, 29)
expect_true("family" %in% class(glmSLMA.res$output.summary$study2$family))
expect_true("matrix" %in% class(glmSLMA.res$output.summary$study2$coefficients))
expect_equal(glmSLMA.res$output.summary$study2$rank, 2)
expect_equal(glmSLMA.res$output.summary$study2$aic, 7490.000, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study2$iter, 2)
expect_equal(glmSLMA.res$output.summary$study2$contrasts, NULL)
expect_equal(glmSLMA.res$output.summary$study2$dispersion, 1.13414, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study2$Ntotal, 3088)
expect_equal(glmSLMA.res$output.summary$study2$Nvalid, 2526)
expect_equal(glmSLMA.res$output.summary$study2$Nmissing, 562)
expect_length(glmSLMA.res$output.summary$study3, 29)
expect_true("family" %in% class(glmSLMA.res$output.summary$study3$family))
expect_true("matrix" %in% class(glmSLMA.res$output.summary$study3$coefficients))
expect_equal(glmSLMA.res$output.summary$study3$rank, 2)
expect_equal(glmSLMA.res$output.summary$study3$aic, 10256.000, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study3$iter, 2)
expect_equal(glmSLMA.res$output.summary$study3$contrasts, NULL)
expect_equal(glmSLMA.res$output.summary$study3$dispersion, 1.12, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study3$Ntotal, 4128)
expect_equal(glmSLMA.res$output.summary$study3$Nvalid, 3473)
expect_equal(glmSLMA.res$output.summary$study3$Nmissing, 655)
})
context("ds.glmSLMA::smk::binomial")
test_that("simple glmSLMA, binomial", {
ds.asCharacter('D$DIS_AMI', 'str.dis.ami')
ds.asNumeric('str.dis.ami', 'num.dis.ami')
ds.asCharacter('D$GENDER', 'str.gender')
ds.asNumeric('str.gender', 'num.gender')
ds.asCharacter('D$DIS_DIAB', 'str.dis.diab')
ds.asNumeric('str.dis.diab', 'num.dis.diab')
glmSLMA.res <- ds.glmSLMA('num.dis.ami~num.gender*num.dis.diab', family="binomial")
expect_length(glmSLMA.res, 9)
expect_length(glmSLMA.res[[1]], 1)
expect_equal(glmSLMA.res[[1]][1], "EVERY STUDY HAS DATA THAT COULD BE POTENTIALLY DISCLOSIVE UNDER THE CURRENT MODEL:")
expect_length(glmSLMA.res[[2]], 1)
expect_equal(glmSLMA.res[[2]][1], "Any values of 1 in the following tables denote potential disclosure risks.")
expect_length(glmSLMA.res[[3]], 1)
expect_equal(glmSLMA.res[[3]][1], "Errors by study are as follows:")
expect_true("matrix" %in% class(glmSLMA.res$y.vector.error))
expect_length(glmSLMA.res$y.vector.error["sim1", ], 1)
expect_length(glmSLMA.res$y.vector.error["sim2", ], 1)
expect_length(glmSLMA.res$y.vector.error["sim3", ], 1)
expect_length(glmSLMA.res$y.vector.error[, 1], 3)
expect_true("matrix" %in% class(glmSLMA.res$X.matrix.error))
expect_length(glmSLMA.res$X.matrix.error[1, ], 4)
expect_length(glmSLMA.res$X.matrix.error[2, ], 4)
expect_length(glmSLMA.res$X.matrix.error[3, ], 4)
expect_length(glmSLMA.res$X.matrix.error[, 1], 3)
expect_length(glmSLMA.res$X.matrix.error[, 2], 3)
expect_length(glmSLMA.res$X.matrix.error[, 3], 3)
expect_length(glmSLMA.res$X.matrix.error[, 4], 3)
expect_true("matrix" %in% class(glmSLMA.res$weight.vector.error))
expect_length(glmSLMA.res$weight.vector.error["sim1", ], 1)
expect_length(glmSLMA.res$weight.vector.error["sim2", ], 1)
expect_length(glmSLMA.res$weight.vector.error["sim3", ], 1)
expect_length(glmSLMA.res$weight.vector.error[, 1], 3)
expect_true("matrix" %in% class(glmSLMA.res$offset.vector.error))
expect_length(glmSLMA.res$offset.vector.error["sim1", ], 1)
expect_length(glmSLMA.res$offset.vector.error["sim2", ], 1)
expect_length(glmSLMA.res$offset.vector.error["sim3", ], 1)
expect_length(glmSLMA.res$offset.vector.error[, 1], 3)
expect_true("matrix" %in% class(glmSLMA.res$glm.overparameterized))
expect_length(glmSLMA.res$glm.overparameterized["sim1", ], 1)
expect_length(glmSLMA.res$glm.overparameterized["sim2", ], 1)
expect_length(glmSLMA.res$glm.overparameterized["sim3", ], 1)
expect_length(glmSLMA.res$glm.overparameterized[, 1], 3)
expect_true("matrix" %in% class(glmSLMA.res$errorMessage))
expect_length(glmSLMA.res$errorMessage["sim1", ], 1)
expect_length(glmSLMA.res$errorMessage["sim2", ], 1)
expect_length(glmSLMA.res$errorMessage["sim3", ], 1)
expect_length(glmSLMA.res$errorMessage[, 1], 3)
})
context("ds.glmSLMA::smk::poisson")
test_that("simple glmSLMA, poisson", {
glmSLMA.res <- ds.glmSLMA('D$LAB_TSC~D$LAB_TRIG', family="poisson")
expect_length(glmSLMA.res, 7)
expect_equal(glmSLMA.res$num.valid.studies, 3)
expect_true("matrix" %in% class(glmSLMA.res$betamatrix.all))
expect_true("matrix" %in% class(glmSLMA.res$sematrix.all))
expect_true("matrix" %in% class(glmSLMA.res$betamatrix.valid))
expect_true("matrix" %in% class(glmSLMA.res$sematrix.valid))
expect_true("matrix" %in% class(glmSLMA.res$SLMA.pooled.ests.matrix))
expect_length(glmSLMA.res$output.summary, 5)
expect_true("matrix" %in% class(glmSLMA.res$output.summary$input.beta.matrix.for.SLMA))
expect_true("matrix" %in% class(glmSLMA.res$output.summary$input.se.matrix.for.SLMA))
expect_length(glmSLMA.res$output.summary$study1, 29)
expect_true("family" %in% class(glmSLMA.res$output.summary$study1$family))
expect_true("matrix" %in% class(glmSLMA.res$output.summary$study1$coefficients))
expect_equal(glmSLMA.res$output.summary$study1$rank, 2)
expect_equal(glmSLMA.res$output.summary$study1$aic, Inf, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study1$iter, 4)
expect_equal(glmSLMA.res$output.summary$study1$contrasts, NULL)
expect_equal(glmSLMA.res$output.summary$study1$dispersion, 1.000, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study1$Ntotal, 2163)
expect_equal(glmSLMA.res$output.summary$study1$Nvalid, 1801)
expect_equal(glmSLMA.res$output.summary$study1$Nmissing, 362)
expect_length(glmSLMA.res$output.summary$study2, 29)
expect_true("family" %in% class(glmSLMA.res$output.summary$study2$family))
expect_true("matrix" %in% class(glmSLMA.res$output.summary$study2$coefficients))
expect_equal(glmSLMA.res$output.summary$study2$rank, 2)
expect_equal(glmSLMA.res$output.summary$study2$aic, Inf, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study2$iter, 4)
expect_equal(glmSLMA.res$output.summary$study2$contrasts, NULL)
expect_equal(glmSLMA.res$output.summary$study2$dispersion, 1.00, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study2$Ntotal, 3088)
expect_equal(glmSLMA.res$output.summary$study2$Nvalid, 2526)
expect_equal(glmSLMA.res$output.summary$study2$Nmissing, 562)
expect_length(glmSLMA.res$output.summary$study3, 29)
expect_true("family" %in% class(glmSLMA.res$output.summary$study3$family))
expect_true("matrix" %in% class(glmSLMA.res$output.summary$study3$coefficients))
expect_equal(glmSLMA.res$output.summary$study3$rank, 2)
expect_equal(glmSLMA.res$output.summary$study3$aic, Inf, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study3$iter, 4)
expect_equal(glmSLMA.res$output.summary$study3$contrasts, NULL)
expect_equal(glmSLMA.res$output.summary$study3$dispersion, 1.00, tolerance = 0.001)
expect_equal(glmSLMA.res$output.summary$study3$Ntotal, 4128)
expect_equal(glmSLMA.res$output.summary$study3$Nvalid, 3473)
expect_equal(glmSLMA.res$output.summary$study3$Nmissing, 655)
})
#
# Done
#
context("ds.glmSLMA::smk::shutdown")
test_that("shutdown", {
ds_expect_variables(c("D", "str.dis.ami", "num.dis.ami", "str.gender", "num.gender", "str.dis.diab", "num.dis.diab"))
})
disconnect.studies.dataset.cnsim()
context("ds.glmSLMA::smk::done")