R/kontingenz.R

Defines functions chi_squared

Documented in chi_squared

#' Chi Squared Value
#'
#' @param x A matrix.
#'
#' @export
chi_squared <- function(x) {
  n <- sum(x)
  h_i <- matrix(rowSums(x))
  h_j <- matrix(colSums(x))
  h_ij <- h_i %*% t(h_j) / n
  sum((x - h_ij)^2 / h_ij)
}
DavidBarke/Stat1-Functions documentation built on Feb. 25, 2021, 2:56 p.m.