-
Notifications
You must be signed in to change notification settings - Fork 23
/
test-smk-ds.lmerSLMA.R
132 lines (98 loc) · 4.84 KB
/
test-smk-ds.lmerSLMA.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
#-------------------------------------------------------------------------------
# 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.lmerSLMA::smk::setup phase 1")
connect.studies.dataset.cluster.int(list("incid_rate", "trtGrp", "Male", "idDoctor", "BMI", "idSurgery"))
test_that("setup", {
ds_expect_variables(c("D"))
})
#
# Tests
#
context("ds.lmerSLMA::smk::phase 1")
test_that("simple lmerSLMA", {
res <- ds.lmerSLMA(formula = 'incid_rate ~ trtGrp + Male + (1|idDoctor)', dataName = "D")
expect_length(res, 8)
})
## try some different formulae structures?
test_that("alternative formulae for nested groups", {
res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idSurgery/idDoctor)', dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idSurgery) +(1|idSurgery:idDoctor)', dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
# different behaviour for normal DS versus DSLite...
#res = ds.lmerSLMA(formula = 'D$BMI ~ D$trtGrp + D$Male + (1|D$idSurgery)')
#expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idDoctor)', dataName = "D", combine.with.metafor = FALSE)
expect_length(res, 5)
})
test_that("server side error", {
res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idSurgery)', dataName = 'D', optimizer = 'nloptwrap')
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
res=ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idSurgery)', dataName = 'D', optimizer = 'not_this_one')
expect_equal(res$errorMessage, "ERROR: the only optimizer currently available for lmer is 'nloptwrap', please respecify")
res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idDoctor)', dataName = "D", REML = FALSE)
expect_equal(res$output.summary$study1$methTitle, "Linear mixed model fit by maximum likelihood ")
})
test_that("test offsets and weights", {
ds.make('D$BMI/D$BMI', "some.weights")
ds.make('D$BMI/D$BMI', "some.offsets")
ds.dataFrame(x=c("D", "some.weights", "some.offsets"), newobj = "D2")
res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idDoctor)', weights = "some.weights", dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idDoctor)', offset = "some.offsets", dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idDoctor)', weights = "D2$some.weights", dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idDoctor)', offset = "D2$some.offsets", dataName = "D")
expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported")
})
#
# Shutdown
#
context("ds.lmerSLMA::smk::shutdown phase 1")
test_that("shutdown", {
#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
#
context("ds.lmerSLMA::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
#
context("ds.lmerSLMA::smk::test phase 2")
test_that("check slope formulae", {
# res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idDoctor) + (1|idSurgery) + (0+trtGrp|idSurgery)', dataName = 'D', control_type = 'check.conv.grad',control_value = 0.1)
# expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported", fixed=TRUE)
# res = ds.lmerSLMA(formula = 'BMI ~ trtGrp + Male + (1|idDoctor) + (trtGrp||idSurgery)', dataName = 'D', control_type = 'check.conv.grad',control_value = 0.1)
# expect_equal(res$Convergence.error.message[2], "Study2: no convergence error reported", fixed=TRUE)
})
#
# Shutdown
#
context("ds.lmerSLMA::smk::shutdown phase 2")
test_that("shutdown", {
#note the offset and weights objects below are artefacts
ds_expect_variables(c("D"))
})
disconnect.studies.dataset.cluster.slo()
#
# Done
#
context("ds.lmerSLMA::smk::done")