1- library(rstan )
2- options(mc.cores = parallel :: detectCores())
1+ library(devtools )
2+ if (! require(cmdstanr )){
3+ devtools :: install_github(" stan-dev/cmdstanr" , dependencies = c(" Depends" , " Imports" ))
4+ }
5+ library(cmdstanr )
36
47source(" mungeCARdata4stan.R" )
58source(" scotland_data.R" )
@@ -13,11 +16,22 @@ node1 = nbs$node1;
1316node2 = nbs $ node2 ;
1417N_edges = nbs $ N_edges ;
1518
16- scot_stanfit = stan(" bym_predictor_plus_offset.stan" ,
17- data = list (N ,N_edges ,node1 ,node2 ,y ,x ,E ),
18- iter = 10000 );
19+ data = list (N = N ,N_edges = N_edges ,node1 = node1 ,node2 = node2 ,y = y ,x = x ,E = E )
20+
21+ bym_model = cmdstan_model(" bym_predictor_plus_offset.stan" );
22+ scot_stanfit = bym_model $ sample(
23+ data = data ,
24+ parallel_chains = 4 ,
25+ iter_warmup = 5000 ,
26+ iter_sampling = 5000 );
27+
28+ options(digits = 3 )
29+ scot_stanfit $ summary(variables = c(" lp__" , " beta0" , " beta1" ,
30+ " sigma_phi" , " tau_phi" ,
31+ " sigma_theta" , " tau_theta" ,
32+ " mu[5]" ," phi[5]" ," theta[5]" ),
33+ ~ quantile(.x , probs = c(0.025 , 0.5 , 0.975 )))
34+
35+
1936
20- print(scot_stanfit ,
21- pars = c(" lp__" , " beta0" , " beta1" , " sigma_phi" , " tau_phi" , " sigma_theta" , " tau_theta" ," mu[5]" ," phi[5]" ," theta[5]" ),
22- probs = c(0.025 , 0.5 , 0.975 ),digits = 3 );
2337
0 commit comments