R/02_algebrahelpers_trysolve.R

Defines functions trysolve

trysolve <- function(x){
warning("'trysolve' should be removed!")
  tryres <- try({
    y <- solve(x)
  }, silent = TRUE)
  if (!is(tryres, "try-error")){
    return(y)
  }

  # Try psuedoinverse:
  tryres <- try({
    y <- corpcor::pseudoinverse(x)
  }, silent = TRUE)
  if (!is(tryres, "try-error")){
    return(y)
  }
  
  # Try spectral shift:
  tryres <- try({
    y <- corpcor::pseudoinverse(spectralshift(x))
  }, silent = TRUE)
  if (!is(tryres, "try-error")){
    return(y)
  }

  stop("Could not compute matrix inverse")
}

Try the psychonetrics package in your browser

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

psychonetrics documentation built on Oct. 3, 2023, 5:09 p.m.