Skip to content

variance of combinations of means - off topic

6 messages · Liaw, Andy, Kjetil Halvorsen, Thomas Lumley +1 more

#
You could try googling for "delta method".  I believe MASS even has code for
that...

Andy
#
Hi, Andy: 

      MASS4 has section 5.7 "Bootstrap and Permutation Methods".  Is 
this what you are suggesting?  It certainly is relevant to the question 
(but not to the "delta method", except as a means of checking on it). 

      Thanks,
      spencer graves
Liaw, Andy wrote:

            
#
Liaw, Andy wrote:

            
If you have the original data you can bootstrap --- else you need the 
standar errors and
correlation between the means, and can use the delta methos as above. 
You could even
use D or deriv or deriv3 to get the derivatives automatically.

We learnt this (the delta method) in physics class in high school, to be 
able to write
the lab reports.

Kjetil
-- 

Kjetil Halvorsen.

Peace is the most effective weapon of mass construction.
               --  Mahdi Elmandjra
#
Liaw, Andy wrote:

            
also,

help.search("delta")
does give nothing usefull, so if it is in MASS it would be hidden, and 
need a \concept
entry in the .Rd file.

The delta method is really nothimg more (or less) than a linear
Taylor approximation.

The following is a very fast implementation, which surely can be bettered:

se.delta <- function(expr, namevec, theta, sigma) {
    # theta is means, or more generally, estimates,
    # sigma is vector or matrix containing (standard errors)^2 and (if 
matrix)
    # covariances. If vector must be same length as theta, and we assume no
    # correlation between estimates theta.
    # expr must be a formula defining a function
    # taking as many arguments as length of theta.
    # namevec is a character vector containing the symbols used in the 
formula.
    p <- length(theta)
    if (!is.matrix(sigma)) sigma <- diag(sigma)
    if(!(NROW(sigma)==p)) stop("sigma and theta must have appropiate 
dimension")
    fun <- deriv(expr, namevec, TRUE)
    derivs <- do.call("fun", as.list(theta))
    derivs <- as.vector(attr(derivs, "gradient"))
    vartheta <- derivs %*% sigma %*% derivs
    setheta <- sqrt(vartheta)
    setheta
}

example:

se.delta(~ x^2 + y^2, c("x", "y"), c(0.5, 1), c(0.001, 0.001))
           [,1]
[1,] 0.07071068

(there must be possible to calculate the namevec argument from the 
formula argument, but I have no time
for that now)

Kjetil
-- 

Kjetil Halvorsen.

Peace is the most effective weapon of mass construction.
               --  Mahdi Elmandjra
#
On Wed, 5 Jan 2005, Kjetil Brinchmann Halvorsen wrote:

            
I believe you are thinking of an example in S Programming, which does 
automatic differentiation and the delta method.

 	-thomas
#
Of course, the delta method is terrible when the first derivative 
is small relative to the curvature.  In that case, you either need to 
consider bootstrap, Monte Carlo, permutation testing, as suggested by 
Venables and Ripley in MASS and S Programming, or possibly using a 
higher order Taylor series expansion. 

      spencer graves
Thomas Lumley wrote: