Skip to contents

This function takes a set of model specifications for the three sub-models of the mixture model and fits them to a data set.

Usage

mixglm(
  stateValModels,
  stateProbModels,
  statePrecModels,
  inputData,
  numStates = NULL,
  stateValError = gaussian,
  mcmcIters = 10000,
  mcmcBurnin = 5000,
  mcmcChains = 4,
  mcmcThin = 1,
  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)")),
  setInit = NULL,
  setSeed = FALSE,
  verbose = TRUE,
  mixglmSpecif = NULL
)

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 components in the mixture. 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 mixture model. This can be from the family specification or character scalar with the following possible values: "gaussian", "gamma", "beta", or "negbinomial".

mcmcIters

An integer scalar providing the number of post-burn-in samples to draw from the MCMC sampler (per chain).

mcmcBurnin

An integer scalar providing the number of MCMC samples to use for the adaption or burn-in portion of the process (per chain).

mcmcChains

An integer scalar giving the number of MCMC chains to use.

mcmcThin

An integer scalar giving the thinning frequency in the MCMC chains. For example, a value of 4 results in every fourth values being retained.

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 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 mixture components.

setInit

list of initial values which overwrites generated ones.

setSeed

logical or numeric argument passed to runMCMC. If "TRUE" or numeric, R's random number seed is set at the onset of each MCMC chain.

verbose

A logical value specifying if NIMBLE messages should be printed.

mixglmSpecif

Output of "mixglmSpecification()". Mainly for development.

Value

A list containing the following components:

mcmcSamples

An mcmc object if mcmcChains == 1 or mcmc.list object if mcmcChains > 1 containing the sampled values

compiledModel

An R interface object containing an interface for the compiled NIMBLE model. This is the same output as the compileNimble function applied to the model object

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 provided to NIMBLE

data

A list containing the data 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 used 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)

mod <- mixglm(
  stateValModels = y ~ x,
  stateProbModels = ~ x,
  statePrecModels = ~ x,
  inputData = dat,
  numStates = 2)
plot(mod)} # }