crosstab
Cross-tabulation
Syntax
Description
specifies options using one or more name-value arguments in
addition to any of the input argument combinations in the
previous syntaxes. You can specify whether to include
missing groups, and specify to return the output as a
matrix, table, or stacked table.tbl
= crosstab(___,Name=Value
)
Examples
Input Arguments
Name-Value Arguments
Output Arguments
Algorithms
crosstab
usesgrp2idx
to assign a positive integer to each distinct value.tbl(i,j)
is a count of indices wheregrp2idx(x1)
isi
andgrp2idx(x2)
isj
. The numerical order ofgrp2idx(x1)
andgrp2idx(x2)
order rows and columns oftbl
, respectively.In this case, the returned value of
tbl(i,j,...,n)
is a count of indices wheregrp2idx(x1)
isi
,grp2idx(x2)
isj
,grp2idx(x3)
isk
, 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 usefishertest
instead. This function performs Fisher’s exact test, which does not depend on large-sample distribution assumptions.