R/cor.test2.R

Defines functions cor.test2

Documented in cor.test2

#' @title Extensió de la funció cor.test \{stats\}
#' 
#' @description La justificació d'haver fet aquesta funció: 1) la funció cor \{stats\} no retorna els p-values; 2) la funció cor.test \{stats\} no permet passar un conjunt de dades. Aquesta extensió permet obtenir el valor p de les correlacions calculades a partir d'un conjunt de dades.
#' 
#' @param x numeric vector of data values. x and y must have the same length.
#' @param y numeric vector of data values. x and y must have the same length.
#' @param method a character string indicating which correlation coefficient is to be used for the test. Currently only works for "spearman".
#' @param conf.level confidence level of the interval.
#' @param ... further arguments to be passed to or from methods.
#' @return A list with the correlation, lower and upper bounds of the confidence interval, p-value.
#' @export
cor.test2 <- function(x, y, method = "spearman", conf.level = 0.95, ...){
  #només treballa amb Spearman (el IC de la r de Pearson ja el retorna la funció cor.test)
  stopifnot(method == "spearman")

  correlation <- cor.test(x = x, y = y, method = method, conf.level = conf.level, ...)
  N <- length(x[which(!is.na(x) & !is.na(y))])
  cirho <- mada::CIrho(correlation$estimate, N = N, level = conf.level)
  return(list = c(cirho[1, 1], cirho[1, 2], cirho[1, 3], p.value = correlation$p.value))
}
IRBLleida/UdBRpackage documentation built on Dec. 24, 2019, 9:10 p.m.