dmethod: Delta method for regression model objects (experimental).

View source: R/dmethod.R

dmethodR Documentation

Delta method for regression model objects (experimental).

Description

This function applies the "delta method" to functions of parameters of model objects, provided that functions can be specified to extract the parameter estimates and the (estimated) covariance matrix of the estimator from the object. Derivatives are computed using numerical differentiation. Alternatively standard errors can be approximated using a bootstrap approach described by Mandel (2013). It is based on the deltaMethod function from the car package, but uses numerical rather than analytical derivatives, and has a few other options.

Usage

dmethod(
  object,
  pfunc,
  pname = NULL,
  cfunc = coef,
  vfunc = vcov,
  tfunc,
  fname,
  B = 0,
  sample = FALSE,
  level = 0.95,
  df = Inf,
  ...
)

Arguments

object

Model object. Just about any object can be specified provided that functions can also be specified to extract the parameter estimates and the estimated covariance matrix of the estimators.

pfunc

A character object that is function of the parameters that can be evaluated by R. Parameters must be referenced by name as specified by pname. Alternatively a function that takes as an argument the parameters. In either case the function can return a scalar or vector.

pname

Names of the parameters extracted by cfunc.

cfunc

Function for extracting the parameter estimates from object (default is coef).

vfunc

Function for extracting the estimated covariance matrix of the estimator from object (default is vcov).

tfunc

Function for transforming the result of pfunc for cases when the sampling distribution is thought to be more approximately normal on some other scale (e.g., log).

fname

Character string(s) for function names for output.

B

Number of bootstrap samples. The default (B = 0) results in numerical differentiation instead.

sample

Return sample of simulated realizations from sampling distribution when B > 0.

level

Confidence level in (0,1) (default is 0.95).

df

Degrees of freedom (infinite by default).

...

Optional arguments for jacobian.

Details

By default the function applies the delta method using numerical differentiation. However if B > 0 then a bootstrap method described by Mandel (2013) is used which avoids needing to compute derivatives.

Source

Mandel, M. (2013). Simulation-based confidence intervals for functions with complicated derivatives. The American Statistician, 62, 76-81.

Examples

# estimation of LD50 for each type of insecticide
m <- glm(cbind(deaths, total - deaths) ~ insecticide * log2(deposit),
  family = binomial, data = insecticide)
dmethod(m, "2^c(-b0/b3, -(b0+b1)/(b3+b4), -(b0+b2)/(b3+b5))",
  paste("b", 0:5, sep = ""), fname = c("BHC","both","DDT"))


trobinj/trtools documentation built on Jan. 28, 2024, 3:20 a.m.