interactions
interactions copied to clipboard
probe_interaction function can not calculate the interaction effect of panelr's wbm object
Hello, I found out the probe_interaction function can not calculate the interaction effect of panelr's wbm object.
How can I resolve it?
Best, Seongho
Hello,
I am also facing the same issue and find Johnson Neyman intervals and the panelr incredibly useful for interactions of panel data and know you have developed both packages. Here is a reprex using example dataset wages from the panelr package
# Load packages
library(panelr)
library(interactions)
# Example data in panelr package
wages <- panel_data(WageData, id = id, wave = t)
# Run example model
examplemod <- wbm(lwage ~ wks*exp + ms + occ, data = wages, model = "within")
# Get johnson-neyman intervals and simple slopes
interactions::sim_slopes(examplemod, pred = wks, modx = exp, jnplot = TRUE)
And here is the error I get:
Error: ~does not appear to be a one- or two-sided formula.
lwagedoes not appear to be a one- or two-sided formula.
wks * exp + ms + occdoes not appear to be a one- or two-sided formula.
Backtrace:
1. interactions::sim_slopes(...)
2. jtools::get_data(model)
4. jtools:::get_lhs(formula)
Thanks, I hope to tackle this soon. The issues are unfortunately very complex and thus far I've preferred to let the errors happen rather than having the potential for misleading results.
Hi Jacob,
I have managed to work out a way to get johnson-neyman intervals by modifying the lmer object produced. Perhaps this may be helpful for the package. The values make sense to me, what do you think?
# Load packages
library(panelr)
library(interactions)
### Create true model
# Example data in panelr package
wages <- panel_data(WageData, id = id, wave = t)
# Run example model
examplemod <- wbm(lwage ~ wks*exp + ms + occ, data = wages, model = "within")
#extract de-meaned + double-demeaned data
examplemod_demeaned <- examplemod@frame[,c("id","t","wks","exp","wks:exp","ms","occ","lwage")]
colnames(examplemod_demeaned)[5] <- "wks.exp"
#create lmer model (same as wbm)
examplemod_lmer <- lmer(lwage ~ wks + exp +
wks.exp
+ ms + occ + (1 | id), data = examplemod_demeaned)
### Create "dummy" lmer model (to modify for predictions)
#dummy model
examplemod_lmer_dum <- lmer(lwage ~ wks+ exp +
wks:exp
+ ms + occ + (1 | id), data = examplemod_demeaned)
#changing var names so calculating interaction effects is easier
examplemod_lmer@call <- examplemod_lmer_dum@call
examplemod_lmer@frame <- examplemod_lmer_dum@frame #make the raw data the same
obj1 <- merPredD(X=examplemod_lmer@pp$X,
Zt=examplemod_lmer@pp$Zt,
Lambdat=examplemod_lmer@pp$Lambdat,
Lind=examplemod_lmer@pp$Lind,
theta=examplemod_lmer@pp$theta,
n=nrow(examplemod_lmer@pp$X))
Xold <- Xnew <- examplemod_lmer@pp$X
colnames(Xnew)[4] = "wks:exp"
examplemod_lmer@pp <- merPredD(X=Xnew,
Zt=examplemod_lmer@pp$Zt,
Lambdat=examplemod_lmer@pp$Lambdat,
Lind=examplemod_lmer@pp$Lind,
theta=examplemod_lmer@pp$theta,
n=nrow(examplemod_lmer@pp$X))
# Get johnson-neyman intervals and simple slopes
interactions::sim_slopes(examplemod_lmer, pred = wks, modx = exp, jnplot = TRUE)