R: Get marginal effects for polynomial terms

ggpoly {ggeffects} | R Documentation

## Get marginal effects for polynomial terms

### Description

`ggpoly()` computes marginal effects for polynomial terms. The result is returned as tidy data frame.

### Usage

    ggpoly(model, poly.term, ci.lvl = 0.95, ...)

### Arguments

`model` | A fitted model object, or a list of model objects. Any model that is supported by the effects-package should work.
`poly.term` | Name of the polynomial term in `model`, as string.
`ci.lvl` | Numeric, the level of the confidence intervals. For `ggpredict()`, use `ci.lvl = NA`, if confidence intervals should not be calculated (for instance, due to computation time).
`...` | Further arguments passed down to `effect`.

### Details

`ggpoly()` is just an alternative call to `ggpredict()` for polynomial model terms. It internally calls `effect()` from effects (like `ggeffect()` does), hence it may work for certain models that are not yet supported by `ggpredict()`. Otherwise, there should be no difference in the results from `ggpoly()` and `ggpredict()`, or at least only minor differences (as `effect()` holds categorical covariates constant at other values, see 'Details' in ggeffect).

### Value

A tibble (with `ggeffects` class attribute) with consistent data columns:

`x`

  the values of the first term in `terms`, used as x-position in plots.

`predicted`

  the predicted values, used as y-position in plots.

`conf.low`

  the lower bound of the confidence interval for the predicted values.

`conf.high`

  the upper bound of the confidence interval for the predicted values.

`group`

  the grouping level from the second term in `terms`, used as grouping-aesthetics in plots.

### Examples

    data(efc)
    fit <- lm(
      tot_sc_e ~ c12hour + e42dep + e17age + I(e17age^2) + I(e17age^3),
      data = efc
    )
    dat <- ggpoly(fit, "e17age")

    # this would give the same result
    ggpredict(fit, "e17age")

    library(ggplot2)
    ggplot(dat, aes(x, predicted)) +
      stat_smooth(se = FALSE) +
      geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .15) +
      labs(x = get_x_title(dat), y = get_y_title(dat))

    ## Not run:
    # or:
    plot(dat)
    ## End(Not run)

[Package ggeffects version 0.4.0 Index]