/
fs_funceval_expand.R
39 lines (30 loc) · 1.24 KB
/
fs_funceval_expand.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
## ----global_options, include = FALSE------------------------------------------------------------------------------------------------
try(source("../../.Rprofile"))
## ----setup_data---------------------------------------------------------------------------------------------------------------------
# Parameter Setups
it_M <- 3
it_Q_max <- 5
fl_rnorm_mu <- 1000
ar_rnorm_sd <- seq(0.01, 200, length.out=it_M)
ar_it_q <- sample.int(it_Q_max, it_M, replace=TRUE)
# N by Q varying parameters
mt_data = cbind(ar_it_q, ar_rnorm_sd)
tb_M <- as_tibble(mt_data) %>% rowid_to_column(var = "ID") %>%
rename(sd = ar_rnorm_sd, Q = ar_it_q) %>%
mutate(mean = fl_rnorm_mu)
# display
kable(tb_M) %>%
kable_styling_fc()
## ----normal draw expansion dot dollar-----------------------------------------------------------------------------------------------
# Generate $Q_m$ individual specific incomes, expanded different number of times for each m
tb_income <- tb_M %>% group_by(ID) %>%
do(income = rnorm(.$Q, mean=.$mean, sd=.$sd)) %>%
unnest(c(income))
# Merge back with tb_M
tb_income_full_dd <- tb_income %>%
left_join(tb_M)
# display
kable(tb_income) %>%
kable_styling_fc()
kable(tb_income_full_dd) %>%
kable_styling_fc()