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

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.

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.

Note

ggpoly() is just an alternative call to ggpredict() for polynomial model terms. 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().

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")
#> Following variables had many unique values and were prettified: e17age. Use `pretty = FALSE` to get smoother plots with all values, however, at the cost of increased memory usage.
#> # A tibble: 9 x 5 #> x predicted conf.low conf.high group #> <int> <dbl> <dbl> <dbl> <fct> #> 1 65 1.25 0.963 1.54 1 #> 2 70 0.982 0.841 1.12 1 #> 3 75 0.934 0.797 1.07 1 #> 4 80 0.999 0.885 1.11 1 #> 5 85 1.07 0.938 1.20 1 #> 6 90 1.04 0.873 1.20 1 #> 7 95 0.793 0.479 1.11 1 #> 8 100 0.231 -0.556 1.02 1 #> 9 105 -0.759 -2.42 0.898 1
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))
#> `geom_smooth()` using method = 'loess'
# NOT RUN { # or: plot(dat) # }