tabulate: Table Variables, with Stratification and Statistical Tests

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/tabulate.R

Description

Takes in a list of strata, and returns a stratified table of counts (can also include other descriptives as specified by the user) as well as the chi-squared summaries for each. Relies on the Exact package for calculating Odds Ratios and Risk Ratios, the plyr package for array manipulation, and the survival package for censored data analysis.

Usage

1
2
3
4
5
6
7
## S3 method for class 'tabulate'
tabulate(..., dispRatios=FALSE, stratified=TRUE, tests=NULL, 
        stat="count", na.rm=TRUE, subset=NULL, probs= c(.25,.50,.75), 
        replaceZeroes=FALSE, restriction=Inf, above=NULL, 
        below=NULL, labove=NULL, rbelow=NULL, lbetween=NULL, rbetween=NULL, 
        interval=NULL, linterval=NULL, rinterval=NULL, lrinterval=NULL, 
        version=FALSE)

Arguments

...

a list of strata variables. All variables must have the same length.

dispRatios

can only be used if the first two variables only take on two values. Default is FALSE. If TRUE, displays Odds Ratio and Relative Risk (the user must decide which is appropriate for inference). It is assumed that the lower value of the data is healthy and the higher value is diseased (for example 0 might be no stroke and 1 would be had stroke).

stratified

default is TRUE, displays chi-squared statistics by stratum. Also if row/column/total percentages are requested, displays stratified percentages. If FALSE, only the overall chi-squared statistic is displayed and row/column/total percentages are calculated over all values.

tests

the type of tests to include in addition to the chi-squared test. Options are "lrchisq" - Likelihood Ratio Chi-squared Test, "lr" - Likelihood Ratio Test (logistic regression), "fisher" - Fisher's Exact Test, "mh" - Mantel-Haenszel Test, "uWald" - Barnard's Unconditional Exact Test (Wald statistic), "uScore" - Barnard's Unconditional Exact Test (score statistic), "score" - calculate Rao's Score statistic (logistic regression), and "wald" - Wald Chi-square Test (logistic regression). If "mh" is entered, the first three strata variables must have dimension at least 2.

stat, na.rm, subset, probs, replaceZeroes, restriction, above, below, labove, rbelow, lbetween, rbetween, interval, linterval, rinterval, lrinterval, version

variables passed to descrip(). For a detailed description, read the file on descrip().

Details

If stratified=TRUE, prints the stratified count tables and chi-squared summaries. The printed result is a matrix with columns for (if appropriate): the point estimate, test statistic, degrees of freedom, 95% confidence interval, p-value, and any warnings in computation. If requested, row/column/total percentages are also stratified based on the first two variables entered. If stratified=FALSE, then the overall chi-squared statistic is returned and percentages are calculated from the overall table. If specified the user can also display Odds Ratio/Risk Ratio, likelihood-ratio test, Fisher's Exact test, Wald test, Barnard's Unconditional Exact test, Rao's Score test, and Mantel-Haenszel test results. The Mantel-Haenzsel chi-squared estimate, confidence interval, and estimate of the odds ratio are only returned if the first three variables entered into tabulate() are 2 by 2 by K. Any call to tabulate() will run tabulate.default(), with user specified values in place of the appropriate defaults.

Value

Returns an object of class tabulate. Contains two values in a list:

rslt

the raw result, which has all of the tables of counts.

printer

the raw result with descriptive statistics, if specified.

Author(s)

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

See Also

exact.test, fisher.test, aaply, descrip, tableStat

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## load the necessary libraries
library(survival)
library(Exact)
library(plyr)

## read in the mri dataset 
mri <- read.table("http://www.emersonstatistics.com/datasets/mri.txt",header=TRUE)

## attach the mri dataset
attach(mri)

## create a table of stroke and race
tabulate(stroke, race)

## perform a chi-squared test of stroke vs race, display the count, row percentage, 
## and column percentage
tabulate(stroke, race, stat="@count@ @row%@ @col%@")

## perform chi-squared test, likelihood ratio test, and fisher's exact test 
## for stroke vs race
tabulate(stroke, race, tests=c("lrchisq", "fisher"))

## for diabetes vs male by race, perform chi-squared test, display 
## odds ratio/risk ratio, mantel-haenzsel, likelihood ratio chi-squared
tabulate(diabetes, male, race, dispRatios=TRUE, tests=c("lrchisq", "mh"))

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