R/weighted.cramer.R

Defines functions weighted.cramer

Documented in weighted.cramer

weighted.cramer <- function(x, y, weights = NULL, na.rm = FALSE) {
  
  t <- weighted.table(x, y, weights, na.rm = na.rm, digits = NULL)
  expected <- sapply(colSums(t), function(x) x*rowSums(t)/sum(t))
  chi.squared <- sum((t-expected)*(t-expected)/expected)
  cramer.v <- sqrt(chi.squared / (length(x)*(min(nrow(t),ncol(t))-1)))
  
  return(cramer.v)
}

Try the descriptio package in your browser

Any scripts or data that you put into this service are public.

descriptio documentation built on June 8, 2025, 10:50 a.m.