Closed smaskevich closed 1 year ago
Sorry for the late reply here -- my guess is that this is the same issue as #98; can you please check that thread and see if it solves your problem?
Briefly, the issue is that subsetting "on the fly" used to work, but some things changed in R 4.0 and not all these bugs have been caught yet. This semester is hectic and I haven't had time to repairing these issues, but a simple workaround is just to create the subset as a separate data frame along the lines of:
Sub <- subset(original_data, subset_condition)
fit <- lmer(..., data=Sub)
Does this help?
Closing this issue since I never heard back from you.
Fistly, thank you for this amaizing package I have been using it to create plots for publications of my research.
I recently started encountering an error while trying to plot one of my models (not all). I have tried to see if anyone else encountered the same problem, however, did not find anything.
When I use visreg to plot a models, in which I remove outliers (m2.ne1) I get an error : "Error in exists(as.character(CALL$data), call.env) : first argument has length > 1".
This script used to work in the past (prior to July 2021). The same script works for the initial model (m2 - outliers not removed). In addition, m2.ne1 works perfectly through: plot(ggpredict(m2.ne1, terms = c("BBTd", "COND"))).
These are the scripts I use for your reference: m2 <- lmer(TIB ~ BBTd * COND + WBTd + SEX + BORN + WHITE + StudyDay + (1 + WBTd | ID), data = d, REML = FALSE, control = strictControl)
m2.diag <- modelDiagnostics(m2, ev.perc = .0001) plot(m2.diag, ask = FALSE, ncol = 2, nrow = 3) m2.extreme <- subset(m2.diag$extremeValues, EffectType != "Residuals") unique(m2.extreme$ID)
[1] 1309 1150
m2.ne <- update(m2, data = subset(d,!(ID %in% unique(m2.extreme$ID)))) m2.ne.diag <- modelDiagnostics(m2.ne, ev.perc = .0001) plot(m2.ne.diag, ask = FALSE, ncol = 2, nrow = 3) m2.ne.extreme <- subset(m2.ne.diag$extremeValues, EffectType != "Residuals") unique(m2.ne.extreme$ID)
[1] 1183
m2.ne1 <- update(m2, data = subset(d,!(ID %in% c(unique(m2.extreme$ID), unique(m2.ne.extreme$ID))))) m2.ne1.diag <- modelDiagnostics(m2.ne1, ev.perc = .0001) plot(m2.ne1.diag, ask = FALSE, ncol = 2, nrow = 3) m2.ne1.extreme <- subset(m2.ne1.diag$extremeValues, EffectType != "Residuals") unique(m2.ne1.extreme$ID)
integer(0)
fig.mBBTd <- visreg(m2.ne1, xvar = "BBTd", by = "COND", overlay=TRUE, breaks = c(0, 1), partial = FALSE, rug = FALSE, gg=TRUE, xlab = "Actual-planned bedtime (between-person)", ylab = "Time in bed") + scale_color_manual(values = c("1" = "black", "0" = "grey70")) + coord_cartesian(ylim = c(3, 12)) + scale_y_continuous(breaks=c(4, 6, 8, 10, 12)) + theme_pubr() + guides(colour = "none", fill = "none") + annotate(geom = "text", x = 2.5, y = 8.8, label = "paste(\"Non-school: \",italic(b), \" = -0.25 [-0.38, -0.12], \",italic(p), \" < .001\")", parse = TRUE, angle = -8.5, size = 5) + annotate(geom = "text", x = 2.5, y = 7.5, label = "paste(\"School: \",italic(b), \" = -0.42 [-0.57, -0.28], \",italic(p), \" < .0001\")", parse = TRUE, angle = -13.5)
Thank you for your continuous support!
Best wishes, Svetlana