negbinom: Bayesian negative binomial regression

Description Usage Arguments Value Examples

View source: R/negbinom.R

Description

This implements a Bayesian negative binomial regression by using the 2nd parameterization from the Stan manual.

Usage

1
2
negbinom(y, x, chains = 2, iter = 1000, allpars = FALSE,
  cores = max(parallel::detectCores() - 1, 1), ...)

Arguments

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

Value

the stanfit from the sampled model

Examples

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)

DoktorMike/bayesian-model-zoo documentation built on May 23, 2019, 11:32 p.m.