bystats | R Documentation |
For any number of cross-classification variables, bystats
returns a matrix with the sample size, number missing y
, and
fun(non-missing y)
, with the cross-classifications designated
by rows. Uses Harrell's modification of the interaction
function to produce cross-classifications. The default fun
is
mean
, and if y
is binary, the mean is labeled as
Fraction
. There is a print
method as well as a
latex
method for objects created by bystats
.
bystats2
handles the special case in which there are 2
classifcation variables, and places the first one in rows and the
second in columns. The print
method for bystats2
uses
the print.char.matrix
function to organize statistics
for cells into boxes.
bystats(y, ..., fun, nmiss, subset)
## S3 method for class 'bystats'
print(x, ...)
## S3 method for class 'bystats'
latex(object, title, caption, rowlabel, ...)
bystats2(y, v, h, fun, nmiss, subset)
## S3 method for class 'bystats2'
print(x, abbreviate.dimnames=FALSE,
prefix.width=max(nchar(dimnames(x)[[1]])), ...)
## S3 method for class 'bystats2'
latex(object, title, caption, rowlabel, ...)
y |
a binary, logical, or continuous variable or a matrix or data frame of
such variables. If |
... |
For |
v |
vertical variable for |
h |
horizontal variable for |
fun |
a function to compute on the non-missing |
nmiss |
A column containing a count of missing values is included if |
subset |
a vector of subscripts or logical values indicating the subset of data to analyze |
abbreviate.dimnames |
set to |
prefix.width |
see |
title |
|
caption |
caption to pass to |
rowlabel |
|
x |
an object created by |
object |
an object created by |
for bystats
, a matrix with row names equal to the classification labels and column
names N, Missing, funlab
, where funlab
is determined from fun
.
A row is added to the end with the summary statistics computed
on all observations combined. The class of this matrix is bystats
.
For bystats
, returns a 3-dimensional array with the last dimension
corresponding to statistics being computed. The class of the array is
bystats2
.
latex
produces a .tex
file.
Frank Harrell
Department of Biostatistics
Vanderbilt University
fh@fharrell.com
interaction
, cut
, cut2
, latex
, print.char.matrix
,
translate
## Not run:
bystats(sex==2, county, city)
bystats(death, race)
bystats(death, cut2(age,g=5), race)
bystats(cholesterol, cut2(age,g=4), sex, fun=median)
bystats(cholesterol, sex, fun=quantile)
bystats(cholesterol, sex, fun=function(x)c(Mean=mean(x),Median=median(x)))
latex(bystats(death,race,nmiss=FALSE,subset=sex=="female"), digits=2)
f <- function(y) c(Hazard=sum(y[,2])/sum(y[,1]))
# f() gets the hazard estimate for right-censored data from exponential dist.
bystats(cbind(d.time, death), race, sex, fun=f)
bystats(cbind(pressure, cholesterol), age.decile,
fun=function(y) c(Median.pressure =median(y[,1]),
Median.cholesterol=median(y[,2])))
y <- cbind(pressure, cholesterol)
bystats(y, age.decile,
fun=function(y) apply(y, 2, median)) # same result as last one
bystats(y, age.decile, fun=function(y) apply(y, 2, quantile, c(.25,.75)))
# The last one computes separately the 0.25 and 0.75 quantiles of 2 vars.
latex(bystats2(death, race, sex, fun=table))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.