inst/rstan/poisson-stan.R

## SKG
## Jan 21, 2020
## Getting rstan to run


library(rstan)
library(ggplot2)
library(dplyr)
devtools::load_all()

options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)

data(clusts_tb)
clusts2 <- clusts_tb %>% filter(size >= 2)
x <- clusts2$size

dat <- list(N = length(x),
            x = x)

print(fit)
plot(fit)
pairs(fit, pars = c("mu", "tau", "lp__"))

la <- extract(fit, permuted = TRUE) # return a list of arrays 
mu <- la$mu 

### return an array of three dimensions: iterations, chains, parameters 
a <- extract(fit, permuted = FALSE) 

### use S3 functions on stanfit objects
a2 <- as.array(fit)
m <- as.matrix(fit)
d <- as.data.frame(fit)


schools_dat <- list(J = 8, 
                    y = c(28,  8, -3,  7, -1,  1, 18, 12),
                    sigma = c(15, 10, 16, 11,  9, 11, 10, 18))


fit <- stan(file = 'test.stan', data = schools_dat)

print(fit)
plot(fit)
pairs(fit, pars = c("mu", "tau", "lp__"))

la <- extract(fit, permuted = TRUE) # return a list of arrays 
mu <- la$mu 

### return an array of three dimensions: iterations, chains, parameters 
a <- extract(fit, permuted = FALSE) 

### use S3 functions on stanfit objects
a2 <- as.array(fit)
m <- as.matrix(fit)
d <- as.data.frame(fit)
skgallagher/TBornotTB documentation built on April 21, 2020, 1:19 p.m.