-
Notifications
You must be signed in to change notification settings - Fork 0
/
CTMparam_test-input-output.Rmd
353 lines (231 loc) · 6.93 KB
/
CTMparam_test-input-output.Rmd
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
---
title: "Testing the input and output of Area"
author: "Judith Neve"
date: "20/01/2022"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(CTmeta)
```
This document tests what can be used as input and output for the function Area. Each argument is examined in turn, and at the end some additional checks are done to verify plots can be made for different configurations of the model.
Where the function runs, the output is compared to the expected output.
After every attempt to "break" the function, a diagnostic is written as a comment in the code chunk, and the code chunk is followed by a "to do" list to indicate what needs to be specified/improved/changed in the function documentation or the function itself.
Original example:
```{r}
DeltaT <- 1
Phi <- myPhi[1:2, 1:2]
#
q <- dim(Phi)[1]
SigmaVAR <- diag(q) # for ease
#
Gamma <- Gamma.fromVAR(Phi, SigmaVAR)
##################################################################################################
CTMpar <- CTMparam(DeltaT, Phi, SigmaVAR)
```
# DeltaT
## DeltaT = 2
```{r}
CTMpar.break <- CTMparam(DeltaT = 2, Phi, SigmaVAR)
summary(CTMpar.break) == summary(CTMpar)
CTMpar.break$standSigma == CTMpar$standSigma
```
Looks like it works!
## DeltaT = Inf
```{r}
CTMpar.break <- CTMparam(DeltaT = Inf, Phi, SigmaVAR)
CTMpar.break
summary(CTMpar.break) == summary(CTMpar)
CTMpar.break$standSigma == CTMpar$standSigma
```
This is ok - the results are enough to show there may be something wrong + specifies the process in not stable
## DeltaT = 0
```{r}
CTMpar.break <- CTMparam(DeltaT = 0, Phi, SigmaVAR) %>% try()
```
## DeltaT = -1
```{r}
CTMpar.break <- CTMparam(DeltaT = -1, Phi, SigmaVAR)
CTMpar.break
summary(CTMpar.break) == summary(CTMpar)
CTMpar.break$standSigma == CTMpar$standSigma
```
Negative values will work, but there is a message in the output that shows this is not ideal. We can keep this.
## DeltaT = c(1, 0)
```{r}
CTMpar.break <- CTMparam(DeltaT = c(1, 0), Phi, SigmaVAR) %>% try()
```
## DeltaT = TRUE
```{r}
CTMpar.break <- CTMparam(DeltaT = TRUE, Phi, SigmaVAR)
CTMpar.break
summary(CTMpar.break) == summary(CTMpar)
CTMpar.break$standSigma == CTMpar$standSigma
```
TRUE is converted to 1. That's ok.
## DeltaT = "text"
```{r}
CTMpar.break <- CTMparam(DeltaT = "text", Phi, SigmaVAR) %>% try()
```
The error does suggest DeltaT or Phi is the problem. No need for further checks.
## DeltaT = NA
```{r}
CTMpar.break <- CTMparam(DeltaT = NA, Phi, SigmaVAR) %>% try()
```
This runs well.
# SigmaVAR
## SigmaVAR with NAs
```{r}
SigmaVAR.break <- SigmaVAR
SigmaVAR.break[2,1] <- NA
CTMpar.break <- CTMparam(DeltaT, Phi, SigmaVAR = SigmaVAR.break) %>% try()
```
## SigmaVAR with text
```{r}
SigmaVAR.break <- SigmaVAR
SigmaVAR.break[2,1] <- "text"
CTMpar.break <- CTMparam(DeltaT, Phi, SigmaVAR = SigmaVAR.break) %>% try()
```
## SigmaVAR with 1 extra row
```{r}
SigmaVAR.break <- SigmaVAR
SigmaVAR.break <- rbind(SigmaVAR.break, c(1,1))
CTMpar.break <- CTMparam(DeltaT, Phi, SigmaVAR = SigmaVAR.break) %>% try()
```
## SigmaVAR with 1 extra col
```{r}
SigmaVAR.break <- SigmaVAR
SigmaVAR.break <- cbind(SigmaVAR.break, c(1,1))
CTMpar.break <- CTMparam(DeltaT, Phi, SigmaVAR = SigmaVAR.break) %>% try()
```
## SigmaVAR with 1 extra row and 1 extra col
```{r}
SigmaVAR.break <- SigmaVAR
SigmaVAR.break <- cbind(SigmaVAR.break, c(1,1))
SigmaVAR.break <- rbind(SigmaVAR.break, c(1,1,1))
CTMpar.break <- CTMparam(DeltaT, Phi, SigmaVAR = SigmaVAR.break) %>% try()
```
## SigmaVAR a vector
```{r}
SigmaVAR.break <- SigmaVAR %>% as.vector()
CTMpar.break <- CTMparam(DeltaT, Phi, SigmaVAR = SigmaVAR.break) %>% try()
```
## Both SigmaVAR and Gamma - which one gets used?
```{r}
CTMpar.break <- CTMparam(DeltaT, Phi, SigmaVAR = SigmaVAR, Gamma = Gamma)
CTMpar.break
```
We first input a mismatched Gamma.
```{r}
Gamma.break <- Gamma
Gamma.break[1,1] <- 10
CTMpar.break <- CTMparam(DeltaT, Phi, SigmaVAR = SigmaVAR, Gamma = Gamma.break)
CTMpar.break
summary(CTMpar.break) == summary(CTMpar)
CTMpar.break$standSigma == CTMpar$standSigma
```
Gamma is used.
We input a mismatched SigmaVAR.
```{r}
SigmaVAR.break <- SigmaVAR
SigmaVAR.break[1,1] <- 10
CTMpar.break <- CTMparam(DeltaT, Phi, SigmaVAR = SigmaVAR.break, Gamma = Gamma)
CTMpar.break
summary(CTMpar.break) == summary(CTMpar)
CTMpar.break$standSigma == CTMpar$standSigma
```
SigmaVAR is also used.
Added a warning that says they are mismatched.
# Gamma
## Gamma with NAs
```{r}
Gamma.break <- Gamma
Gamma.break[2,1] <- NA
CTMpar.break <- CTMparam(DeltaT, Phi, Gamma = Gamma.break)
CTMpar.break
```
NA values appear but some things are still in. This should be fine.
## Gamma with text
```{r}
Gamma.break <- Gamma
Gamma.break[2,1] <- "text"
CTMpar.break <- CTMparam(DeltaT, Phi, Gamma = Gamma.break) %>% try()
```
## Gamma with 1 extra row
```{r}
Gamma.break <- Gamma
Gamma.break <- rbind(Gamma.break, c(1,1))
CTMpar.break <- CTMparam(DeltaT, Phi, Gamma = Gamma.break) %>% try()
```
Proper break.
## Gamma with 1 extra col
```{r}
Gamma.break <- Gamma
Gamma.break <- cbind(Gamma.break, c(1,1))
CTMpar.break <- CTMparam(DeltaT, Phi, Gamma = Gamma.break) %>% try()
```
Proper break.
## Gamma with 1 extra row and 1 extra col
```{r}
Gamma.break <- Gamma
Gamma.break <- cbind(Gamma.break, c(1,1))
Gamma.break <- rbind(Gamma.break, c(1,1,1))
CTMpar.break <- CTMparam(DeltaT, Phi, Gamma = Gamma.break) %>% try()
```
Proper break.
## Gamma a vector
```{r}
Gamma.break <- Gamma %>% as.vector()
CTMpar.break <- CTMparam(DeltaT, Phi, Gamma = Gamma.break) %>% try()
```
Proper break.
# Phi
## Phi with NAs
```{r}
Phi.break <- Phi
Phi.break[2,1] <- NA
CTMpar.break <- CTMparam(DeltaT, Phi.break, SigmaVAR) %>% try()
```
The error message.
## Phi with text
```{r}
Phi.break <- Phi
Phi.break[2,1] <- "text"
CTMpar.break <- CTMparam(DeltaT, Phi.break, SigmaVAR) %>% try()
```
Error message added.
## Phi with 1 extra row
```{r}
Phi.break <- Phi
Phi.break <- rbind(Phi.break, c(1,1))
CTMpar.break <- CTMparam(DeltaT, Phi.break, SigmaVAR) %>% try()
```
Error message added.
## Phi with 1 extra col
```{r}
Phi.break <- Phi
Phi.break <- cbind(Phi.break, c(1,1))
CTMpar.break <- CTMparam(DeltaT, Phi.break, SigmaVAR) %>% try()
```
Error message added.
## Phi with 1 extra row and 1 extra col but normal size SigmaVAR
```{r}
Phi.break <- Phi
Phi.break <- rbind(Phi.break, c(1,1))
Phi.break <- cbind(Phi.break, c(1,1,1))
CTMpar.break <- CTMparam(DeltaT, Phi.break, SigmaVAR) %>% try()
```
Error message is about SigmaVAR, not Phi.
## Phi with 1 extra row and 1 extra col but larger SigmaVAR
```{r}
SigmaVAR.break <- SigmaVAR
SigmaVAR.break <- rbind(SigmaVAR.break, c(1,1))
SigmaVAR.break <- cbind(SigmaVAR.break, c(1,1,1))
CTMpar.break <- CTMparam(DeltaT, Phi.break, SigmaVAR.break) %>% try()
```
This would likely run fine if the matrices were from actual data - there is no warning about size.
## Phi a vector
```{r}
Phi.break <- Phi %>% as.vector()
CTMpar.break <- CTMparam(DeltaT, Phi.break, SigmaVAR) %>% try()
```