delta.method {alr3} | R Documentation |
delta.method
is a generic function that uses the delta method to get a
first-order approximate
standard error for a nonlinear function of a vector of random variables
with known or estimated covariance matrix.
delta.method(object, ...) ## Default S3 method: delta.method(object,g,var,...) ## S3 method for class 'lm' delta.method(object, g, var=vcov,parameterPrefix="b",...) ## S3 method for class 'nls' delta.method(object, g, var=vcov,...) ## S3 method for class 'lmList' delta.method(object, g, var=vcov,parameterPrefix="b",...) ## S3 method for class 'nlsList' delta.method(object, g, var=vcov,...) ## S3 method for class 'lme' delta.method(object, g, var=vcov,parameterPrefix="b",...) ## S3 method for class 'nlme' delta.method(object, g, var=vcov,...) ## S3 method for class 'multinom' delta.method(object, g, var=vcov,parameterPrefix="b",...) ## S3 method for class 'polr' delta.method(object, g, var=vcov,parameterPrefix="b",...)
object |
For the default method, |
g |
A quoted string that is the function of the parameter estimates to be evaluated; see the details below. |
var |
The (estimated) covariance matrix of the coefficient
estimates. For the default method, this argument is required. For all
other methods, this argument must either provide the estimated covariance
matrix or a function that when applied
to |
parameterPrefix |
Typically a single letter with default
|
... |
Additional arguments; not currently used. |
Suppose x is a random vector of length p that is at least approximately normally distributed with mean β and estimated covariance matrix C. Then any function g(β) of β, is estimated by g(x), which is in large samples normally distributed with mean g(β) and estimated variance h'Ch, where h is the first derivative of g(β) with respect to β evaluated at x. This function returns both g(x) and its standard error, the square root of the estimated variance.
The default method requires that you provide x in the argument
object
, C in the argument var
, and a text expression
in argument g
that when evaluated gives the function g.
Since
the delta method is often applied to functions of regression parameter
estimates, the argument object
may be the name of a regression
object from which the vector x will be taken from coef(object)
,
and C will be taken from vcov(object)
unless you provide
some other estimate of variance, for example, using a sandwich estimator. Methods
have been provided for many common regression models.
For regression models for which methods are not provided, you must extract the named vector of coefficient estimates and and estimate of its covariance matrix and then apply the default delta.method function.
In the argument g
you must provide a quoted character string
that gives the function of interest, for example g="b1/b2"
, where
b1
and b2
are names of two of the coefficient estimates.
For nonlinear regression objects of type nls, the call coef(object)
returns the estimated
coefficient vectors with names corresponding to parameter names.
For example,
m2 <- nls(y~theta/(1+gamma*x), start = list(theta=2,gamma=3))
will
have parameters named c("theta", "gamma")
.
In many other familiar regression methods, such as lm and glm, the names of
the coefficient estimates are the corresponding variable names, not
parameter names. For example, in
m2 <- lm(Y~X1+X2)
, names(coef(m2))
returns
c("(Intercept)","X1","X2")
. For models where the
coefficient names are variable
names, delta.method
will
provide names for the parameter estimates, given by
“b0”, “b1”,...,“bp”, if parameterPrefix
is
left at its default value of “b”. In this case, “b0” is the
intercept (if the model has no intercept, then the numbering of the
parameters starts with 1, not 0), “b1” is the first estimated parameter
after the intercept, and so on.
Special characters should be avoided in the names of the elements of x
as these can cause problems, and the D
function used to compute derivatives may
get confused. However, embedded spaces or “:” are permitted.
A data.frame with two components
named Estimate
for the estimate, SE
for its standard error.
The value of g
is given as a row label.
Sanford Weisberg, sandy@stat.umn.edu
S. Weisberg (2005), Applied Linear Regression, third edition, Wiley, Section 6.1.2
First derivatives of g
are computed using symbolic differentiation
by the function D
.
# cakes is a data frame with response Y, predictors X1 X2 data(cakes,package="alr3") m1 <- lm(Y~ X2 + I(X2^2), data = cakes) # quadratic polynomial delta.method(m1, "-b1/(2*b2)") # X2 that maximizes the quadratic # second order polynomial in two predictors: m2 <- lm(Y ~ X1 + X2 + I(X1^2) + I(X2^2) + X1:X2, data=cakes) # Find X1 to maximize Y when X2=350: delta.method(m2,"(b1+b5*350)/(-2*b3)")