-
Notifications
You must be signed in to change notification settings - Fork 0
/
Supp Table 3 - Model Statistics.R
48 lines (41 loc) · 2.27 KB
/
Supp Table 3 - Model Statistics.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
# . -----------------------------------------------------------------------
rm(list=ls())
scales <- readRDS('DATA derived/scales.rds')
scales.list <- scales$paramcd
lm.mod <- readRDS('DATA derived/models.predictions.rds')
# model criteria ----------------------------------------------------------
lm.mod %>%
select(-data, -pred.lm, -pred.pl) %>%
gather(type, model, mod.lm, mod.pl) %>%
mutate( glance = map (model, ~ broom::glance(.))) %>%
unnest( glance ) %>%
# filter( dep %in% c('FARS.E','SARA.ax','ICARS.ax')) %>%
filter( dep %in% c('mFARS','SARA' , 'FARS.E','SARA.ax' )) %>%
filter( ind %in% c('mFARS','SARA' ,'ICARS','FARS.E','SARA.ax','ICARS.ax')) %>%
ungroup %>%
select(dep, ind, type, r.squared, AIC, BIC, p.value ) %>%
# select(dep, ind, type, r.squared, adj.r.squared, AIC, BIC, p.value ) %>%
mutate(p.value = '<0.0001') %>%
pivot_wider(id_cols = c(dep, ind), values_from = c(r.squared, AIC, BIC, p.value), names_from = type) %>%
# pivot_wider(id_cols = c(dep, ind), values_from = c(r.squared, adj.r.squared, AIC, BIC, p.value), names_from = type) %>%
select(dep, ind, ends_with('mod.lm'), everything()) %>%
mutate(dep = gsub('\\.',' ',dep)) %>%
mutate(ind = gsub('\\.ax','\\-AX',ind)) %>%
qflextable() %>%
colformat_double(digits = 2) %>%
colformat_double(digits = 0, j = c(4,5,8,9), big.mark = '') %>%
# colformat_double(digits = 0, j = c(5,6,10,11), big.mark = '') %>%
set_header_labels(
values = c(dep = 'Dep. Var.',ind = 'Indep. Var',
r.squared_mod.lm='R^2',AIC_mod.lm='AIC',BIC_mod.lm='BIC',p.value_mod.lm = 'p.value',
r.squared_mod.pl='R^2',AIC_mod.pl='AIC',BIC_mod.pl='BIC',p.value_mod.pl = 'p.value')
) %>%
# set_header_labels(
# values = c(dep = 'Dep. Var.',ind = 'Indep. Var',
# r.squared_mod.lm='R^2',adj.r.squared_mod.lm='R^2 adj',AIC_mod.lm='AIC',BIC_mod.lm='BIC',p.value_mod.lm = 'p.value',
# r.squared_mod.pl='R^2',adj.r.squared_mod.pl='R^2 adj',AIC_mod.pl='AIC',BIC_mod.pl='BIC',p.value_mod.pl = 'p.value')
# ) %>%
set_table_properties(layout = "autofit", width = .8) %>%
add_header_row(top = T, values = c('', 'linear model','2nd order poly. model'), colwidths = c(2,4,4)) %>%
align(align = 'center', part = 'all') %>%
autofit()