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

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to