Plot conditional densities by group. For describing how the conditional distribution of a categorical variable y changes over a numerical variable x we have the function cdplot. But if we want to compare multiple densities much work is required. PlotConDens allows to easily enter a grouping variable.
PlotConDens(formula, data, col = NULL, lwd = 2, lty = 1, xlim = NULL, rev = TRUE,
args.dens = NULL, ...)
the functions for the curves
a "formula"
of type y ~ x | g
with a single dependent factor
, a single numerical explanatory variable and a grouping factor
g.
a data frame containing values for any variables in the formula. By default the environment where PlotConDens
was called from is used.
a vector of colors to be used to plot the lines. If too short, the values are recycled.
a vector of linewidths to be used to plot the lines. If too short, the values are recycled.
a vector of linetypes to be used to plot the lines. If too short, the values are recycled.
the range for the x axis.
logical, should the values of the response variable be reversed? Default is TRUE
.
additional arguments for the densitiy curves.
the dots are passed on to plot()
.
Andri Signorell <andri@signorell.net>
Especially when we're modelling binary response variables we might want to know, how the binary variable behaves along some numeric predictors.
data(Pima.tr2, package="MASS")
PlotConDens (type ~ age | I((npreg > 0)*1L),
data=Pima.tr2, col=c(hblue, hred), rev=FALSE,
panel.first=quote(grid()))
Run the code above in your browser using DataLab