-
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
Issue generating adjusted predictions with wbm-models #622
Comments
This could be an issue in panelr's FWIW, dataset__wide <- read.csv(file = "~/../Downloads/dataset__wide.csv")
library(panelr)
# Pivot data to long.
dataset__long <- dataset__wide |>
tidyr::pivot_longer(
# Exclude the time-invariant variables
!c(
ID,
Control,
),
names_to = "Variables", values_to = "Values"
) |>
dplyr::mutate(
# Create a variable keeping track of the waves.
Wave = dplyr::case_when(
stringr::str_detect(string = Variables, pattern = "t1") ~ 0,
stringr::str_detect(string = Variables, pattern = "t2") ~ 1,
TRUE ~ NA_real_
),
# Create a variable to standardize the variable names.
Variable = dplyr::case_when(
!(is.na(Variables)) ~ stringr::str_replace_all(string = Variables, pattern = "(_+((t1)|(t2)))", replacement = ""),
TRUE ~ Variables
),
) |>
dplyr::select(
!Variables
) |>
tidyr::pivot_wider(names_from = Variable, values_from = "Values", values_fill = NA_real_)
# Create a panel data frame.
dataset__long__panel <- panel_data(data = dataset__long, id = ID, wave = Wave)
# Fit the panel model
panel_model <- wbm(
formula = DV ~ IV + M | Control | IV*M,
data = dataset__long__panel,
family = binomial(link = "logit"),
use.wave = TRUE,
wave.factor = TRUE,
weights = Weights,
scale = TRUE,
model = "between",
control = glmerControl(optimizer = "bobyqa")
)
d <- expand.grid(lapply(dataset__long__panel[c("IV", "M")], unique))
predict(panel_model, newdata = d)
#> Error in complete.cases(data[[variable]]): no input has determined the number of cases
d <- ggeffects::data_grid(panel_model, c("IV", "M"))
predict(panel_model, newdata = d)
#> Unordered factor wave variable was converted to ordered. You should check
#> that the order is correct.
#> Error in complete.cases(data[[variable]]): no input has determined the number of cases Created on 2024-12-17 with reprex v2.1.1 |
Thanks @strengejacke for the suggestion to use
You can consider my initial issue (of generating adjusted predictions) solved. However, to shed more light on the earlier problem, I was interested in the methodology applied by this paper: https://doi.org/10.1177/1940161224129270. The author(s) have (graciously) provided the replication dataset [(.Rdata)] (https://drive.google.com/file/d/1a-OPCFA3N0ZC8MNvtA2yp-AzVyXCrV75/view?usp=sharing) and code to generate the interaction plot online. I have extracted the relevant portions of the code below. I find it odd that
Anyways, just wanted to share that this package is really valuable to academic research and I would like to express my sincerest thanks to you (and the other maintainers) for all your efforts on this amazing package! |
I'm facing some issue generating adjusted predictions with
wbm
models. My intention is to generate an interaction plot withggpredict
. However, it keeps issuing the following error:I'm unable to resolve this error. May I know if the
ggeffects
package is compatible withwbm
panel models?I've included a replication dataset here: dataset__wide.csv.
Below is the code to prepare the dataset and run the model.
The text was updated successfully, but these errors were encountered: