-
Notifications
You must be signed in to change notification settings - Fork 23
/
test-smk-ds.glmerSLMA.R
130 lines (96 loc) · 4.78 KB
/
test-smk-ds.glmerSLMA.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
#-------------------------------------------------------------------------------
# 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 Phase 1
#
context("ds.glmerSLMA::smk::setup - phase 1")
connect.studies.dataset.cluster.int(list("incid_rate", "trtGrp", "Male", "idDoctor", "idSurgery"))
test_that("setup", {
ds_expect_variables(c("D"))
})
#
# Tests Phase 1
#
context("ds.glmerSLMA::smk::phase 1")
test_that("simple glmerSLMA tesing (mis)use of arguments", {
res = ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor)', family='poisson', dataName = "D", start_theta = c(1))
expect_length(res, 8)
expect_error(ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor)', family='poisson', dataName = "D", start_theta = c(1,1,1)), "There are some DataSHIELD errors, list them with datashield.errors()", fixed=TRUE)
errs <- datashield.errors()
expect_length(errs, 3)
expect_length(errs$sim1, 0)
expect_length(errs$sim2, 0)
expect_length(errs$sim3, 0)
res = ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor)', family='poisson', dataName = "D", start_fixef = c(1,1,1), start_theta = c(1))
expect_length(res, 8)
})
test_that("test offsets and weights", {
ds.make('D$incid_rate/D$incid_rate', "some.weights")
ds.make('D$incid_rate/D$incid_rate', "some.offsets")
ds.dataFrame(x=c("D", "some.weights", "some.offsets"), newobj = "D2")
res = ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor)', family='poisson', weights = "some.weights", dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
res = ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor)', family='poisson', offset = "some.offsets", dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
res = ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor)', family='poisson', weights = "D2$some.weights", dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
res = ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor)', family='poisson', offset = "D2$some.offsets", dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
})
## try some different formulae structures?
test_that("alternative formulae for nested groups", {
res = ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idSurgery/idDoctor)', family='poisson', dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
res = ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idSurgery) +(1|idSurgery:idDoctor)', family='poisson', dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
})
test_that("simple glmerSLMA", {
res <- ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor)', family="poisson", dataName = "D")
expect_length(res, 8)
})
#
# Shutdown phase 1
#
context("ds.glmerSLMA::smk::shutdown - phase 1")
test_that("setup", {
#note the offset and weights objects below are artefacts
ds_expect_variables(c("D", "D2", "offset", "some.offsets", "some.weights", "weights"))
})
disconnect.studies.dataset.cluster.int()
#
# Set up phase 2
#
context("ds.glmerSLMA::smk::setup - phase 2")
connect.studies.dataset.cluster.slo(list("incid_rate", "trtGrp", "Male", "idDoctor", "BMI", "idSurgery"))
test_that("setup", {
ds_expect_variables(c("D"))
})
#
# Tests phase 2
#
context("ds.glmerSLMA::smk::test - phase 2")
test_that("check slope formulae", {
# res = ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor) + (1|idSurgery) + (0+trtGrp|idSurgery)', family='poisson', dataName = 'D', control_type = 'check.conv.grad',control_value = 0.1)
# expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
# res = ds.glmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor) + (trtGrp||idSurgery)', family='poisson', dataName = 'D', control_type = 'check.conv.grad',control_value = 0.1)
# expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
})
#
# Shutdown phase 2
#
context("ds.glmerSLMA::smk::shutdown - phase 2")
test_that("setup", {
ds_expect_variables(c("D"))
})
disconnect.studies.dataset.cluster.slo()
#
# Done
#
context("ds.glmerSLMA::smk::done")