Description Usage Arguments Details Value Author(s) References Examples
The primary function which automates the running of JAGS
and nimble
.
See vignettes included in the package for full documentation. The list
of available vignettes can be generated with
vignette(package="dalmatian")
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | dalmatian(
df,
family = "gaussian",
mean.model,
dispersion.model,
joint.model = NULL,
jags.model.args,
coda.samples.args,
response = NULL,
ntrials = NULL,
rounding = FALSE,
lower = NULL,
upper = NULL,
parameters = NULL,
svd = FALSE,
residuals = FALSE,
gencode = NULL,
run.model = TRUE,
engine = "JAGS",
n.cores = 1L,
drop.levels = TRUE,
drop.missing = TRUE,
include.checks = TRUE,
overwrite = FALSE,
debug = FALSE,
saveJAGSinput = NULL
)
|
df |
Data frame containing the response and predictor values for each individual. (data.frame) |
family |
Name of family of response distribution. Currently supported families include normal ( |
mean.model |
Model list specifying the structure of the mean. (list) |
dispersion.model |
Model list specifying the structure of the dispersion. (list) |
joint.model |
Model list specifying structure with parameter shared between linear predictors of the mean and variance. (list) |
jags.model.args |
List containing named arguments of |
coda.samples.args |
List containing named arguments of |
response |
Name of variable in the data frame representing the response. (character) |
ntrials |
Name of variable in the data frame representing the number of independent trials for each observation of the beta binomial model. |
rounding |
Specifies that response has been rounded if TRUE. (logical) |
lower |
Name of variable in the data frame representing the lower bound on the response if rounded. (character) |
upper |
Name of variable in the data frame representing the upper bound on the response if rounded. (character) |
parameters |
Names of parameters to monitor. If NULL then default values are selected. (character) |
svd |
Compute Singular Variable Decomposition of model matrices to improve convergence. (logical) |
residuals |
If TRUE then compute residuals in output. (logical) |
gencode |
If TRUE then generate code potentially overwriting existing model file. By default generate code if the file does not exist and prompt user if it does. (logical) |
run.model |
If TRUE then run sampler. Otherwise, stop once code and data have been created. (logical) |
engine |
Specifies the sampling software. Packages currently supported include JAGS (the default) and nimble. (character) |
n.cores |
Number of cores to use. If equal to 1 then chains will not be run in parallel. If greater than 1 then chains will be run in parallel using the designated number of cores. |
drop.levels |
If TRUE then drop unused levels from all factors in |
drop.missing |
If TRUE then remove records with missing response variable. (logical) |
include.checks |
If TRUE (default) then include extra Bernoulli variables in the model to ensure that the mean and dispersion parameters remain within their support. (logical) |
overwrite |
If TRUE then overwrite existing JAGS files (non-interactive sessions only). (logical) |
debug |
If TRUE then enter debug model. (logical) |
saveJAGSinput |
Directory to which jags.model input is saved prior to calling |
The primary function in the package, dalmatian automates the generation of code, data, and initial values. These are then passed as arguments to function from the rjags
package which automates the generation of samples from the posterior.
An object of class dalmatian
containing copies of the original data frame, the mean model, the
dispersion model the arguments of jags.model
and coda.samples
. and the output of the MCMC sampler.
Simon Bonner
Bonner, S., Kim, H., Westneat, D., Mutzel, A.,
Wright, J., and Schofield, M.. (2021). dalmatian
: A Package
for Fitting Double Hierarchical Linear Models in R
via JAGS
and
nimble
. Journal of Statistical Software, 100, 10, 1–25.
doi: 10.18637/jss.v100.i10.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | ## Not run:
## Load pied flycatcher data
data(pied_flycatchers_1)
## Create variables bounding the true load
pfdata$lower=ifelse(pfdata$load==0,log(.001),log(pfdata$load-.049))
pfdata$upper=log(pfdata$load+.05)
## Mean model
mymean=list(fixed=list(name="alpha",
formula=~ log(IVI) + broodsize + sex,
priors=list(c("dnorm",0,.001))))
## Dispersion model
myvar=list(fixed=list(name="psi",
link="log",
formula=~broodsize + sex,
priors=list(c("dnorm",0,.001))))
## Set working directory
## By default uses a system temp directory. You probably want to change this.
workingDir <- tempdir()
## Define list of arguments for jags.model()
jm.args <- list(file=file.path(workingDir,"pied_flycatcher_1_jags.R"),n.adapt=1000)
## Define list of arguments for coda.samples()
cs.args <- list(n.iter=5000)
## Run the model using dalmatian
pfresults <- dalmatian(df=pfdata,
mean.model=mymean,
dispersion.model=myvar,
jags.model.args=jm.args,
coda.samples.args=cs.args,
rounding=TRUE,
lower="lower",
upper="upper",
debug=FALSE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.