# crosstab

Cross-tabulation

## Syntax

## Description

`[`

also
returns the chi-square statistic and
`tbl`

,`chi2`

,`p`

]
= crosstab(___)*p*-value for a chi-square test. The test
null hypothesis is that the proportion in any entry in
`tbl`

is the product of the
proportions in each dimension. For this syntax, you can
specify any of the input argument combinations in the
previous syntaxes.

## Examples

## Input Arguments

## Output Arguments

## Algorithms

`crosstab`

uses`grp2idx`

to assign a positive integer to each distinct value.`tbl(i,j)`

is a count of indices where`grp2idx(x1)`

is`i`

and`grp2idx(x2)`

is`j`

. The numerical order of`grp2idx(x1)`

and`grp2idx(x2)`

order rows and columns of`tbl`

, respectively.In this case, the returned value of

`tbl(i,j,...,n)`

is a count of indices where`grp2idx(x1)`

is`i`

,`grp2idx(x2)`

is`j`

,`grp2idx(x3)`

is`k`

, and so on.`crosstab`

computes the*p*-value of the chi-square test statistic using a formula that is asymptotically valid for a large sample size. The approximation is less accurate for small samples or samples with uneven marginal distributions. If your sample includes only two variables and each has two levels, you can use`fishertest`

instead. This function performs Fisher’s exact test, which does not depend on large-sample distribution assumptions.

## Extended Capabilities

## Version History

**Introduced before R2006a**