ca.test: Cochran-Armitage test for trend

View source: R/stat.R

ca.testR Documentation

Cochran-Armitage test for trend

Description

Performs a Cochran-Armitage chi-squared test for trend in proportions for a 2 x c contingency table with a nominal row (r == 2) and ordinal column (c > 2) variable.

Usage

ca.test(x, ...)

## Default S3 method:
ca.test(x, g, ..., score = NULL, simulate.p.value = FALSE, B = 2000L)

## S3 method for class 'formula'
ca.test(formula, data, ...)

Arguments

x

a factor-like vector giving the (unordered) variable (equivalently the row variable of a contingency table)

alternatively, x can be a 2 x c table or matrix with exactly two rows and at least three ordered columns; x may also be a list of the row variable split by the ordered column variable in which case the list is assumed to be ordered, i.e., x[[1]] < x[[2]] < ... < x[[c]]; see examples

...

further arguments to be passed to or from methods

g

a factor-like vector giving the ordered group for each corresponding element of x, ignored with a warning if x is a list or table; if g is not a factor, it will be coerced, and groups will be ordered as sort(unique(g)); see factor

score

group score for each column, default is 1:ncol

simulate.p.value

logical; if TRUE, p-value is computed using by Monte Carlo simulation

B

an integer specifying the number of replicates used in the Monte Carlo test

formula

a formula of the form row ~ column where row gives the row variable having two unique values and column gives the ordered column variable

data

an optional matrix or data frame (or similar: see model.frame) containing the variables in formula; by default the variables are taken from environment(formula)

Value

A list with class "htest" containing the following elements:

statistic

the chi-squared test statistic

parameter

the degrees of freedom of the approximate chi- squared distribution of the test statistic

p.value

the p-value of the test (two-sided)

method

a character string describing the test, and, optionally, the number of Monte Carlo replications, if applicable

data.name

a character string giving the names of the data

conf.int

optionally (if simulate.p.value = TRUE), the 99% confidence interval of the Monte Carlo p-value

summary

optionally (if simulate.p.value = TRUE), a summary of the simulated test statistics

See Also

prop.trend.test; jt.test for doubly-ordered tables; cuzick.test; DescTools::CochranArmitageTest

Examples

## example from stats::prop.trend.test
smokers  <- c(83, 90, 129, 70)
patients <- c(86, 93, 136, 82)
prop.test(smokers, patients)
prop.trend.test(smokers, patients)

# DescTools::CochranArmitageTest(rbind(smokers, patients - smokers))
ca.test(rbind(smokers, patients - smokers))
ca.test(rbind(smokers, patients - smokers), score = c(0, 0, 1, 2))

## equivalent ways to call ca.test
dat <- data.frame(x = mtcars$vs, y = mtcars$gear)
ca.test(dat$x, dat$y)
ca.test(x ~ y, dat)
ca.test(split(dat$x, dat$y))
ca.test(table(dat$x, dat$y))


## Not run: 
## simulate p-value with 1k replicates
set.seed(1)
ca.test(rbind(smokers, patients - smokers), simulate.p.value = TRUE, B = 1000)

## End(Not run)


raredd/rawr documentation built on March 4, 2024, 1:36 a.m.