R/02_algebrahelpers_maxcor.R

Defines functions maxcor

# This function reduces covariances to limit the correlation to be too strong, useful for starting values (I hope):
maxcor <- function(cov, max = 0.1){
  if (is.list(cov)) {
    return(lapply(cov,maxcor))
  }
  cor <- cov2cor(cov)
  sd <- diag(sqrt(diag(cov)))
  cor[] <- pmin(max,pmax(-max,cor))
  diag(cor) <- 1
  sd %*% cor %*% sd
}

Try the psychonetrics package in your browser

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

psychonetrics documentation built on June 22, 2024, 10:29 a.m.