prop_ci: Confidence intervals for binary target variable by values of...

View source: R/deprec-all.R

prop_ciR Documentation

Confidence intervals for binary target variable by values of a discrete predictor

Description

For a data frame input, one variable is a binary target (target_name) and another is selected to be a predictor variable (var_name). Mean response and a confidence interval is calculated for the target variable for each level or value of the predictor. The results are plotted and returned as a table. The function most appropriate for factor predictors but will work with other variable types also.

Usage

prop_ci(
  dt,
  target_name,
  var_name,
  min_n = 1,
  show_all = TRUE,
  order_n = NULL,
  conf_level = 0.95,
  prop_lim = NULL,
  pos_class = NULL,
  plot = TRUE,
  return_plot = FALSE
)

Arguments

dt

A data frame.

target_name

Column to use as target variable. Column name (quoted or unquoted) or position.

var_name

Column to use as predictor variable. Column name (quoted or unquoted) or position.

min_n

Integer >= 1. Predictor levels with less than min_n observations are not displayed.

show_all

Logical. Defaults to TRUE. If FALSE will not show levels whose confidence interval overlaps the mean response of all observations.

order_n

Logical. Whether to force plot and table to order by number of observations of the predictior. The default setting NULL retains ordering if predictor is numeric or ordered factor and orders by number of observations otherwise.

conf_level

Numeric in (0,1). Confidence level used for confidence intervals.

prop_lim

Optional x axis limits passed to ggplot() e.g. c(0,1).

pos_class

Optional. Specify value in target to associate with class 1.

plot

Optional logical. Output a plot or not.

return_plot

Optional logical. If TRUE the plot is returned instead of the table (this overrides plot argument).

Details

The target variable must be binary. Top compute confidence intervals this is converted to 0 and 1 values. If it is not obvious which value corresponds to 1 and which to 0 then it will be based on level order if a factor and the first observation otherwise. Giving the value of corresponding to 1 in the argument pos_class will override this.

Use the plot and return_plot arguments to control output. By default (designed to be used interactively) returns a table and prints a plot. If return_plot = TRUE then just the plot is returned. If return_plot = FALSE and plot = FALSE then the table is returned and no plot is generated. The default


jedwards24/edwards documentation built on Sept. 2, 2023, 8:16 a.m.