deltamethod | R Documentation |
Delta-method implementations for Jensen's inequality and prediction uncertainty
deltamethod(fun, z, var = "x", params = NULL, max.order = 2)
deltavar(fun,meanval=NULL,vars,Sigma,verbose=FALSE)
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: needed if |
params |
list or 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? |
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 rather than a matrix, the parameters are assumed to be
independently estimated.
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
Ben Bolker
Lyons (1991), "A practical guide to data analysis for physical science students", Cambridge University Press
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.