R/CorrDelRow.R

Defines functions CorrDelRow

Documented in CorrDelRow

#' Testing to see which participant to delete to get significance.
#' A way to look for outlayers.
#' The correlation is between two variables
#'
#' @param DFDEL Data frame with two variables.
#' The dataframe should have an Index and two variables
#' @return cortestResults - Data frame with the correlation and significance.
#' between the two varibels and without one participant each time.
#' @note Use wisely. You need the package library(Hmisc)
#' @examples
#' FindDelRow(DF)

CorrDelRow <- function(DFDEL)
{
  # Building main vars and Final DF
  delline <- 1
  row <- 1
  counter <- 1
  DF <- DFDEL %>% setNames(c("ID", "Var1", "Var2"))
  cortestResults <- data.frame(R = as.numeric(),
                             P = as.numeric(),
                             n = as.numeric(),
                             no = as.numeric())

  # Looping
  for (counter in 1:NROW(DF)) {
    DForginal <- DF
    DFTemp <- DF[-delline,]
    cortest <- rcorr(as.matrix(DFTemp))
    cortestResults[row,1] <- cortest$r[3,2]
    cortestResults[row,2] <- cortest$P[3,2]
    cortestResults[row,3] <- cortest$n[3,2]
    cortestResults[row,4] <- DF$ID[delline]
    counter <- counter + 1
    delline <- delline + 1
    row <- row + 1
  } #End Loop
  return(cortestResults)
} #End Function
AmirDJV/UsefulFunctions documentation built on Nov. 18, 2017, 5:10 a.m.