customError: Function to Define a Custom Error Distribution

View source: R/mcmcInternals.R

customErrorR Documentation

Function to Define a Custom Error Distribution

Description

A function that allows for the definition of user-specified error distributions for use in generalized linear models

Usage

customError(
  nimbleLikeli,
  simulate,
  nimblePrior = list(),
  nimbleConstants = list(),
  link = "identity",
  discrete = FALSE,
  elementWise = FALSE
)

Arguments

nimbleLikeli

A function that returns a string containing the text for a specification of the likelihood in NIMBLE. The function must take three arguments: the first argument is a string that contains the name of the node that contains the expectation of the linear model, the second argument is a string that contains the node containing the data, and the third argument is an optional suffix that can be added to all the names of the nodes in the linear model.

simulate

A function that takes the expected value as its first argument along with named arguments equal to those defined in nimblePrior and nimbleConstants and then draws a number of random draws from the error distribution with the specified parameterization.

nimblePrior

A list with named elements corresponding to each parameter used in the error distribution and with each element being a function that returns a string containing a prior specification for that parameter in NIMBLE code. Each function element takes ones argument: an optional suffix that can be added to all the names of the nodes in the linear model.

nimbleConstants

A list with named elements corresponding to each constant value used in the error distribution and with each element being a function that returns a numeric vector containing the values for the constants. Each function is passed the complete set of parameters that are passed to the modelDefinitionToNIMBLE function. Alternatively, the constants can just be values as they would be used by the nimbleModel function.

link

Either a character vector containing the names of supported link functions (see unique(unlist(errorFamilies())) for a list of natively-supported link functions) or a list of named elements and each element is the output of the customLink function. The first element of link will be used as the default link function for the distribution.

discrete

A logical scalar denoting whether the distribution is defined for a discrete variable or not.

elementWise

A logical scalar denoting whether the nimbleLikeli function defines the likelihood for one data point at a time (using a loop in the model specification) or defines the entire data vector as a multivariate output from a joint probability distribution.

Value

A list containing the following named elements:

link

A list of link functions that are valid for this error distribution. Each element is a list containing the output from a call to the customLink function

nimbleLikeli

A version of the nimbleLikeli function encapsulated in such a way as to be usable by the package

nimblePrior

A version of the nimblePrior list with each element encapsulated in such as a way as to by usable by the package

nimbleConstants

A version of the nimbleConstants list with each element encapsulated in such a way as to be usable by the package

elementWise

A copy of the input argument elementWise

discrete

A copy of the input argument discrete

simulate

A version of the simulate function encapsulated in such a way as to be usable by the package

Author(s)

Joseph D. Chipperfield, joechip90@googlemail.com

See Also

nimbleCode customLink errorFamilies modelDefinitionToNIMBLE


joechip90/PaGAn documentation built on April 17, 2025, 4:05 p.m.