Skip to content

Commit

Permalink
update to CmdStanR
Browse files Browse the repository at this point in the history
  • Loading branch information
mitzimorris committed Sep 9, 2023
1 parent b333788 commit f25f280
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions knitr/car-iar-poisson/fit_scotland.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
library(rstan)
options(mc.cores = parallel::detectCores())
library(devtools)
if(!require(cmdstanr)){
devtools::install_github("stan-dev/cmdstanr", dependencies=c("Depends", "Imports"))
}
library(cmdstanr)

source("mungeCARdata4stan.R")
source("scotland_data.R")
Expand All @@ -13,11 +16,22 @@ node1 = nbs$node1;
node2 = nbs$node2;
N_edges = nbs$N_edges;

scot_stanfit = stan("bym_predictor_plus_offset.stan",
data=list(N,N_edges,node1,node2,y,x,E),
iter=10000);
data = list(N=N,N_edges=N_edges,node1=node1,node2=node2,y=y,x=x,E=E)

bym_model = cmdstan_model("bym_predictor_plus_offset.stan");
scot_stanfit = bym_model$sample(
data = data,
parallel_chains = 4,
iter_warmup = 5000,
iter_sampling = 5000);

options(digits=3)
scot_stanfit$summary(variables = c("lp__", "beta0", "beta1",
"sigma_phi", "tau_phi",
"sigma_theta", "tau_theta",
"mu[5]","phi[5]","theta[5]"),
~quantile(.x, probs = c(0.025, 0.5, 0.975)))



print(scot_stanfit,
pars=c("lp__", "beta0", "beta1", "sigma_phi", "tau_phi", "sigma_theta", "tau_theta","mu[5]","phi[5]","theta[5]"),
probs=c(0.025, 0.5, 0.975),digits=3);

0 comments on commit f25f280

Please sign in to comment.