This function produces an empirical logit plot for a binary response variable and with a single quantitative predictor variable broken down by a single categorical factor.
emplogitplot2(formula, data = NULL, ngroups = 3, breaks = NULL,
yes = NULL, padj = TRUE, out = FALSE, showplot = TRUE,
showline = TRUE, ylab = "Log(Odds)", xlab = NULL,
putlegend = "n", levelcol = NULL, pch = NULL, main = "",
ylim = NULL, xlim = NULL, lty = NULL, lwd = 1, cex = 1)
A formula of the form (binary) Response~Quantitative Predictor+Factor
A dataframe
Number of groups to use (not needed if breaks is used), ngroups="all" uses all unique values
A vector of endpoints for the bins (not needed if ngroups is used)
Set a value for the response to be counted for proportions (optional)
Should proportions be adjusted to avoid zero and one? (default is TRUE)
Should the function return a dataframe with group and factor information? (default is FALSE)
Show the plot? default is TRUE
Show the regression lines? default is TRUE
Text label for the vertical axis (default is "Log(Odds)")
Text label for the horizontal axis (default is NULL)
Position for the legend (default is "n" for no legend)
Vector of colors for the factor levels
Plot character for the dots
Title for plot
Limits for the vertical axis
Limits for the horizontal axis
Line type (default is 1)
Line width (default is 1)
Multiplier for plot symbols
A dataframe with group information (if out=TRUE)
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 a proportion for the binary response variable within each of the groups created from
the quantitative variable crossed with the categrical variable. To avoid problems with proportions
of zero and one, we compute an adjusted proportion with
(Number yes +0.5)/(Number of cases+1)
. This is converted to an adjusted log odds
log(adjp/(1-adjp))
. 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 with different
colors for each of the categories defined by the categorical variable.
A least square line is fit to these points within each categorical group.
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.
# NOT RUN {
data(MedGPA)
emplogitplot2(Acceptance~GPA+Sex,data=MedGPA)
GroupTable2=emplogitplot2(Acceptance~MCAT+Sex,ngroups=5,out=TRUE,data=MedGPA,putlegend="topleft")
emplogitplot2(Acceptance~MCAT+Sex,data=MedGPA,breaks=c(0,34.5,39.5,50.5),
levelcol=c("red","blue"),putlegend="bottomright")
# }
Run the code above in your browser using DataLab