-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 14.6 KB
/
.Rhistory
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
covr()
code_coverage()
package_coverage()
devtools::load_all(".")
package_coverage()
devtools::load_all(".")
plot(hystar_fit(hystar_sim(z_sim())$data)
)
(1:10)[[c(4, 5)]]
(1:10)[[2]]
a <- c(b = 4, c = 5)
a[["b"]]
devtools::load_all(".")
plot(hystar_fit(hystar_sim(z_sim())$data))
devtools::load_all(".")
plot(hystar_fit(hystar_sim(z_sim())$data))
devtools::load_all(".")
plot(hystar_fit(hystar_sim(z_sim())$data), name_regime0 = "margo")
plot(hystar_fit(hystar_sim(z_sim())$data), name_regime0 = "margo", color_regime1 = "red")
?call
body(hystar_fit)
lm(x ~ y, data = matrix(rnorm(100), nrow = 50))
lm(x ~ y, data = data.frame(x = rnorm(100), y = rnorm(100)))
lm
?match.call
test <- function(a, b) {
return(match.call())
}
test(a = 4, b = 5)
a <- test(a = 4, b = 5)
class(a)
print(a)
test <- function(a, b = 4) {
return(match.call())
}
a <- test(a = 4)
a
lm
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim())$data)
hystar_fit(hystar_sim(z_sim())$data)$call
devtools::load_all(".")
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim())$data)$call
hystar_fit(hystar_sim(z_sim())$data)
devtools::load_all(".")
hystar_fit(hystar_sim(z_sim())$data)
?eval
?quote
a <- hystar_fit(hystar_sim(z_sim())$data)$call
a
cat(a)
print(a)
cat(as.character(a))
devtools::load_all(".")
a <- hystar_fit(hystar_sim(z_sim())$data)
a
a <- hystar_fit(hystar_sim(z_sim())$data)$call
a
quote(a)
cat(quote(a))
cat(enquote(a))
lm
print.lm
lm.print
cat(enquote(a))
enquote(a)
substitute(a)
?deparse
devtools::load_all(".")
a <- hystar_fit(hystar_sim(z_sim())$data)$call
a <- hystar_fit(hystar_sim(z_sim())$data)
a
a <- hystar_sim(z_sim())
a
devtools::load_all(".")
document()
?plot.hystar_fit
document()
?plot.hystar_fit
?plot
devtools::load_all(".")
plot(hystar_sim(z_sim()))
devtools::load_all(".")
test_that("plot function does not return", {
z <- z_sim(n_t = 50, n_switches = 3,
start_regime = 1, start_hyst = TRUE,
range = c(-1, 1))
sim <- hystar_sim(z = z, r = c(-.5, .5), d = 5,
phi_R0 = c(0, .6), phi_R1 = c(1. -.3),
resvar = c(1, .9),
start_regime = 1)
fit <- hystar_fit(sim$data)
expect_equal(plot(sim), NULL)
expect_equal(plot(fit), NULL)
})
sim <- hystar_sim(z_sim())
hystar_sim(sim$data$y)
hystar_fit(sim$data$y)
plot(sim)
fit <- hystar_fit(sim$data$y)
plot(fit)
check()
usethis::use_package_doc()
devtools::load_all(".")
document()
vignette()
library(devtools)
devtools::load_all(".")
?apply
?lapply
?replicate
vignette
clean_vignettes()
devtools::load_all(".")
check()
test_active_file()
hystar_info()
hystar_fit(hystar_sim(z_sim())$data)
control_variable <- z_sim(n_t = 100)
simulated_hystar_model <- hystar_sim(z = control_variable)
fitted_hystar_model <- hystar_fit(data = simulated_hystar_model$data)
summary(fitted_hystar_model)
?knitr
packageVersion("knitr")
install.packages("knitr")
install.packages("knitr")
install.packages("knitr")
install.packages("knitr")
library(knitr)
detach("package:knitr", unload = TRUE)
detach("package::knitr", unload = TRUE)
packageVersion("xfun")
search()
update.packages(ask = FALSE, checkBuilt = TRUE)
library(devtools)
devtools::load_all(".")
devtools::load_all(".")
check()
install()
test_that("users should provide data", {
expect_error(hystar_fit(),
"Argument `data` is missing, with no default.")
})
alphabet()
letters
test_that("data must be numeric", {
expect_error(hystar_fit(data.frame(letters, letters)),
"Argument `data` is missing, with no default.")
})
data.frame(letters, letters)
test_that("data must be numeric", {
expect_error(hystar_fit(data.frame(letters, letters)),
"numeric")
})
test_that("data must be a vector, matrix or df", {
expect_error(hystar_fit(mean),
"vector, matrix or data.frame")
})
test_that("data cannot have missings", {
expect_error(hystar_fit(data.frame(1:20, c(1:19, NA))),
"not have missing values")
})
library(covr)
codecov()
test_that("data cannot have missings", {
expect_error(hystar_fit(c(1:20, NA)),
"not have missing values")
})
test_that("r must be numeric", {
expect_error(check_r_fit(letters), "numeric")
})
devtools::load_all(".")
test_that("r must be numeric", {
expect_error(check_r_fit(letters), "numeric")
})
test_that("r must be a proper interval", {
expect_error(check_r_fit(c(3, 2)), "interval")
})
test_that("a matrix for r must have correct thresholds if TAR is specified", {
r <- matrix(c(1, 2,
3, 3),
nrow = 2, byrow = TRUE)
expect_error(check_r_fit(r), "TAR")
})
test_that("a matrix for r must have correct thresholds", {
r <- matrix(c(1, 2,
2, 1),
nrow = 2, byrow = TRUE)
expect_error(check_r_fit(r), "The second threshold value should")
})
test_that("a matrix for r must have correct thresholds if TAR is specified", {
r <- matrix(c(1, 2,
3, 3),
nrow = 2, byrow = TRUE)
expect_error(check_r_fit(r, tar = TRUE), "TAR")
})
test_that("user is notified that they are fitting a TAR model", {
r <- matrix(c(2, 2,
3, 3),
nrow = 2, byrow = TRUE)
expect_error(check_r_fit(r, tar = FALSE), "TAR")
})
test_that("user is notified that they are fitting a TAR model", {
r <- matrix(c(2, 2,
3, 3),
nrow = 2, byrow = TRUE)
expect_warning(check_r_fit(r, tar = FALSE), "TAR")
})
test_that("`r` must be in the range of `z`", {
expect_error(check_rz(r = matrix(c(2, 20), nrow = 1),
z = 1:10), "range")
})
test_that("z should be present", {
expect_error(hystar_sim(),
"`z` is missing")
})
?hystar_sim
test_that("r must be numeric", {
expect_error(hystar_sim(1:10, r = c("a", "b")),
"numeric")
})
test_that("r must be length 2", {
expect_error(hystar_sim(1:10, r = 1:3),
"two threshold values")
})
test_that("r must be a proper interval", {
expect_error(hystar_sim(1:10, r = c(4, 2)),
"second threshold should be larger")
})
test_that("p cannot exceed d + 10", {
expect_error(hystar_sim(1:10, p0 = 15, d = 4),
"maximum order can not be")
})
test_that("p cannot exceed d + 10", {
expect_error(hystar_sim(1:10, phi_R0 = rep(.01, times = 15), d = 4),
"maximum order can not be")
})
test_that("p cannot exceed d + 10", {
expect_error(hystar_sim(1:100, phi_R0 = rep(.01, times = 15), d = 4),
"maximum order can not be")
})
test_that("p cannot exceed d + 10", {
expect_error(hystar_sim(1:100, r = c(5, 6), phi_R0 = rep(.01, times = 15), d = 4),
"maximum order can not be")
})
test_that("p cannot exceed d + 10", {
expect_error(hystar_sim(1:100, r = c(5, 6), phi_R0 = rep(.01, times = 15), d = 3),
"maximum order can not be")
})
test_that("residual variances must be numeric", {
expect_error(hystar_sim(-5:100, resvar = c(TRUE, TRUE)))
})
test_that("phi must be numeric", {
expect_error(hystar_sim(-5:10, phi_R0 = c(), "at least 1 value"))
})
test_that("there must be more than 1 switch", {
expect_error(z_sim(n_switches = 1), "must be at least 2"))
test_that("there must be more than 1 switch", {
expect_error(z_sim(n_switches = 1), "must be at least 2")
})
test_that("start regime in hystar_sim matches that in z_sim", {
expect_error(hystar_sim(z_sim(start_regime = 0), start_regime = 1), "does not match")
})
test_that("start regime in hystar_sim matches that in z_sim", {
expect_warning(hystar_sim(z_sim(start_regime = 0), start_regime = 1), "does not match")
})
?z-sim
?z_sim
z_sim(start_regime = NULL)
typeof(NULL)
?hystar_sim
devtools::load_all(".")
test_that("start regime must be 0 or 1", {
expect_error(z_sim(start_regime = 2), "must be 0 or 1")
})
test_that("start regime can be NULL for hystar_sim", {
expect_no_error(hystar_sim(z_sim()))
})
test_that("range must be numeric", {
expect_error(z_sim(range = letters), "numeric")
})
test_that("range must contain exactly two values", {
expect_error(z_sim(range = 1:3), "of length 2")
})
test_that("range must be an interval", {
expect_error(z_sim(range = c(1, 1)), "a proper interval")
})
test()
devtools::load_all(".")
test()
devtools::load_all(".")
hystar_sim(start_regime = "a")
hystar_sim(1:10, start_regime = "a")
hystar_sim(-1:10, start_regime = "a")
hystar_sim(z_sim(), r = c(-2, -.5), start_regime = "a")
hystar_sim(z_sim(start_hyst = TRUE), start_regime = "a")
hystar_sim(c(4:10, 10:1), r = c(3, 5), start_regime = "a")
hystar_sim(c(4:10, 10:1), r = c(3, 5))
devtools::load_all(".")
test()
r_search <- hystar_fit(hystar_sim(z_sim)$data, tar = TRUE)
r_search <- hystar_fit(hystar_sim(z_sim())$data, tar = TRUE)
r_search
r_search <- hystar_fit(hystar_sim(z_sim())$data, tar = TRUE)$r_search
r_search
test_that("tar = TRUE makes sure that r_search is a TAR search", {
grid <- create_grid_r(1:10, r = c(3, 6), thin = FALSE, tar = TRUE)
expect_true(all(grid[, 1] == grid[, 2]))
})
test_that("tar = TRUE makes sure that r_search is a TAR search", {
grid <- create_grid_r(1:10, r = c(.1, .4), thin = FALSE, tar = TRUE)
expect_true(all(grid[, 1] == grid[, 2]))
})
length(from = .1, to = .2, by = .01)
length(seq(from = .1, to = .2, by = .01))
test_that("thin works", {
grid <- create_grid_r(1:10, r = c(.1, .2), thin = TRUE, tar = TRUE)
expect_equal(nrow(grid), 11)
})
create_grid_r(1:10, r = c(.1, .2), thin = TRUE, tar = TRUE)
test_that("thin works", {
grid <- create_grid_r(1:10, r = c(.1, .2), thin = TRUE, tar = TRUE)
expect_equal(nrow(grid), 10)
})
test_that("p_select must be a valid choice", {
expect_error(hystar_fit(1:100, p_select = 1),
"character")
expect_error(hystar_fit(data.frame(y = 1:10, z = 1:10), p_select = "bla"),
"aic")
p_select <- check_hystar_fit_input(
z = 1:4, d = 1, p0 = 1, p1 = 1,
p_select = "aic", r = c(.8, .9), thin = TRUE, tar = FALSE
)
expect_equal(p_select, "aic")
})
class(NA)
devtools::load_all(".")
test()
devtools::load_all(".")
test()
devtools::load_all(".")
test()
devtools::load_all(".")
test()
devtools::load_all(".")
test_that("`r` must be numeric", {
expect_error(hystar_fit(hystar_sim(z_sim()$data, r = c("a", "b"))))
})
test_that("r must be numeric", {
expect_error(hystar_sim(1:10, r = c("a", "b")),
"numeric")
})
test_that("delay must be numeric", {
expect_error(hystar_sim(1:10, d = "1"),
"numeric")
})
test_that("things run normally with certain arguments off-default", {
expect_no_error({
hystar_fit(hystar_sim(z_sim())$data, show_progress = TRUE)
})
})
test_that("phi must be numeric", {
expect_error(hystar_sim(-5:10, phi_R0 = c(), "at least 1 value"))
})
test_that("phi contain values", {
expect_error(hystar_sim(-5:10, phi_R0 = c())), "at least 1 value")
test_that("phi contain values", {
expect_error(hystar_sim(-5:10, phi_R0 = c()), "at least 1 value")
})
c()
test_that("phi contain values", {
expect_error(hystar_sim(-5:10, phi_R0 = numeric(0)), "at least 1 value")
})
check_resvar(c(0, 2))
test_that("zero or negative residual variances are not allowed", {
expect_error(check_resvar(c(0, 2)), "positive")
})
devtools::load_all(".")
test_that("zero or negative residual variances are not allowed", {
expect_error(check_resvar(c(0, 2)), "positive")
})
test_that("zero or negative residual variances are not allowed", {
expect_error(check_resvar(c(0, 2)), "nonnegative")
})
test_that("whole error has correct variable name", {
hey <- 4.4
expect_error(error_whole(hey), "`hey` must be a whole number")
joe <- "a"
expect_error(error_whole(hey), "`joe` must benumeric")
})
hey <- 4.4
expect_error(error_whole(hey), "`hey` must be a whole number")
joe <- "a"
expect_error(error_whole(joe), "`joe` must benumeric")
test_that("whole error has correct variable name", {
hey <- 4.4
expect_error(error_whole(hey), "`hey` must be a whole number")
joe <- "a"
expect_error(error_whole(joe), "`joe` must benumeric")
})
test_that("whole error has correct variable name", {
hey <- 4.4
expect_error(check_whole_nn(hey), "`hey` must be a whole number")
joe <- "a"
expect_error(check_whole_nn(joe), "`joe` must benumeric")
})
hystar_sim(z_sim(), d = .2)
hystar_sim(z_sim(), d = "a")
devtools::load_all(".")
joe <- "a"
check_whole_nn(joe)
substitute(joe)
z_sim(n_t = 2.5)
devtools::load_all(".")
z_sim(n_t = 2.5)
?substitute
test_that("custom errors have correct variable name", {
expect_error(error_numeric(hey = TRUE), "`hey` must be numeric")
expect_error(error_nonnegative(hey = -9), "`hey` must be nonnegative")
expect_error(error_nonnegative(hey = 0.6), "`hey` must be a whole")
})
error_numeric()
test_that("custom errors have correct variable name", {
all <- TRUE
expect_error(error_numeric(all), "`all` must be numeric")
night <- -9
expect_error(error_nonnegative(night), "`night` must be nonnegative")
long <- 0.6
expect_error(error_nonnegative(long), "`long` must be a whole")
})
test_that("custom errors have correct variable name", {
all <- TRUE
expect_error(error_numeric(all), "`all` must be numeric")
night <- -9
expect_error(error_nonnegative(night), "`night` must be nonnegative")
long <- 0.6
expect_error(error_whole(long), "`long` must be a whole")
})
test_that("whole numbers are correctly checked", {
expect_true(is_whole(5))
expect_false(is_whole(pi))
})
test_that("custom errors have correct variable name", {
hey <- TRUE
expect_error(error_numeric(hey), "`hey` must be numeric")
mister <- -9
expect_error(error_nonnegative(mister), "`mister` must be nonnegative")
blue <- 0.6
expect_error(error_whole(long), "`blue` must be a whole")
skye <- 7
expect_error(error_logical(skye), "`skye` must be logical")
})
test_that("custom errors have correct variable name", {
hey <- TRUE
expect_error(error_numeric(hey), "`hey` must be numeric")
mister <- -9
expect_error(error_nonnegative(mister), "`mister` must be nonnegative")
blue <- 0.6
expect_error(error_whole(long), "`blue` must be a whole")
skye <- 7
expect_error(error_logical(skye), "`skye` must be TRUE or FALSE")
})
test_that("custom errors have correct variable name", {
hey <- TRUE
expect_error(error_numeric(hey), "`hey` must be numeric")
mister <- -9
expect_error(error_nonnegative(mister), "`mister` must be nonnegative")
blue <- 0.6
expect_error(error_whole(blue), "`blue` must be a whole")
skye <- 7
expect_error(error_logical(skye), "`skye` must be TRUE or FALSE")
})
test()
test_active_file()
use_test()
test_that("hystar info does not throw error", {
expect_no_error(hystar_info())
expect_invisible(hystar_info())
})
hystar_info()
test_that("fit throws no errors with certain off-default settings", {
expect_no_error({
hystar_fit(1:100, show_progress = TRUE)
})
})
check()
document()
check()
?hystar
test_that("n_t and n_switches must be correct", {
expect_error(check_n_t_switches("a", 100), "numeric")
expect_error(check_n_t_switches(.3, 100), "whole")
expect_error(check_n_t_switches(-1, 100), "nonnegative")
expect_error(check_n_t_switches(5, "100"), "numeric")
expect_error(check_n_t_switches(5, .5), "whole")
expect_error(check_n_t_switches(5, -5), "nonnegative")
})
test_that("delay must be numeric, whole and nonnegative", {
expect_error(check_d("1"), "numeric")
expect_error(check_d(.6), "whole")
expect_error(check_d(-10), "nonnegative")
})
test_that("orders are checked correctly", {
expect_error(check_p0("a"), "numeric")
expect_error(check_p0(.4), "whole")
expect_error(check_p0(-1), "nonnegative")
expect_error(check_p1("a"), "numeric")
expect_error(check_p1(.4), "whole")
expect_error(check_p1(-1), "nonnegative")
})
devtools::load_all(".")