forked from saudiwin/ordbetareg_pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_package.R
64 lines (49 loc) · 2.53 KB
/
test_package.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
library(ordbetareg)
library(tidyverse)
data("pew")
# prepare data
model_data <- select(pew,therm,
education="F_EDUCCAT2_FINAL",
region="F_CREGION_FINAL",
income="F_INCOME_FINAL",
THERMO_THERMBA_W28) %>%
mutate(THERMO_THERMBA_W28=as.numeric(THERMO_THERMBA_W28))
# fit the actual model
ord_fit_one_mod <- ordbetareg(formula=bf(THERMO_THERMBA_W28~ education),
data=model_data,
cores=2,chains=2,sample_prior="only",
backend="cmdstanr")
ord_fit_one_mod_newbounds <- ordbetareg(formula=bf(THERMO_THERMBA_W28~ education),
data=model_data,
true_bounds=c(0,100),
cores=2,chains=2,sample_prior="only",
backend="cmdstanr")
ord_fit_two_mods <- ordbetareg(formula=bf(THERMO_THERMBA_W28~ education) +
bf(therm ~ region),
data=model_data,
cores=2,chains=2,sample_prior="only",
backend="cmdstanr")
ord_fit_two_mods_dfam <- ordbetareg(formula=bf(THERMO_THERMBA_W28~ education, family="gaussian") +
bf(therm ~ region),
data=list(model_data,
model_data),
use_brm_multiple = T,
cores=2,chains=2,sample_prior="only",
backend="cmdstanr")
ord_fit_two_mods_mi <- ordbetareg(formula=bf(THERMO_THERMBA_W28~ education) +
bf(therm ~ region),
data=list(model_data,model_data),
use_brm_multiple = T,
cores=2,chains=2,sample_prior="only",
backend="cmdstanr")
ord_fit_phireg <- ordbetareg(formula=bf(THERMO_THERMBA_W28~ 1,
phi ~ (1|education)),
phi_reg = "intercepts",
extra_prior = set_prior("normal(0,2)",class="sd",dpar="phi"),
data=model_data,
cores=2,chains=2,sample_prior="only",
backend="cmdstanr")
# check with cmdstnar
require(cmdstanr)
dirich <- cmdstan_model("~/test.stan",quiet=F,compile = T,force_recompile=T)
dirich_fit <- dirich$sample(data=list(K=3))