-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreport-script-rmd.R
133 lines (113 loc) · 3.16 KB
/
report-script-rmd.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
133
#' ---
#' title: "`r title`"
#' author: "`r author`"
#' date: "`r Sys.Date()`"
#' ---
#+ setup, include=FALSE
require("knitr")
require("pander")
opts_chunk$set(fig.path = figure.dir, comment = NA)
# options(width = 200)
panderOptions("table.split.table", Inf)
#'
#' Total number of unique independent units in the input data:
{{prettyNum(nuniqueIDs, big.mark = ",", scientific = FALSE)}}
#'
#' Total number of person-time observations in the input data:
{{prettyNum(nobs, big.mark = ",", scientific = FALSE)}}
#'
#' Total number of unique time-points in the input data:
{{prettyNum(nuniquets, big.mark = ",", scientific = FALSE)}}
#'
#' ## Model Performance Based on MSE for Holdout / Validation Data
#'
#+ warning=FALSE, message=FALSE
plotMSEs(modelfit, K = K, interactive = TRUE)
#'
#'
#'
#'
#+ warning=FALSE, message=FALSE, results='asis'
tabMSEonly <- modelfit$get_best_MSEs(K = K)
pander::set.caption("Top MSEs (for Holdout / Validation Data).")
pander::pander(data.frame(model = names(tabMSEonly), MSEs = tabMSEonly, row.names = NULL))
#'
#'
#'
#'
#+ warning=FALSE, message=FALSE, results='asis'
tab <- modelfit$get_best_MSE_table(K = K)
pander::set.caption("Best Performing Models (Based on MSE for Holdout / Validation Data).")
pander::pander(tab)
#'
#'
#'
#'
#'
#' ## Summary of Model Grids
#'
#+ warning=FALSE, message=FALSE
grids <- modelfit$get_modelfits_grid()
for (grid in grids) {
print(grid)
cat("\n\n\n");
}
#'
#'
#'
#'
#+ results='asis'
panderOptions('knitr.auto.asis', FALSE)
grids <- modelfit$get_modelfits_grid()
for (grid in grids) {
if (is.data.frame(grid) || is.data.table(grid))
grid <- grid[ , names(grid)[!(names(grid) %in% c("glob_params", "xgb_fit", "fit", "params"))], with = FALSE]
pander::pander(grid) # , caption = "Grid Details"
}
panderOptions('knitr.auto.asis', TRUE)
#'
#'
#'
#'
#'
#' ## Top Performing Models
#'
#+ echo=FALSE, warning=FALSE, message=FALSE, results='asis'
panderOptions('knitr.auto.asis', FALSE)
if (!skip.modelfits) {
models.object <- modelfit$get_best_models(K = K)
for (model_idx in seq_along(models.object)) {
cat("\n\n");
cat("###")
cat('<a name=',paste0("jump",model_idx),'>', "Summaries for Model " %+% names(models.object)[model_idx], '</a> ')
cat("\n\n");
if (!is.null(models.object[[model_idx]])) {
print_tables(models.object[[model_idx]])
} else {
cat("*no modeling objects found*")
}
cat("\n\n"); cat(" ")
}
}
panderOptions('knitr.auto.asis', TRUE)
#'
#'
#'
#'
#'
#' ## Model Stack Summaries
#'
#+ echo=FALSE
if (!skip.modelfits) {
print(modelfit, model_stats = TRUE, all_fits = print_all_fits)
# print(modelfit, model_stats = TRUE)
# models <- modelfit$getfit
# single_models <- models$modelfits_all[[1]]
# for (single_model in models$modelfits_all) {
# # print(models, only.coefs = only.coefs)
# print(single_model)
# # res <- utils::capture.output(single_models)
# # pander(print(paste(res, collapse = '\n')))
# }
}
# panderOptions('knitr.auto.asis', TRUE)