Skip to content
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

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

Open
seonghobae opened this issue Mar 17, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@seonghobae
Copy link

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

@richardneilbelcher
Copy link

richardneilbelcher commented Oct 19, 2021

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)

@jacob-long
Copy link
Owner

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 jacob-long added the enhancement New feature or request label Apr 14, 2022
@richardneilbelcher
Copy link

richardneilbelcher commented Feb 15, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants