| 1 |
\name{percentages} |
| 2 |
\alias{percentages} |
| 3 |
\alias{percentages.table} |
| 4 |
\alias{percentages.formula} |
| 5 |
\alias{percentages.default} |
| 6 |
\alias{percentages.data.frame} |
| 7 |
\alias{percentages.list} |
| 8 |
\alias{as.data.frame.percentage.table} |
| 9 |
\alias{as.data.frame.xpercentage.table} |
| 10 |
\title{ |
| 11 |
Easy Creation of Tables of Percentages |
| 12 |
} |
| 13 |
\description{ |
| 14 |
The generic function \code{percentages} and its methods |
| 15 |
create one- or multidimensional tables of percentages. As such, |
| 16 |
the function \code{percentages} can be viewed as a convenience |
| 17 |
interface to \code{\link{prop.table}}. However, it also |
| 18 |
allows to obtain standard errors and confidence intervals. |
| 19 |
} |
| 20 |
\usage{ |
| 21 |
percentages(obj, \dots) |
| 22 |
\method{percentages}{table}(obj, |
| 23 |
by=NULL, which=NULL, se=FALSE, ci=FALSE, ci.level=.95, \dots) |
| 24 |
\method{percentages}{formula}(obj, |
| 25 |
data=parent.frame(), weights=NULL, \dots) |
| 26 |
\method{percentages}{default}(obj, |
| 27 |
weights=NULL, \dots) |
| 28 |
\method{percentages}{data.frame}(obj, |
| 29 |
weights=NULL, \dots) |
| 30 |
\method{percentages}{list}(obj, |
| 31 |
weights=NULL, \dots) |
| 32 |
\method{as.data.frame}{percentage.table}(x, \dots) |
| 33 |
\method{as.data.frame}{xpercentage.table}(x, \dots) |
| 34 |
} |
| 35 |
\arguments{ |
| 36 |
\item{obj}{an object; a contingency table or a formula. If |
| 37 |
it is a formula, its left-hand side determines the factor |
| 38 |
or combination of factors for which percentages are |
| 39 |
computed while its right-hand side determines the |
| 40 |
factor or combination of factors that define the |
| 41 |
groups within which percentages are computed.} |
| 42 |
\item{by}{a character vector with the names of the |
| 43 |
factor variables that define the groups within which percentages |
| 44 |
are computed. Percentages sum to 100 within combination |
| 45 |
of levels of these factors.} |
| 46 |
\item{which}{a character vector with the names of the |
| 47 |
factor variables for which percentages |
| 48 |
are computed.} |
| 49 |
\item{se}{a logical value; determines whether standard |
| 50 |
errors are computed.} |
| 51 |
\item{ci}{a logical value; determines whether confidence |
| 52 |
intervals are computed. Note that the confidence intervals |
| 53 |
are for infinite (or very large) populations.} |
| 54 |
\item{ci.level}{a numerical value, the required confidence level of |
| 55 |
the confidence intervals.} |
| 56 |
\item{data}{a contingency table (an object that inherits from "table") |
| 57 |
or a data frame or an object coercable into a data frame.} |
| 58 |
\item{weights}{an optional vector of weights. Should be NULL or a |
| 59 |
numeric vector.} |
| 60 |
\item{\dots}{Further arguments passed on to the |
| 61 |
"table" method of \code{percentages} or ignored in case of |
| 62 |
a call to \code{as.data.frame}.} |
| 63 |
\item{x}{an object coerced into a data frame.} |
| 64 |
} |
| 65 |
\value{ |
| 66 |
An array that inherits classes "percentage.table" and "table". If |
| 67 |
\code{percentages} was called with \code{se=TRUE} or \code{ci=TRUE} |
| 68 |
then the result additionally inherits class "xpercentage.table". |
| 69 |
} |
| 70 |
\examples{ |
| 71 |
percentages(UCBAdmissions) |
| 72 |
|
| 73 |
# Three equivalent ways to create the same table of conditional |
| 74 |
# percentages |
| 75 |
percentages(Admit~Gender+Dept,data=UCBAdmissions) |
| 76 |
percentages(UCBAdmissions,by=c("Gender","Dept")) |
| 77 |
percentages(UCBAdmissions,which="Admit") |
| 78 |
# Percentage table as data frame |
| 79 |
as.data.frame(percentages(Admit~Gender+Dept,data=UCBAdmissions)) |
| 80 |
|
| 81 |
# Standard errors and confidence intervals |
| 82 |
percentages(Admit~Dept,data=UCBAdmissions,se=TRUE) |
| 83 |
percentages(Admit~Dept,data=UCBAdmissions,ci=TRUE) |
| 84 |
(p<- percentages(Admit~Dept,data=UCBAdmissions,ci=TRUE,se=TRUE)) |
| 85 |
|
| 86 |
# An extended table of percentages as data frame |
| 87 |
as.data.frame(p) |
| 88 |
|
| 89 |
# A table of percentages of a factor |
| 90 |
percentages(iris$Species) |
| 91 |
|
| 92 |
UCBA <- as.data.frame(UCBAdmissions) |
| 93 |
percentages(UCBA$Admit,weights=UCBA$Freq) |
| 94 |
|
| 95 |
percentages(UCBA,weights=UCBA$Freq) |
| 96 |
|
| 97 |
} |