interactions icon indicating copy to clipboard operation
interactions copied to clipboard

probe_interaction function can not calculate the interaction effect of panelr's wbm object

Open seonghobae opened this issue 5 years ago • 3 comments

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

seonghobae avatar Mar 17 '20 02:03 seonghobae

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)

richardneilbelcher avatar Oct 19 '21 09:10 richardneilbelcher

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.

jacob-long avatar Apr 14 '22 16:04 jacob-long

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)

richardneilbelcher avatar Feb 15 '23 10:02 richardneilbelcher