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

Add a plot_predictions() or equivalent function #300

Open
gavinsimpson opened this issue Jul 25, 2024 · 0 comments
Open

Add a plot_predictions() or equivalent function #300

gavinsimpson opened this issue Jul 25, 2024 · 0 comments

Comments

@gavinsimpson
Copy link
Owner

The marginaleffects package has a plot_predictions() function which combines (from a gratia viewpoint) data_slice() with fitted_values().

It has a condition argument which allows the user to either specify up to four covariates via a character vector or a named list (names of the list are covariate labels). The order of the covariates in the vector/list are used for:

  1. x-axis,
  2. colour / shape,
  3. facet variable 1
    • if only three covariates specified this is passed to facet_wrap(), or
    • if four covariates are specified this is is the column facet variable in facet_grid()
  4. facet variable 2, for the rows of facet_grid().

The character vector form requires some defaults for generating data:

  • if the covariate is numeric (which the first covariate should really be for a GAM) then we would spread n values evenly over that covariate. For numeric covariates 2-4, then we should compute a smaller set of values (Tukey's fivenum is the default in plot_predictions()). The list version in plot_predictions() allows greater customisation of the generated numbers.
  • for factors, just use the levels of the named factor

The list form allows more flexibility; not sure I will implement everything. It allows:

  • name of covariate as a length 1 character vector. If this is used, then the behaviour for that covariate is as per the character vector form, above,
  • a function, the output of which defines the values used in the data slice for the covariate,
  • a character string of in-built summaries ("minmax", "threenum", "quartile", where "threenum" is -SD, mean, +SD.

Can't call this plot_predictions as that will clash with marginaleffects and users (including me) should want to use both packages for interrogating GAMs. Also, following my design principles for the package, it would be good to return a data frame of the required predicted values (with attributes to inform on conditioning variables) and then have a draw() method for that object. Will need a subsetting method for [ if I do this...

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

No branches or pull requests

1 participant