Skip to contents

Mainly for internal use. This function takes a set of model specifications for the three sub-models of a mixture model and generates a set of structures for initialisation of a NIMBLE model

Usage

mixglmSpecification(
  stateValModels,
  stateProbModels,
  statePrecModels,
  inputData,
  numStates = NULL,
  stateValError = gaussian,
  setPriors = list(stateVal = list(int1 = "dnorm(0.0, 0.001)", int2 = "dgamma(1.0, 0.5)",
    pred = "dnorm(0.0, 0.001)"), stateProb = list(int2 = "dnorm(0.0, 0.001)", pred =
    "dnorm(0.0, 0.001)"), statePrec = list(int = "dnorm(0.0, 0.001)", pred =
    "dnorm(0.0, 0.001)"))
)

Arguments

stateValModels

A formula describing the regression relationship between the mean of the response variable and the covariates for all mixture components, or a list of formulas with each element giving the regression relationship between the mean of the response variable and the covariates for each mixture component (ordered according to intercept of the mixture component on the y-axis). The response variable must be given on the left-hand side of the formula.

stateProbModels

A formula describing the regression relationship between the probability of the existence of mixture components and the covariates, or a list of formulas with each element giving the regression relationship between the probability of the existence of a mixture component and its covariates (ordered according to intercept of the mixture component on the y-axis).

statePrecModels

A formula describing the regression relationship between the variances in the mixture components and the covariates, or a list of formulas with each mixture component giving the regression relationship between the variance in the mixture component and the covariates for each mixture component (ordered according to intercept of the mixture component on the y-axis).

inputData

A data frame containing the covariate information and the response variable.

numStates

An integer scalar containing the number of mixture components. If any of the stateValModels, stateProbModels, or statePrecModels parameters is a list then numStates can be omitted and is therefore set to the length of the list.

stateValError

A description of the error distribution and link function to be used in the model describing the response variable. This can be from the family specification or character scalar with the following possible values: "gaussian", "gamma", "beta", or "negbinomial".

setPriors

A named list of prior distributions. Distribution are specified using character strings. If sublists are not provided, values from the list are distributed to all sublist items allowing to specify several priors at once. Sublist items are "int", for specification of priors on intercept parameters, and "pred", from specification of priors on predictor/covariate parameters. "int" is followed by "1" or "2" marking priors for the first intercept and all the other intercepts respectively. For full structure of the list see default values. Prior "stateVal$Int2" should allow only positive values to ensure distinctness of states.

Value

A list containing the following components:

modelText

A character scalar containing the text of the model specification in the NIMBLE BUGS dialect

modelCode

A nimbleCode object containing the model specification

constants

A list containing the constants to be provided to NIMBLE

data

A list containing the data to be provided to NIMBLE

errorModel

A factor containing the error model used for the specification of the error distribution for the response variable

linkFunction

A factor containing the link function used in the specification of the mixture model

initialValues

A list containing potential initial values for each of the stochastic nodes in the NIMBLE model specification

Author

Joseph D. Chipperfield joechip90@googlemail.com, Adam Klimes

Examples

if (FALSE) { # \dontrun{
set.seed(10)
n <- 200
x <- rnorm(n)
group <- rbinom(n, 1, 0.5)
y <- rnorm(n, 1 + 0.5 * x * c(-1, 1)[group + 1], 0.1)
plot(y ~ x)
dat <- data.frame(x, y)

modSpecification <- mixglmSpecification(
  stateValModels = y ~ x,
  stateProbModels = ~ x,
  statePrecModels = ~ x,
  inputData = dat,
  numStates = 2)
} # }
mod <- mixglm(mixglmSpecif = modSpecification,
  mcmcChains = 2)
#> Error: object 'modSpecification' not found