Learn R Programming

glmmBUGS (version 2.4.2)

writeBugsModel: Write a bugs model file for a Generalised Linear Mixed Model

Description

Given a list of effect groups, and the covariates associated with each level, a bugs model file is written using ragged arrays corresponding to output from winBugsRaggedArray

Usage

writeBugsModel(file, effects, covariates, observations, 
family = c("bernoulli", "binomial", "poisson", "normal", "other"), 
spatial = NULL,  geostat=FALSE, 
prefix = "",reparam=NULL, brugs=TRUE, priors=NULL)

Arguments

file

a character string denoting the name of the bugs model file writen.

effects

vector of effect groups

covariates

A list with names corresponding to effects and each element being a vector of covariates applicable at that level

observations

A character string giving the column of observations, or a vector where the first element is the observations and the remaning are offsets.

family

Response distribution

spatial

name of the spatial random effect

geostat

Is this a geostatistical random effect? Defaults to FALSE for the Besag, York and Mollie discrete spatial variation model

prefix

the prefix

reparam

vector of random effect names, subtract covariates at this level from the intercept.

brugs

make the model file compatible with OpenBugs by using the inprod function in place of inprod2

priors

character string of prior distributions, with the name of each element referring to the parameter it is the prior for

Value

A file, suitable for passing to the bugs function in R2WinBUGS.

Warning

You are strongly encouraged to modify the model file prior to using it.

Details

The arguments to the function specify a generalised linear mixed model. A file containing code for a corresponding bugs model is written. The model uses ragged arrays to specify grouping factors, and includes covariates at the appropriate levels to aid in chain convergence. It is intended that the user will edit this file before it's use. The prior distributions in particular may not be appropriate.

References

"Handling unbalanced datasets" in the "Tricks: Advanced Use of the BUGS Language" section of the bugs manual, at http://www.openbugs.net/Manuals/Tricks.html

Examples

Run this code
# NOT RUN {
writeBugsModel("model.bug", effects="Strip",  observations="conc",
  covariates=list(observations="length"),
  family="normal", priors=c(intercept="dunif(-10,10)") )

cat(scan("model.bug", "a",sep='\n'),sep='\n')

# }

Run the code above in your browser using DataLab