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

ggeffects capabilities with spatail regression model objects #474

Open
amikulas opened this issue Mar 29, 2024 · 2 comments
Open

ggeffects capabilities with spatail regression model objects #474

amikulas opened this issue Mar 29, 2024 · 2 comments
Labels
reprex 💾 An example (and data) to reproduce the issue is needed to

Comments

@amikulas
Copy link

This is a great package. Incredibly useful for plotting models with complicated interaction terms.

I use spatial regression and I am trying to use ggeffects with a model object, type Sarlm (produced from the spatialreg R package, errorsarlm model).

When I try to use any ggeffects command, I get errors like this:

> ggpredict(Sarlm_model,
          terms = c("var1_continuous"))

Error in show_pretty_message && model_info$is_binomial :  invalid 'y' type in 'x && y'

Additionally, margins does not work with these model objects. When I attempt margins, I get errors like:

> margins(Sarlm_model, variables = "var1_continuous")

Error in x$terms %||% attr(x, "terms") %||% stop("no terms component nor attribute") : 
  no terms component nor attribute

It does not look like ggeffects currently supports Sarlm objects based on the model object list here.

These model objects also do not work for any commands in the margins package. They can be accessed by the insights package.

I have two questions. The first is if you know of ggeffects work arounds for these types of model objects. I have looked into how ggeffects uses the insight package to index model parameters, and I do not think the issue is with insight. The issue may lie with margins, however, if ggeffects employs margins dependencies. My issue may also be related to closed issue number 93.

The second is if you would consider and update that allows ggeffects to work with Sarlm objects. I know many (at least online, here and here) are trying to figure out how to model and plot interaction effects with spatial data sets and spatial regression model output.

The issue may be in that these models predict coefficients (direct effect), lag coefficients (indirect effect), and a lamda (effect of spatially autocorrelated OLS errors). These coefficients effects are uninterpretable unless you calculate the total effect (direct + indirect-lag effect + error effect), total SE, and total p-value for each model term. The spatailreg::impacts function does this.

@strengejacke
Copy link
Owner

Do you have a reproducible example?

@strengejacke strengejacke added the reprex 💾 An example (and data) to reproduce the issue is needed to label Mar 30, 2024
@amikulas
Copy link
Author

amikulas commented Apr 1, 2024

I do. The attached rscript should work as is if you have the packages installed. Be warned, Mac users may need additional dependencies to use the spdep and sf packages, as they access the machine's existing geospatial programming.

ggeffects_help.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reprex 💾 An example (and data) to reproduce the issue is needed to
Projects
None yet
Development

No branches or pull requests

2 participants