-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ggpredict unable to plot from a natural spline with specified knots #240
Comments
strange, maybe you updated at a time where the new binaries weren't properly built? For me, it works: library(glmmTMB)
library(splines)
data_e <- data.frame(
positives = c(3L, 2L, 0L, 7L, 0L, 5L, 0L, 3L, 6L, 0L, 2L, 0L, 2L, 3L, 2L, 14L, 1L, 3L, 3L, 0L),
values = c(86.1702127659574, 100, 81.0344827586207, 98.7341772151899, 97.5903614457831,
98.1308411214953, 96.551724137931, 100, 100, 96.045197740113, 99.1150442477876,
98.8888888888889, 100, 91.6279069767442, 33.3333333333333, 0,
92.3076923076923, 24, 0, 93.5483870967742))
m1 <- glmmTMB(
positives ~ ns(values, 3, knots = seq(min(values), max(values), length = 4)[2:3]),
data = data_e,
ziformula = ~ 1,
family = poisson
)
ggeffects::ggpredict(m1, terms="values [all]", type ='zero_inflated')
#> # Predicted counts of positives
#>
#> values | Predicted | 95% CI
#> ----------------------------------
#> 0.00 | 6.41 | [2.65, 10.18]
#> 33.33 | 1.52 | [0.00, 3.04]
#> 86.17 | 1.33 | [0.00, 2.65]
#> 92.31 | 1.82 | [0.52, 3.11]
#> 93.55 | 1.94 | [0.73, 3.15]
#> 96.55 | 2.29 | [1.19, 3.39]
#> 98.13 | 2.50 | [1.36, 3.65]
#> 100.00 | 2.78 | [1.37, 4.18] Created on 2021-10-24 by the reprex package (v2.0.1) |
hmmm...I just updated 2 hours ago. Do you have any troubleshooting suggestions? I uninstalled the previous version of insight on my windows computer and tried to reinstall and got the same error. I have also tried to replicate the problem on a mac but I can't install the updated package. My session info on the mac and windows is below. I will really appreciate any help.
|
I was able to solve the issue by updating my R version and reinstalling all packages. The problem I am having now is that when I fit my final model, I end up with a new error message. See below. The data can be downloaded here. Again, I will appreciate any help.
|
Could you also please upload the fitted model object? It takes hours to fit the model on my machine ;-) |
@strengejacke, thanks for returning to this! The model rds file can be downloaded here |
Not sure what the issue here exactly is, but the function fails when computing the model matrix for the count component of the model: library(splines)
library(glmmTMB)
library(ggeffects)
map2 <- readr::read_csv("D:/Downloads/all_data.csv", show_col_types = FALSE)
#> New names:
#> * `` -> ...1
m2 <- readRDS("D:/Downloads/multivariate_model.rds")
nd <- new_data(m2, "edu_a [all]")
condformula <- lme4::nobars(stats::formula(m2)[-2])
stats::model.matrix(condformula, nd)
#> Error in qr.default(t(const)): NA/NaN/Inf in foreign function call (arg 1) Created on 2021-11-07 by the reprex package (v2.0.1) |
I am having the same issue as @ifeomaozo -- I get this error when trying to use the ggpredict() call and "zero_inflated" type on a fitted glmmTMB object: "Error in get_predictions_glmmTMB(model, data_grid, ci.lvl, linv, type, : Just moving this to the front in case there's been some resolution on it. Thank you! |
@nicholasgrebe Could you resolve the issue by any chance? I am trying to do the same thing (ggpredict with "zero_inflated" type on a fitted glmmTMB object) and receive the same error. Curiously, it just happens with one model specification - for other models, the same command works... |
@jml-science I never had any luck with this package, but using the marginaleffects package was a good substitute (e.g. the "type" argument under the plot_predictions function did what I needed): https://marginaleffects.com/articles/reference/plot_predictions.html |
Note that this issue (#240 (comment)) stems from how standard errors for zero-inflated models are calculated (or better: should be calculated, see https://journal.r-project.org/archive/2017/RJ-2017-066/index.html), so I'm not sure how accurate SE's returned by marginaleffects or library(ggeffects)
library(marginaleffects)
library(glmmTMB)
data(Salamanders)
m1 <- glmmTMB(count ~ mined + (1 | site),
zi = ~mined,
family = poisson, data = Salamanders
)
ggpredict(m1, terms = "mined", type = "zero_inflated")
#> # Predicted counts of count
#>
#> mined | Predicted | 95% CI
#> --------------------------------
#> yes | 0.26 | [0.10, 0.43]
#> no | 2.21 | [1.77, 2.64]
#>
#> Adjusted for:
#> * site = NA (population-level)
avg_predictions(m1, variables = "mined", type = "response", vcov = vcov(m1))
#>
#> mined Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#> yes 0.272 0.0442 6.15 <0.001 30.2 0.185 0.359
#> no 2.265 0.1583 14.31 <0.001 151.8 1.955 2.576
#>
#> Columns: mined, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high
#> Type: response Created on 2023-10-06 with reprex v2.0.2 Another issue is that there were some changes in glmmTMB that changed the behaviour of predict for model with truncated family, see easystats/insight#679 (comment). Maybe when I try to fix #319, this issue here can also be resolved |
@strengejacke, I am reopening this issue since the insight update did not solve the problem. Please see below
The text was updated successfully, but these errors were encountered: