customLink: Function to Define a Custom Link Function

View source: R/mcmcInternals.R

customLinkR Documentation

Description

A function to allow for the definition of custom or non-standard link functions for use in generalized linear models

Usage

customLink(func, invfunc, nimbleImp)

Arguments

func

A function with one argument that applies the link function to that argument

invfunc

A function with one argument that applies the inverse of the link function to that argument

nimbleImp

A function with two arguments. The first argument is a character scalar of an output node in NIMBLE that contains the mean value of the response variable that is the subject of the regression model and the second argument is the text containing the linear model specification. The function returns a character scalar containing the text of the NIMBLE code specification relating the mean value to the linear model specification.

Value

A list of containing the following named elements:

func

A version of the function of the func argument encapsulated such that it has an interface usable by the package

invfunv

A version of the function of the invfunc argument encapsulated such that it has an interface usable by the package

nimbleImp

A version of the function of the nimbleImp argument encapsulated such that is has an interface usable by the package

Author(s)

Joseph D. Chipperfield, joechip90@googlemail.com

See Also

nimbleCode

Examples

# Example of using the custom link function to implement the standard
# log link function

# 1. Define a function that creates the NIMBLE model specification using the
# link function. The function has two arguments: 'outNodeText' which is the
# text containing the name of the output node containing the mean value
# which is the response of the regression model, 'expFormText' which is the
# text containing the linear model specification
nimbleLinkSpec <- function(outNodeText, expFormText) {
  paste0("log(", outNodeText, ") <- ", expFormText)
}
# so for example:
nimbleLinkSpec("meanValue[iter]", "intercept + coefficient * covariate[iter]")
# will give "log(meanValue[iter]) <- intercept + coefficient * covariate[iter]"

# 2. Use the NIMBLE link specification function alongside the R
# implementation of the link function and its inverse to produce a custom
# link function that is usable by the package
customLink(log, exp, nimbleLinkSpec)



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