partial_plot: Partial Regression Plots for visualizing relationship between...

Description Usage Arguments Value Methods (by class) Examples

View source: R/partial_plot.R

Description

partial_plot accepts a fitted regression object and the name of the variable you wish to view the partial regression plot of as a character string. It returns a ggplot object showing the independent variable values on the x-axis with the resulting predictions from the independent variable's values and coefficients on the y-axis. This shows the relationship that the model has estimated between the independent variable the dependent variable. You can determine which prediction level the plot is against using the response parameter which is a logical value defaulted to FALSE.

Usage

1
2
3
4
partial_plot(fitted_model, ...)

## S3 method for class 'gam'
partial_plot(fitted_model, variable, response = F, rug = F)

Arguments

fitted_model

a complete regression model object

variable

the name of the independent variable as a character string

response

logical indicating if the plot should be on the linear prediction scale or the response scale. Defaults to FALSE

rug

logical indicating if a rug plot should be added on the independent variable axis

Value

a ggplot2 object of the partial regression plot

Methods (by class)

Examples

1
2
3
4
5
6
7
8
library(mgcv)
car_gam <- gam(mpg ~ s(hp), data = mtcars)
partial_plot(car_gam, "hp")

# Response level changes look for non-gaussian families
am_gam <- gam(factor(am) ~ s(hp), data = mtcars, family = "binomial")
partial_plot(am_gam, "hp") # on the log odds scale
partial_plot(am_gam, "hp", response = T) # on the probability scale

mattmills49/modeler documentation built on May 21, 2019, 1:25 p.m.