Description Usage Arguments Value Examples
This implements a Bayesian negative binomial regression by using the 2nd parameterization from the Stan manual.
1 2 |
y |
the response variable to uses |
x |
the matrix of covariates to use |
chains |
the number of chains to use which defaults to 2 |
iter |
the number of samples to pull which defaults to 1000 |
allpars |
decides if all parameters should be returned or not. FALSE which is the default only gives the mu's, beta's, phi and predicted y_rep |
cores |
the number of cores to use which defaults to max(parallel::detectCores()-1, 1) |
... |
other arguments passed to the sampling method in rstan |
the stanfit from the sampled model
1 2 3 4 5 6 7 8 9 | ## Not run:
data<-list(N=nrow(mtcars), y=mtcars$gear, X=mtcars[, c('drat', 'am')])
sfit<-negbinom(data$y, data$X, iter = 500, chains=2, cores=2, allpars = TRUE)
library(bayesplot)
mcmc_combo(as.array(sfit), regex_pars = "tau")
yrep<-as.matrix(sfit)
ppc_dens_overlay(data$y, yrep[1:50,grep("y_", colnames(yrep))])
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.