
Last chance! 50% off unlimited learning
Sale ends in
Produces a vector containing summary measures computed within clusters.
clusterStats(y, cluster = NULL, stat = "count", subset = NULL, x = NULL, ...,
version = FALSE)
a vector, Date
, or Surv
object for which within cluster summary statistics are desired.
vector, matrix, or list of variables defining clusters. Descriptive statistics will be computed within strata defined by each unique combination of the cluster variables.
a character string indicating the descriptive statistic(s) to be returned for each
cluster. See the documentation for tableStat()
for a full description, although
only single statistics can be specified in this function. If either "probabilities"
or "quantiles"
are specified, only the first such quantity is returned. In addition
to the summary statistics allowed by tableStat()
, a user can also specify within
cluster least squares slopes (stat="slope"
) of y
on x
.
a logical vector indicating a subset to be used for all descriptive statistics.
a numeric vector to be used as regression predictor for least squares slopes.
optional arguments specifying quantiles or thresholds for probabilities to be used
in calculating summary statistics. See arguments for descrip()
.
if TRUE
, the version of the function will be returned. No other computations will
be performed.
A vector is returned that contains the summary statistic relevant for the cluster to which each observation in y
belings. Although only the cases indicated by subset
are used to calculate the summary statistics, values are expanded out to cases beyond those indicated by subset
.
This function uses tableStat()
to compute stratified statistics for each cluster. However, only single summary measures can be used in this function. See examples.
# NOT RUN {
# Load required libraries
library(survival)
# Reading in a dataset
audio <- read.csv("http://www.emersonstatistics.com/datasets/audio.csv",header=TRUE)
# Generating counts for each subject
counts <- clusterStats (audio$R4000, audio$Subject, "count")
table(counts,strata=audio$Dose)
# Generating average R4000 for each subject
mR4000 <- clusterStats (audio$R4000, audio$Subject, "mean")
descrip(mR4000,strata=audio$Dose)
# Generating average R4000 for each subject after visit 0
mtxR4000 <- clusterStats (audio$R4000, audio$Subject, "mean", subset=audio$Visit>0)
descrip(mtxR4000,strata=audio$Dose)
# }
Run the code above in your browser using DataLab