I have a follow-up to the post Regression (logistic) in R: Finding x value (predictor) for a particular y value (outcome).
I have a more complex model:
b1 <- glmmTMB(lambda ~ species * period * ffd_stan + (1|SITE_COUNTY),
data = fives)
where species
(5 species) and period
(3 periods) are categorical and ffd_stan
is numeric. I want to calculate the predicted values of the predictors when lambda = 0 (essentially at what value of ffd_stan
does the population growth not change for each of the species and period combinations).
I know I can build a data frame to predict lambda for many values of ffd_stan
but I would love to be able to do this in a more efficient manner. I'm not sure either how to adapt the following code or whether there is a better solution for my data
findInt <- function(model, value) {
function(x) {
predict(model, data.frame(mpg=x), type="response") - value
}
}
uniroot(findInt(model, .5), range(mtcars$mpg))$root