Learn R Programming

rcompanion (version 2.4.36)

phi: phi

Description

Calculates phi for a 2 x 2 table of nominal variables; confidence intervals by bootstrap.

Usage

phi(
  x,
  y = NULL,
  ci = FALSE,
  conf = 0.95,
  type = "perc",
  R = 1000,
  histogram = FALSE,
  verbose = FALSE,
  digits = 3,
  reportIncomplete = FALSE,
  ...
)

Value

A single statistic, phi. Or a small data frame consisting of phi, and the lower and upper confidence limits.

Arguments

x

Either a 2 x 2 table or a 2 x 2 matrix. Can also be a vector of observations for one dimension of a 2 x 2 table.

y

If x is a vector, y is the vector of observations for the second dimension of a 2 x2 table.

ci

If TRUE, returns confidence intervals by bootstrap. May be slow.

conf

The level for the confidence interval.

type

The type of confidence interval to use. Can be any of "norm", "basic", "perc", or "bca". Passed to boot.ci.

R

The number of replications to use for bootstrap.

histogram

If TRUE, produces a histogram of bootstrapped values.

verbose

If TRUE, prints the table of counts.

digits

The number of significant digits in the output.

reportIncomplete

If FALSE (the default), NA will be reported in cases where there are instances of the calculation of the statistic failing during the bootstrap procedure.

...

Additional arguments. (Ignored.)

Author

Salvatore Mangiafico, mangiafico@njaes.rutgers.edu

Details

phi is used as a measure of association between two binomial variables, or as an effect size for a chi-square test of association for a 2 x 2 table. The absolute value of the phi statistic is the same as Cramer's V for a 2 x 2 table.

Unlike Cramer's V, phi can be positive or negative (or zero), and ranges from -1 to 1.

When phi is close to its extremes, or with small counts, the confidence intervals determined by this method may not be reliable, or the procedure may fail.

References

https://rcompanion.org/handbook/H_10.html

See Also

cramerV

Examples

Run this code
### Example with table
Matrix = matrix(c(13, 26, 26, 13), ncol=2)
phi(Matrix)

### Example with two vectors
Species = c(rep("Species1", 16), rep("Species2", 16))
Color   = c(rep(c("blue", "blue", "blue", "green"),4),
            rep(c("green", "green", "green", "blue"),4))
phi(Species, Color)

Run the code above in your browser using DataLab