clusterStats: Summary Measures within Clusters

Description Usage Arguments Details Value Author(s) Examples

View source: R/clusterStats.R

Description

Produces a vector containing summary measures computed within clusters.

Usage

1
2
clusterStats(y, cluster = NULL, stat = "count", subset = NULL, x = NULL, ..., 
             version = FALSE)

Arguments

y

a vector, Date, or Surv object for which within cluster summary statistics are desired.

cluster

vector, matrix, or list of variables defining clusters. Descriptive statistics will be computed within strata defined by each unique combination of the cluster variables.

stat

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.

subset

a logical vector indicating a subset to be used for all descriptive statistics.

x

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

version

if TRUE, the version of the function will be returned. No other computations will be performed.

Details

This function uses tableStat() to compute stratified statistics for each cluster. However, only single summary measures can be used in this function. See examples.

Value

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.

Author(s)

Scott S. Emerson, M.D., Ph.D., Andrew J. Spieker, Brian D. Williamson, Travis Y. Hee Wai, and Solomon Lim

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 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)

uwIntroStats documentation built on May 2, 2019, 4:34 a.m.