-
Notifications
You must be signed in to change notification settings - Fork 1
/
table_s3.R
137 lines (123 loc) · 5.28 KB
/
table_s3.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
134
135
136
137
library(here)
library(tidyverse)
library(MetBrewer)
library(officer)
library(flextable)
library(magrittr)
setwd(here::here("results"))
load("ic.RData")
ic <- ic |>
dplyr::filter( (nobs > 1 & ndist > 1) | is.na(nobs)) |>
dplyr::group_by(simrep) |>
dplyr::mutate(min_num_obs = min(nobs, na.rm = TRUE),
max_num_obs = max(nobs, na.rm = TRUE)) |>
dplyr::filter(nobs == min_num_obs | nobs == max_num_obs | is.na(nobs)) |>
dplyr::mutate( type = ifelse(nobs == min_num_obs, "rare",
ifelse(nobs == max_num_obs, "common", NA)),
nsp = length(unique(sp))) |>
dplyr::group_by(simrep, type) |>
dplyr::mutate(first_sp = first(sp)) |>
dplyr::filter( sp == first_sp | is.na(first_sp)) |>
tibble::add_column(model = "ic") |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`)
load("dc.RData")
dc <- dc |>
dplyr::filter( (nobs > 1 & ndist > 1) | is.na(nobs)) |>
dplyr::group_by(simrep) |>
dplyr::mutate(min_num_obs = min(nobs, na.rm = TRUE),
max_num_obs = max(nobs, na.rm = TRUE)) |>
dplyr::filter(nobs == min_num_obs | nobs == max_num_obs | is.na(nobs)) |>
dplyr::mutate( type = ifelse(nobs == min_num_obs, "rare",
ifelse(nobs == max_num_obs, "common", NA))) |>
dplyr::group_by(simrep, type) |>
dplyr::mutate(first_sp = first(sp)) |>
dplyr::filter( sp == first_sp | is.na(first_sp)) |>
dplyr::filter(!is.na(mean)) |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`)
load("cc.RData")
cc <- cc |>
dplyr::group_by(simrep) |>
dplyr::mutate(min_num_obs = min(nobs, na.rm = TRUE),
max_num_obs = max(nobs, na.rm = TRUE)) |>
dplyr::filter(nobs == min_num_obs | nobs == max_num_obs | is.na(nobs)) |>
dplyr::mutate(type = ifelse(nobs == min_num_obs, "rare",
ifelse(nobs == max_num_obs, "common", NA))) |>
dplyr::group_by(simrep, type) |>
dplyr::mutate(first_sp = first(sp)) |>
dplyr::filter(sp == first_sp | is.na(first_sp)) |>
dplyr::filter(!is.na(mean)) |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`)
load("is.RData")
is <- is |>
dplyr::mutate(type = ifelse(model == "isr", "rare", "common")) |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`) |>
dplyr::filter(!is.na(mean))
load("ds.RData")
ds <- ds |>
dplyr::mutate(type = ifelse(model == "dsr", "rare", "common")) |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`) |>
dplyr::filter(!is.na(mean))
load("cs.RData")
cs <- cs |>
dplyr::mutate(type = ifelse(model == "csr", "rare", "common")) |>
dplyr::select(model, simrep, param, type, truth, mean, sd, `2.5%`, `97.5%`) |>
dplyr::filter(!is.na(mean))
all <- dplyr::full_join(ic, dc) |>
dplyr::full_join(cc) |>
dplyr::full_join(is) |>
dplyr::full_join(ds) |>
dplyr::full_join(cs)
com_params <- all |>
dplyr::mutate(diff = mean - truth) |>
dplyr::mutate(model = toupper(model)) |>
dplyr::group_by(model, type, param) |>
dplyr::summarise(ab = mean(diff)) |>
dplyr::filter(is.na(type)) |>
dplyr::ungroup() |>
dplyr::select(-type) |>
dplyr::full_join( tibble::tibble(
model = c("IC", "IC", "DC", "DC", "CC", "CC"),
type = c("rare", "common", "rare", "common", "rare", "common"))) |>
dplyr::select(model, type, param, ab)
ab_table <- all |>
dplyr::mutate(diff = mean - truth) |>
dplyr::mutate(model = toupper(model)) |>
dplyr::group_by(model, type, param) |>
dplyr::summarise(ab = mean(diff)) |>
dplyr::filter(!is.na(type)) |>
dplyr::full_join(com_params) |>
dplyr::mutate(type = toupper(str_sub(type, 1, 1))) |>
dplyr::mutate(model = ifelse(model == "ISC", "IS",
ifelse(model == "ISR", "IS",
ifelse(model == "DSR", "DS",
ifelse(model == "DSC", "DS",
ifelse(model == "CSR", "CS",
ifelse(model == "CSC", "CS", model))))))) |>
dplyr::mutate(model = paste0(model, type)) |>
dplyr::mutate(model = factor(model, levels = c(
"ICR", "ICC",
"DCR", "DCC",
"CCR", "CCC",
"ISR", "ISC",
"DSR", "DSC",
"CSR", "CSC"
))) |>
dplyr::arrange(model) |>
dplyr::ungroup() |>
dplyr::select(-type) |>
dplyr::mutate( ab = paste0( sprintf("%.2f", round( ab, 2)))) |>
dplyr::mutate(param = factor(param, levels = c("N_DS", "N_TC",
"mu_gamma0", "sd_gamma0", "gamma0_ds",
"mu_gamma0_c", "sd_gamma0_c", "gamma0_c",
"mu_alpha0", "sd_alpha0", "alpha0",
"mu_alpha1", "sd_alpha1", "alpha1"))) |>
dplyr::arrange(model, param) |>
tidyr::pivot_wider(names_from = model, values_from = ab) |>
dplyr::rename(Parameter = param)
flextable::set_flextable_defaults(font.size = 10)
ft <- flextable::flextable( data = ab_table, cwidth = 0.7)
tmp <- tempfile(fileext = ".docx")
officer::read_docx() |>
flextable::body_add_flextable(ft) |>
print(target = tmp)
utils::browseURL(tmp)