Learn R Programming

emdbook (version 1.3.2.1)

deltamethod: Delta method functions

Description

Delta-method implementations for Jensen's inequality and prediction uncertainty

Usage

deltamethod(fun, z, var = "x", params = NULL, max.order = 2)
deltavar(fun,meanval=NULL,vars,Sigma,verbose=FALSE)

Arguments

fun
Function of one (deltamethod) or more arguments, expressed in raw form (e.g. a*x/(b+x))
z
numeric vector of values
var
variable name
vars
list of variable names
params
list or named numeric vector of parameter values to substitute
meanval
possibly named vector of mean values of parameters
Sigma
numeric vector of variances or variance-covariance matrix
max.order
maximum order of delta method to compute
verbose
print details?

Value

  • For deltavar(), a vector of predicted variances; for deltamethod() a vector containing the observed value of the function average, the function applied to the average, and a series of delta-method approximations

Details

deltamethod() is for computing delta-method approximations of the mean of a function of data; deltavar() is for estimating variances of a function based on the mean values and variance-covariance matrix of the parameters. If Sigma is a vector, the parameters are assumed to be independently estimated.

References

Lyons (1991), "A practical guide to data analysis for physical science students", Cambridge University Press

Examples

Run this code
deltamethod(a*x/(b+x),runif(50),params=list(a=1,b=1),max.order=9)
deltavar(scale*gamma(1+1/shape),meanval=c(scale=0.8,shape=12),
   Sigma=matrix(c(0.015,0.125,0.125,8.97),nrow=2))
## more complex deltavar example
xvec = seq(-4,4,length=101)
x1 = xvec
x2 = xvec
v = matrix(0.2,nrow=3,ncol=3)
diag(v) = 1
m = c(b0=1,b1=1.5,b2=1)
v3  = deltavar(1/(1+exp(-(b0+b1*x1+b2*x2))),meanval=m,Sigma=v)
plot(xvec,v3)

Run the code above in your browser using DataLab