deltamethod               package:msm               R Documentation

_T_h_e _d_e_l_t_a _m_e_t_h_o_d

_D_e_s_c_r_i_p_t_i_o_n:

     Delta method for approximating the standard error of a
     transformation g(X) of a random variable X = (x1, x2, ...), given
     estimates of the mean and covariance matrix of X.

_U_s_a_g_e:

     deltamethod(g, mean, cov, ses=TRUE)

_A_r_g_u_m_e_n_t_s:

       g: A formula representing the transformation. The variables must
          be labelled 'x1, x2,...' For example,

          '~ 1 / (x1 + x2)'

          If the transformation returns a vector, then a list of
          formulae representing (g1, g2, ...) can be provided, for
          example

          'list( ~ x1 + x2,    ~ x1 / (x1 + x2) )'

    mean: The estimated mean of X

     cov: The estimated covariance matrix of X

     ses: If 'TRUE', then the standard errors of g1(X), g2(X),... are
          returned. Otherwise the covariance matrix of g(X) is
          returned.

_D_e_t_a_i_l_s:

     The delta method expands a differentiable function of a random
     variable about its mean, usually with a first-order Taylor
     approximation, and then takes the variance. For example, an
     approximation to the covariance matrix of g(X) is given by


                 Cov(g(X)) = g'(mu) Cov(X) [g'(mu)]^T


     where mu is an estimate of the mean of X.

     A limitation of this function is that variables created by the
     user are not visible within the formula 'g'.  To work around this,
     it is necessary to build the formula as a string, using functions
     such as 'sprintf', then to convert the string to a formula using
     'as.formula'.  See the example below.

_V_a_l_u_e:

     A vector containing the standard errors of g1(X), g2(X), ... or a
     matrix containing the covariance of g(X).

_A_u_t_h_o_r(_s):

     C. H. Jackson chris.jackson@imperial.ac.uk

_R_e_f_e_r_e_n_c_e_s:

     Oehlert, G. W. _A note on the delta method_. American Statistician
     46(1), 1992

_E_x_a_m_p_l_e_s:

     ## Simple linear regression, E(y) = alpha + beta x 
     x <- 1:100
     y <- rnorm(100, 4*x, 5)
     toy.lm <- lm(y ~ x)
     estmean <- coef(toy.lm)
     estvar <- summary(toy.lm)$cov.unscaled

     ## Estimate of (1 / (alphahat + betahat))
     1 / (estmean[1] + estmean[2])
     ## Approximate standard error
     deltamethod (~ 1 / (x1 + x2), estmean, estvar) 

     ## We have a variable z we would like to use within the formula.
     z <- 1
     ## deltamethod (~ z / (x1 + x2), estmean, estvar) will not work.
     ## Instead, build up the formula as a string, and convert to a formula.
     form <- sprintf("~ %f / (x1 + x2)", z)
     form
     deltamethod(as.formula(form), estmean, estvar)

