df_props {mosaicModel} | R Documentation |
Joint and conditional proportions
Description
Uses a formula interface to specify how the proportions are to be calculated.
Usage
df_props(formula, data, as.percent = FALSE, ..., wide = FALSE,
margins = FALSE, format = c("proportion", "percent", "count"))
Arguments
formula |
the formula describing the relationship |
data |
a data frame (or you can pipe this in) |
as.percent |
show proportions in percent (e.g. multiply by 100) |
... |
statistics functions to be applied to the data, e.g. mean, sd, confidence(0.95) |
wide |
reformat the output as a cross-tabulation. This makes sense only when there are just two variables |
margins |
show the marginal probabilities. Makes the most sense if |
format |
Use just for internal purposes. |
Details
Using |
in the formula specifies a conditional proportion
~ A : proportion of cases in each level of A
~ A + B: joint proportion: each level of A crossed with B
~ A | B: conditional proportion: for each level of B, what fraction are in each level of A
A ~ B: another way of specifying the conditional proportion
Examples
df_props(mtcars, ~ cyl + gear)
df_props(mtcars, ~ cyl | gear)
df_props(mtcars, ~ cyl + gear, wide = TRUE)
df_props(mtcars, ~ cyl + gear, margins = TRUE)
df_props(mtcars, ~ cyl | gear, margins = TRUE)