I was originally running the following code and it was working great:
avg_x1 <- mean(df$x1)
avg_x2 <- mean(df$x2)
avg_x3 <- mean(df$x3)
het_prob <- hetprob(y ~ x1 + x2 + x3 | x1, link="probit", data=df)
test <- deltaMethod(het_prob, "dnorm( (Intercept) + avg_x1*x1 + avg_x2*x2 + avg_x3*x3)")
I now want to tweak this as follows:
avg_x1 <- mean(df$x1)
avg_x2 <- mean(df$x2)
avg_x3 <- mean(df$x3)
het_log <- hetprob(y ~ x1 + x2 + x3 | x1, link="logit", data=df)
test <- deltaMethod(het_log , "dlogis( (Intercept) + avg_x1*x1 + avg_x2*x2 + avg_x3*x3)")
However, I’m getting the error:
“Error in D(g., para.names[i]) :
Function ‘dlogis’ is not in the derivatives table”
Is there any workaround to replace dnorm
with dlogis
in deltaMethod()
?
Can you provide a minimal reproducible example? Is this
deltaMethod
from thecar
package …?Actually, looks like
hetprob
is from theRchoice
package … ??From the error message, you would need to add
dlogis
to the “derivatives table”, but that’s built in to R, so this isn’t easy. Thenlsr::nlsDeriv()
function allows you to add your own derivatives, but then you’d need to modifydeltaMethod()
(or something it uses) to usenlsDeriv()
instead ofD()
.There’s also a
Deriv
package that similarly allows the derivative table to be extended (butdeltaMethod
would still need to be rewritten)Yes, deltaMethod is from the car package and hetprob is from the Rchoice package. I can look into the options you mention, thank you!