fitNormalModel: Fit a Normal model to subject-level data

Description Usage Arguments Value Usage notes See Also Examples

View source: R/functions.R

Description

Fit a Normal model to subject-level data

Usage

1
2
fitNormalModel(x, g, inits = NULL, modelString = NULL,
  autoRun = TRUE, raw = FALSE, ...)

Arguments

x

a vector of observed data

g

a vector indicating the group membership for each datum. Either a factor defining group membership, or a vector of integers between 1 and the number of groups.

inits

a list containing the initial values of the hyperparameters. See Usage Notes below.

modelString

The JAGS model string that defines the model to be fitted

autoRun

Logical. If TRUE, use autorun.jags. Otherwise, use run.jags.

raw

logical if TRUE, the mcmc object created by run.jags() is returned. Otherwise, a tibble containing the concatenation of elements of the mcmc.list created by JAGS is returned

...

passed to JAGS

Value

Either the mcmc (or mcmc.list) object returned by JAGS or a tibble containing the MCMC samples from the posterior distribution

Usage notes

If modelString == NULL, the model string is obtained by calling getModelString("tte").

If raw == FALSE, the chain from which each observation is drawn is indicated by Chain and the dataset is transformed into tidy format, with the model parameter indicated by Parameter.

The inits parameter can be used to define the number of chains created my JAGS. If a list of lists, the number of elements in the outer list defines the number of chains and the elements of each sub-list define the initial value for each hyperparameter. For example, the default value of inits requests two chains. The initial values of shape and scale in the first chain are both 0.0001. In the second chain, they are both 1. If the MCMC model has converged and is stationary, the initial values of the hyperparameters will be irrelevant. To check for convergence, it is necessary - but not sufficient - to obtain more than one chain and to use different initial values for each chain.

Note that some parameters to run.jags are incompatible with autorun.jags and will therefor cause an error when passed in ... unless autoRun is set to FALSE. These parameters include samples and burnin and will result in an error similar to "Error in extend.jags(runjags.object, add.monitor = add.monitor, drop.monitor = drop.monitor, : formal argument "burnin" matched by multiple actual arguments".

See Also

fitBinomialModel, fitPoissonModel, fitBinaryModel, fitTteModel

Examples

1
2
3
4
5
6
7
8
#Fit a Normal QTL model to artifical data
nCentres <- 6
centreSizes <- ceiling(runif(nCentres, min=8, max=25))
group <- rep(1:nCentres, times=centreSizes)
centreMeans <- rnorm(nCentres, mean=5, sd=1.5)
means <- rep(centreMeans, times=centreSizes)
x <- rnorm(length(group), means, 3)
fitNormalModel(x, group) 

PuzzledFace/qtlr documentation built on March 19, 2020, 1:17 a.m.