-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path002-paper-m-original-models.Rmd
70 lines (62 loc) · 2.31 KB
/
002-paper-m-original-models.Rmd
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
```{r m-original-models-prep}
## extract the peak heights
d_res_path <- "../data/derived_data/d_peaks"
dir.create(d_res_path)
# extract scaled normalized peak heights from MIRS
res <-
hklmirs::hkl_get_normalized_peak_heights(
x = d_flat,
export = d_res_path,
verbose = FALSE,
make_plots = FALSE,
do_scale = TRUE
)
# extract information on scaling for prediction for new datasets
res_scale <-
tibble::tibble(
name = colnames(res),
center = purrr::map_dbl(res, attr, which = "scaled:center"),
scale = purrr::map_dbl(res, attr, which = "scaled:scale")
)
# add peak info to d
d <- dplyr::bind_cols(d, res %>% purrr::map_df(as.numeric))
```
```{r m-original-models-models}
# compute the regression models
m1.1 <- lm(hol ~ carb,
data = d %>% dplyr::filter(sample_type != "old magazines"))
m2.1 <- lm(kl ~ arom15arom16,
data = d %>% dplyr::filter(sample_type != "office paper"))
```
```{r m-original-models-or-bayesian}
## compute the original regression models as Bayesian models
# define priors
rstanarm_prior <- rstanarm::normal(0, 2.5, autoscale = TRUE)
rstanarm_prior_aux <- rstanarm::exponential(1, autoscale = TRUE)
# compute models
m1.2 <- rstanarm::stan_glm(hol ~ carb,
data = d %>% dplyr::filter(sample_type != "old magazines"),
family = gaussian,
chains = chains,
iter = iter,
warmup = warmup,
seed = seed,
prior = rstanarm_prior,
prior_intercept = rstanarm_prior,
prior_aux = rstanarm_prior_aux)
m2.2 <- rstanarm::stan_glm(kl ~ arom15arom16,
data = d %>% dplyr::filter(sample_type != "office paper"),
family = gaussian,
chains = chains,
iter = iter,
warmup = warmup,
seed = seed,
prior = rstanarm_prior,
prior_intercept = rstanarm_prior,
prior_aux = rstanarm_prior_aux)
# compute loos
m1.2_loo <- loo(m1.2,
k_threshold = k_threshold)
m2.2_loo <- loo(m2.2,
k_threshold = k_threshold)
```