# R/chisqtest.R In oliviermfmartin/zebu: Local Association Measures

#### Documented in chisqtest

#' Chi-squared test
#'
#' Chi-squared test: statistical significance of (global) chi-squared statistic
#' and (local) chi-squared residuals
#'
#' @param x \code{\link[zebu]{lassie}} S3 object.
#'
#' @param p_adjust multiple testing correction method.
#'
#' @return \code{chisqtest} returns an S3 object of \link[base]{class}
#' Adds the following to the lassie object \code{x}:
#' \itemize{
#' \item global_p: global association p-value.
#' \item local_p: array of local association p-values.
#' }
#'
#'
#' @examples
#'
#' # Calling lassie on cars dataset
#' las <- lassie(cars, continuous = colnames(cars), measure = "chisq")
#'
#' # Permutation test using default settings
#' chisqtest(las)
#'
#' @export
#' @import data.table
#'
chisqtest <- function(x, p_adjust = "BH") {

# Check arguments ----
if (! "lassie" %in% class(x)) {
stop("Invalid 'x' argument: must be a 'lassie' object")
}

}

# Compute general variables ----
dimensions <- dim(x$prob$observed)  # Dimensions
dim_names <- dimnames(x$prob$observed)  # Dimension names
measure <- x$lassie_params[["measure"]] # Get association measure used if (measure != "chisq" | length(dimensions) != 2) { stop(paste("This function is only valid for the chi-squared method and two dimensions.")) } # Compute p-values ---- global_p <- stats::pchisq(x$global, df = prod(dimensions - 1), lower.tail = FALSE)
local_p <- 2 * (1 - stats::pnorm(abs(x\$local)))

# Multiple test correction