Under development
The following example compares two estFUN
s. The first performs manipulations of data
outside of the “inner” psiFUN
function. The second performs the manipulations within the returned psiFUN
.
glm_eefun1 <- function(data, model){
f <- grab_psiFUN(model, data)
function(theta){
f(theta)
}
}
glm_eefun2 <- function(data, model){
function(theta){
f <- grab_psiFUN(model, data)
f(theta)
}
}
Now, compare the speed:
##
## Attaching package: 'geex'
## The following object is masked from 'package:methods':
##
## show
library(geepack, quietly = TRUE)
data("ohio")
test_binomial <- glm(resp ~ age, data = ohio,
family = binomial(link = "logit"))
system.time({test <- m_estimate(
glm_eefun1,
data = ohio,
units = 'id',
root_control = setup_root_control(start = coef(test_binomial)),
outer_args = list(model = test_binomial))})
## user system elapsed
## 2.101 0.071 2.576
## user system elapsed
## 12.861 0.662 13.726
method = "simple"
for computing numerical derivativesThe default for the function numDeriv::jacobian
uses the “Richardson” method for computing numerical derivatives, which requires multiple evaluations of each psiFUN
. The “simple” method is much faster, though less accurate. See the numDeriv::jacobian
help page for further options.
# The default uses method = 'Richardson`
system.time({test <- m_estimate(
estFUN = glm_eefun1, data = ohio, units = "id",
roots = coef(test_binomial),
compute_roots = FALSE,
outer_args = list(model = test_binomial))})
## user system elapsed
## 1.572 0.042 1.710
# Using method = "simple"
system.time(update(test,
deriv_control = setup_deriv_control(method = "simple")))
## user system elapsed
## 0.739 0.029 0.791