Learn R Programming

Stat2Data (version 2.0.0)

emplogitplot1: Empirical logit plot for one quantitative variable

Description

This function produces an empirical logit plot for a binary response variable and a single quantitative predictor variable.

Usage

emplogitplot1(formula, data = NULL, ngroups = 3, breaks = NULL,
  yes = NULL, padj = TRUE, out = FALSE, showplot = TRUE,
  showline = TRUE, ylab = "Log(Odds)", xlab = NULL,
  dotcol = "black", linecol = "blue", pch = 16, main = "",
  ylim = NULL, xlim = NULL, lty = 1, lwd = 1, cex = 1)

Arguments

formula

A formula of the form (binary) Response~Predictor

data

A dataframe

ngroups

Number of groups to use (not needed if breaks is used), ngroups="all" uses all unique values

breaks

A vector of endpoints for the bins (not needed if ngroups is used)

yes

Set a value for the response to be counted for proportions (optional)

padj

Should proportions be adjusted to avoid zero and one? (default is TRUE)

out

Should the function return a dataframe with group information? (default is FALSE)

showplot

Show the plot? default is TRUE

showline

Show the regression line? default is TRUE

ylab

Text label for the vertical axis (default is "Log(Odds)")

xlab

Text label for the horizontal axis (default is NULL)

dotcol

Color for the dots (default is "black")

linecol

Color for the line (default is "black")

pch

Plot character for the dots (default is 16)

main

Title for plot

ylim

Limits for the vertical axis

xlim

Limits for the horizontal axis

lty

Line type (default is 1)

lwd

Line width (default is 1)

cex

Multiplier for plot symbols

Value

A dataframe with group information (if out=TRUE)

Details

Values of the quantitative explanatory variable will be grouped into ngroups roughly equal sized groups, unless breaks is used to determine the boundaries of the groups. Using ngroups="all" will make each distinct value of the explanatory variable its own group

We find an adjusted proportion for the binary response variable within each of the groups with (Number yes +0.5)/(Number of cases+1). This is converted to an adjusted log odds log(adjp/(1-adjp)). The adjustment avoids problems if there are no "successes" or all "successes" in a group. What constitutes a "success" can be specified with yes= and the proportion adjustment can be turned off (if no group proportions are likely to be zero or one) with padj=FALSE.

The function plots the log odds versus the mean of the explanatory variable within each group. A least square line is fit to these points. The plot can be suppressed with showplot=FALSE.

The out=TRUE option will return a dataframe with the boundaries of each group, proportion, adjusted proportion, mean explanatory variable, and (adjusted or unadjusted) log odds.

Examples

Run this code
# NOT RUN {
data(MedGPA)
emplogitplot1(Acceptance~GPA,data=MedGPA)

GroupTable=emplogitplot1(Acceptance~MCAT,ngroups=5,out=TRUE,data=MedGPA)

emplogitplot1(Acceptance~MCAT,data=MedGPA,breaks=c(0,34.5,39.5,50.5),dotcol="red",linecol="black")

data(Putts1)
emplogitplot1(Made~Length,data=Putts1,ngroups="all")

# }

Run the code above in your browser using DataLab