Type: | Package |
Title: | Combined Graphs for Logistic Regression |
Version: | 1.1 |
Date: | 2025-04-30 |
Depends: | ggplot2 |
Suggests: | popbio |
Description: | Provides histograms, boxplots and dotplots as alternatives to scatterplots of data when plotting fitted logistic regressions. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
NeedsCompilation: | no |
Packaged: | 2025-04-30 19:09:55 UTC; marcelino |
Author: | Marcelino de la Cruz
|
Maintainer: | Marcelino de la Cruz <marcelino.delacruz@urjc.es> |
Repository: | CRAN |
Date/Publication: | 2025-04-30 19:30:02 UTC |
Plot logistic regression
Description
Plot combined graphs for logistic regressions
Usage
logi.hist.plot2(independ, depend, logi.mod = 1, type = "dit",
boxp = TRUE, rug = FALSE, ylabel = "Probability", ylabel2 = "Frequency",
xlabel = "", mainlabel = "", las.h = 1, counts = FALSE, cex.p = 1,
pch.dit = 1, incre = 0.02, ...)
Arguments
independ |
explanatory variable |
depend |
dependent variable, typically a logical vector |
logi.mod |
type of fitting, 1 = logistic; 2 = "gaussian" logistic |
type |
type of representation, "dit" = dot plot; "hist" = histogram |
boxp |
TRUE = with box plots, FALSE = without |
rug |
TRUE = with rug plots, FALSE = without |
ylabel |
y-axis label |
ylabel2 |
2nd y-axis label |
xlabel |
x-axix label |
mainlabel |
overall title for plot |
las.h |
orientation of axes labels (0 = vertical, 1 = horizontal |
counts |
add counts above histogram bars |
cex.p |
size of points in dotplots |
pch.dit |
Either an integer specifying a symbol or a single character to be used as the default in plotting points. See |
incre |
increment, i.e., separation between neighbour points in the dotplot. |
... |
additional options passed to logi.hist |
Value
A combined logistic regression plot
Note
This is a new version of function logi.hist.plot already available in the package popbio. In this new version, control of points in the dot plot is provided by the arguments cex.p
, pch.dit
and incre
.
Author(s)
M. de la Cruz Rot
References
Examples
data(aq.trans, package="popbio")
aq.trans$survived<-aq.trans$fate!="dead"
a<-subset(aq.trans, leaf<50 & stage!="recruit", c(leaf,survived))
logi.hist.plot2(a$leaf, a$survived,
type="hist", boxp=FALSE, counts=TRUE, int=10,
ylabel="Survival probability", ylabel2="Number of plants",
xlab="Number of leaves" )
b<-glm(survived ~ leaf, binomial, data=a)
summary(b)
Combined Graphs for Logistic Regression
Description
Plot combined graphs for logistic regressions in the ggplot2 system.
Usage
logihist(x, y, scale.hist = 5, breaks = "Sturges", counts = TRUE, intervalo = 0,
ylab2 = "Frequency", fillb = 1, colob = 1, sizeb = 1, pglm = FALSE, se = FALSE,
sizeglm = 1, colglm = 1)
logibox(x, y, boxwd = 0.1, wiswd = 0.05, displac = 0, sizepat = 1, fillb = NA, colob = 1,
colpat = 1, colbig = 1, colmed = 1, sizeb = 1, sizebig = 1, sizemed = 2, colout = 1,
sizeout = 1, shapeout = 1, pglm = FALSE, se = FALSE, sizeglm = 1, colglm = 1)
logidot(x, y, incre = NULL, sizedot = NULL, coldot = 1, shapedot = 1, pglm = FALSE,
se = FALSE, sizeglm = 1, colglm = 1)
Arguments
x |
Either the predictor variable or a glm object. |
y |
If |
scale.hist |
Value to scale the maximum vertical size of histograms. |
breaks |
How to compute the breakpoints for the histograms. See |
counts |
Add counts above histogram bars (not implemented in this version). |
intervalo |
Width of histogram bins. |
ylab2 |
Label for the y-axis of the histograms. |
fillb |
Color to fill the histogram bars or the boxes of the boxplots. Either a single value or a vector witth different values for the 0 and 1 cases. |
colob |
Color to delineate the histogram bars or the boxes of the boxplots. Either a single or double value. |
colpat |
Color of the line representing the whiskers in boxplots. |
colbig |
Color of the line representing the end of whiskers in boxplots. |
colmed |
Color of the line representing the median in boxplots. |
colout |
Color of the line representing the outliers in boxplots. |
sizeb |
Width of the lines that delineate the histogram bars or the boxes of the boxplots. |
boxwd |
Width of the boxes in boxplots. |
wiswd |
Size of the end of whiskers in boxplots. |
sizebig |
Width of the line representing the end of whiskers in boxplots. |
sizepat |
Width of the line representing the whiskers in boxplots. |
sizemed |
Width of the line representing the median in boxplots. |
sizeout |
Size of the points representing the outliers in boxplots. |
shapeout |
Shape of the points representing the outliers. See the entry for |
displac |
Vertical displacement of boxplots along the y-axis. |
incre |
Separation among points in the dotplot. |
sizedot |
Size of points in the dotplot. |
coldot |
Color of points in the dotplot. |
shapedot |
Shape of the points in the dotplot. See the entry for |
pglm |
Draw the fitted logistic curve? (TRUE or FALSE). |
se |
Draw the standard error around the fitted logistic curve?(TRUE or FALSE). |
sizeglm |
Width of the line for the fitted fitted logistic curve. |
colglm |
Color of the line for the fitted fitted logistic curve. |
Details
The use of functions logihist
, logibox
or logidot
will render a combined graph for logistic regression. Either a double histogram, a double boxplot or a double dotplot, which could be modified or integrated with other graphical elements of ggplot2
.
Value
A combined graph for logistic regression.
Note
logidot
would try to find the optimal size of dots to avoid overlaping. The default computed sizes and separation could be fine-tunned by the arguments sizedot
and incre
.
Author(s)
Marcelino de la Cruz
References
See Also
The original implementation of the logi.hist.plot
function for the R graphic sytem in the package popbio.
Examples
# Get some data from package popbio
data(aq.trans, package="popbio")
aq.trans$survived<-aq.trans$fate!="dead"
a <-subset(aq.trans, leaf<50 & stage!="recruit", c(leaf,survived))
# Transform the "survived" variable in numeric
# This is necesary to correctly plot the combined graph.
a$survived <-a$survived*1
# Fit a logistic regression
glm.a<- glm(survived~leaf, data=a, family=binomial)
# Histograms
# From individual variables
# Modifying the appearence of histogram bins
logihist(a$leaf, a$survived)
logihist(a$leaf, a$survived, fillb="blue")
logihist(a$leaf, a$survived, fillb="blue", colob="blue")
logihist(a$leaf, a$survived, fillb=c("orange","blue"), colob=c("orange","blue"))
logihist(a$leaf, a$survived, fillb=c("orange","blue"), colob=c("orange","blue"),
scale.hist=2)
logihist(a$leaf,a$survived, fillb=c("orange","blue"), colob=c("orange","blue"),
breaks=seq(0,50, by=2))
# Modifying the combined plot using functions from ggpplot2
logihist(a$leaf, a$survived, fillb=NA, sizeb=0.5, ylab2="Number of plants") +
ylab("survived") + xlab("leaf") + stat_smooth(method = "glm", method.args =
list(family = "binomial"), se=TRUE, linewidth=1, colour="black") + theme_light()
# The same from a glm object
logihist(glm.a, fillb=NA, sizeb=0.5, ylab2="Number of plants", se=TRUE)+
theme_light()
# Dotplots
# Double dotplot from the individual variables, with different symbols for
# 0 and 1 categories (black and void, redand solid respectively).
logidot(a$leaf, a$survived, coldot=c(1,2), shapedot=c(1,19))
# Try with a larger dot.
logidot(a$leaf, a$survived, coldot=c(1,2), shapedot=c(1,19), sizedot=1)
# Add the fitted logistic curve and change the presentation using
# respectively a stat and a theme from ggplot2
logidot(a$leaf,a$survived, coldot=c(1,2),shapedot=c(1,19), sizedot=1)+
stat_smooth(method = "glm", method.args = list(family = "binomial"),
se=FALSE, size=2) + theme_light() + ylab("leaf")+xlab("survived")
# Get the same graphic directly form the fitted glm object
logidot(glm.a, coldot=c(1,2),shapedot=c(1,19), sizedot=1, sizeglm=2,
colglm="blue") + theme_light()
# Boxplots
logibox(a$leaf,a$survived)+theme_light()+ stat_smooth(method = "glm",
method.args = list(family = "binomial"),se=FALSE )+
geom_jitter(height=0.02, size=0.5, colour="pink", alpha=0.5)