[R] g parameter for deltaMethod() as a function
    Marc Girondot 
    marc_grt at yahoo.fr
       
    Tue Jan 31 11:59:48 CET 2017
    
    
  
Dear John and list members,
I have found a solution using the package nlWaldTest. I post the 
solution in case someone else will have this problem.
Here is a summary of the problem:
I would like use the delta method for a function for which no derivative 
using D() can be calculated. I would like rather use numerical derivative.
Here is the solution. In the two first examples, symbolic derivative is 
used.
library(car)
m1 <- lm(time ~ t1 + t2, data = Transact)
deltaMethod(coef(m1), "t1/t2", vcov.=vcov(m1))
library("nlWaldTest")
nlConfint(obj = NULL, texts="b[2]/b[3]", level = 0.95, coeff = coef(m1),
           Vcov = vcov(m1), df2 = TRUE, x = NULL)
############# Now numerical derivative is used. The result is the same.
try_g <- function(...) {
   par <- list(...)
   return(par[[1]]/par[[2]])
}
nlConfint(obj = NULL, texts="try_g(b[2], b[3])", level = 0.95, coeff = 
coef(m1),
           Vcov = vcov(m1), df2 = TRUE, x = NULL)
Marc
    
    
More information about the R-help
mailing list