R: Plot Conditional Densities

PlotConDens {DescTools} | R Documentation

## Plot Conditional Densities

### Description

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.

### Usage

    PlotConDens(formula, data, col = NULL, lwd = 2, lty = 1, xlim = NULL, rev = TRUE,
                args.dens = NULL, ...)

### Arguments

`formula` | a `"formula"` of type `y ~ x | g` with a single dependent `factor`, a single numerical explanatory variable and a grouping `factor` g.
`data` | a data frame containing values for any variables in the formula. By default the environment where `PlotConDens` was called from is used.
`col` | a vector of colors to be used to plot the lines. If too short, the values are recycled.
`lwd` | a vector of linewidths to be used to plot the lines. If too short, the values are recycled.
`lty` | a vector of linetypes to be used to plot the lines. If too short, the values are recycled.
`xlim` | the range for the x axis.
`rev` | logical, should the values of the response variable be reversed? Default is `TRUE`.
`args.dens` | additional arguments for the densitiy curves.
`...` | the dots are passed on to `plot()`.

### Details

Especially when we're modelling binary response variables we might want to know, how the binary variable behaves along some numeric predictors.

### Value

the functions for the curves

### Author(s)

Andri Signorell <andri@signorell.net>

### See Also

`cdplot`, `spineplot`, `density`, `PlotMultiDens`

### Examples

    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()))

[Package DescTools version 0.99.38 Index]