gen_adapt_model {adaptMT}R Documentation

adapt_model Objects for M-steps

Description

adapt_model objects provide the functions and their arguments in computing the M-steps. Each object can be passed to adapt as a candidate model.

Usage

gen_adapt_model(pifun = NULL, mufun = NULL, pifun_init = NULL,
  mufun_init = NULL, piargs = list(), muargs = list(),
  piargs_init = list(), muargs_init = list(), name = "")

Arguments

pifun

a function to fit pi(x). See Details

mufun

a function to fit mu(x). See Details

pifun_init

a function to fit pi(x) at the initial step

mufun_init

a function to fit mu(x) at the initial step

piargs

a list. Arguments for "pifun". An empty list as default

muargs

a list. Arguments for "mufun". An empty list as default

piargs_init

a list. Arguments for piargs_init. An empty list as default

muargs_init

a list. Arguments for muargs_init. An empty list as default

name

a string. An optional argument for the user-specified name of the model. An empty string as default.

Details

pifun should be in the form of pifun(formula, data, family, weights, ...) or pifun(x, y, family, ...). The former includes glm and gam and the latter includes glmnet. The outputs should be in the form of list(fitv = , info = , ...) where fitv gives the estimate of pi(x), as a vector with the same order of x, and info should at least contain a key df if model selection is used, i.e. info = list(df = , ...)

mufun should be in the form of pifun(formula, data, family, weights, ...) or pifun(x, y, family, weights, ...). Note that mufun must take weights as an input. The outputs should be in the same form as pifun except that fitv should give the estimate of mu(x).

When pifun / mufun takes the form of (formula, family, ...), piargs / muargs should at least contain a key formula; when pifun / mufun takes the form of (x, y, family, ...), piargs / muargs can be empty.

For glm/gam/glmnet, one can use the shortcut by running gen_adapt_model with name = "glm" or "gam" or "glmnet" but without specifying pifun, mufun, pifun_init and mufun_init. See examples below.

Value

name

same as the input name

algo

a list recording pifun, mufun, pifun_init and mufun_init

args

a list recording piargs, muargs, piargs_init and muargs_init

Examples


# Exemplary code to generate 'adapt_model' for logistic-Gamma glm  with naive initialization.
# The real implementation in the package is much more complicated.

# pifun as a logistic regression
pifun <- function(formula, data, weights, ...){
  glm(formula, data, weights = weights, family = binomial(),  ...)
}
# pifun_init as a constant
pifun_init <- function(x, pvals, s, ...){
  rep(0.1, length(pvals))
}
# mufun as a Gamma GLM
mufun <- function(formula, data, weights, ...){
  glm(formula, data, weights = weights, family = Gamma(), ...)
}
# mufun_init as a constant
mufun_init <- function(x, pvals, s, ...){
  rep(1.5, length(pvals))
}

library("splines") # for using ns() in the formula
piargs <- list(formula = "ns(x, df = 8)")
muargs <- list(formula = "ns(x, df = 8)")
name <- "glm"

mod <- gen_adapt_model(pifun, mufun, pifun_init, mufun_init,
                       piargs, muargs, name = name)
mod

# Using shortcut for GLM. See the last paragraph of Details.
mod2 <- gen_adapt_model(name = "glm", piargs = piargs, muargs = muargs)
mod2



[Package adaptMT version 1.0.0 Index]