forked from antoniofabio/tsDyn
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathuniv_ar_mean.Rout.save
95 lines (89 loc) · 3.77 KB
/
univ_ar_mean.Rout.save
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
R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(tsDyn)
> suppressMessages(library(dplyr))
> library(purrr)
> library(tidyr)
>
> ############################
> ### Load data
> ############################
> path_mod_uni <- system.file("inst/testdata/models_univariate.rds", package = "tsDyn")
> if(path_mod_uni=="") path_mod_uni <- system.file("testdata/models_univariate.rds", package = "tsDyn")
>
> models_univariate <- readRDS(path_mod_uni)
>
> ############################
> ### Compute
> ############################
>
> ## ar_mean
> models_ar_mean <- models_univariate %>%
+ filter(model!="aar") %>%
+ mutate(ar_mean = map(object, ~suppressWarnings(ar_mean(.))))
>
> ############################
> ### Show result
> ############################
>
> ## should be only for both and trend
> check_1 <- models_ar_mean %>%
+ filter(map_lgl(ar_mean, is.null)) %>%
+ count(include)
>
> stopifnot(all(check_1$include == c("both", "trend")))
>
> ## should be only for const and none
> check_2 <- models_ar_mean %>%
+ filter(!map_lgl(ar_mean, is.null)) %>%
+ count(include)
>
> stopifnot(all(check_2$include == c("const", "none")))
>
> ## show results
> models_ar_mean %>%
+ filter(!map_lgl(ar_mean, is.null)) %>%
+ mutate(ar_mean = map(ar_mean, ~as_tibble(t(.)))) %>%
+ unnest(ar_mean) %>%
+ select(-object) %>%
+ as.data.frame() %>%
+ print(digits=3)
lag include model nthresh thDelay ar_mean ar_mean_H ar_mean_L ar_mean_M
1 1 const linear NA NA 2.42 NA NA NA
2 1 none linear NA NA 0.00 NA NA NA
3 2 const linear NA NA 2.40 NA NA NA
4 2 none linear NA NA 0.00 NA NA NA
5 1 const setar 1 0 NA 0.559 8.475 NA
6 1 const setar 2 0 NA 14.776 2.123 2.26
7 1 none setar 1 0 0.00 NA NA NA
8 1 none setar 2 0 0.00 NA NA NA
9 2 const setar 1 0 NA 1.444 4.648 NA
10 2 const setar 1 1 NA 2.421 1.703 NA
11 2 const setar 2 0 NA -0.567 0.316 2.50
12 2 const setar 2 1 NA 2.453 2.572 1.97
13 2 none setar 1 0 0.00 NA NA NA
14 2 none setar 1 1 0.00 NA NA NA
15 2 none setar 2 0 0.00 NA NA NA
16 2 none setar 2 1 0.00 NA NA NA
17 1 const lstar NA 0 NA -0.416 8.402 NA
18 1 none lstar NA 0 0.00 NA NA NA
19 2 const lstar NA 0 NA -0.441 4.657 NA
20 2 const lstar NA 1 NA 1.670 1.555 NA
21 2 none lstar NA 0 0.00 NA NA NA
22 2 none lstar NA 1 0.00 NA NA NA
>
>
> proc.time()
user system elapsed
3.182 0.142 3.521