Computes the Phi coefficient as a measure of association between two categorical variables.
Arguments
- x
a vector of categorical data or a contingency table (matrix or
table)- y
optional second categorical vector. If provided, a contingency table is constructed from
xandy.- ...
additional arguments passed to
base::table()
Details
If y is provided, a contingency table is created using
table(x, y, ...). Otherwise, x is assumed to already be
a contingency table.
Note: Yates' continuity correction is not applied when computing the chi-squared statistic.
The Phi coefficient is defined as: $$ \phi = \sqrt{ \frac{\chi^2}{n} } $$ where \(\chi^2\) is the chi-squared test statistic and \(n\) is the total sample size.
This definition is unsigned. For a 2x2 table the signed
coefficient \((n_{11} n_{22} - n_{12} n_{21}) /
\sqrt{n_{1\cdot} n_{2\cdot} n_{\cdot 1} n_{\cdot 2}}\) equals the Pearson
correlation of the two 0/1 indicators and lies in \([-1, 1]\); the value
returned here is its absolute value, so the direction of the association
is not reported. See pearsonCor() if the sign is needed.
For contingency tables larger than 2x2, Phi is not bounded by 1 and
may exceed 1. In such cases, cramerV() is usually preferred.
See also
Other assoc.nominal:
contCoef(),
cramerV(),
gkTau(),
lambda(),
mutInf(),
tschuprowT(),
uncertCoef(),
yule
