ggplot.score_profile: Plot a 'score_profile' object.

View source: R/score_profile.R

ggplot.score_profileR Documentation

Plot a score_profile object.

Description

ggplot method for class ‘score_profile’

Usage

## S3 method for class 'score_profile'
ggplot(x, i.var = NULL, n.type = "boxplot",
  f.type = "percent", statistic = "mean", geom = "point",
  legend.position = NULL, col = NULL, size = NULL, nrows = NULL,
  ncols = NULL, xlab = NULL, ...)

Arguments

x

An object of class score_profile.

i.var

A numeric vector of indices of the variables to plot. The variables should be indexed in the same order that they appear in the initial inspect_balance formula. The default is to plot all variables.

n.type

The type of plot for numeric variables. Boxplots are generated by default. For alternative summary statistics, use summary.

f.type

The type of plot for categorical variables. 100 percent stacked columns are generated by default. The alternative option is counts, which show stacked columns of counts.

statistic

Functions that operate on a vector and produce a single value, as mean and sd do. It may be a user-defined function.

geom

The geometric object to display the data. Argument is passed to ggplot2::stat_summary when type = summary. For type = summary, geom = "point".

legend.position

The position of legends ("left", "right", "bottom", "top"). The default is "right".

col

Color of geom. The default is "red".

size

Size of geom. The default is 2.

nrows

Number of rows for plots.

ncols

Number of columns for plots.

xlab

Title for the x.

...

Additional arguments passed to ggplot2::stat_summary.

Author(s)

Leo Guelman leo.guelman@rbc.com

Examples


set.seed(123)
N <- 10000
eps <- rnorm(N)
age <- round(rnorm(N, 50, 10))
income <- rnorm(N, 60000, 10000) + 200 * age
gender <- gl(2, N/2,  labels = c("F", "M"))
insurance <- gl(4, N/4,  labels = c("HOME", "AUTO", "LIFE", "HEALTH"))
z <- 1e-01 + 0.1 * age - 1e-04 * income + 0.3 * (gender == "F") + eps
pr <- 1 / (1 + exp( -z))
purchase <- rbinom(N, 1, pr)
df <- data.frame(purchase, age, income, gender, insurance)
### Fit glm
pred <- fitted(glm(purchase ~ age + income + gender,
                  data = df, family = "binomial"))
profileForm <- pred ~ age + income + gender + insurance
prof1 <- score_profile(profileForm, data = df)
prof1
ggplot(prof1)

leoguelman/uplift2 documentation built on April 15, 2022, 4:34 a.m.