tests/testthat/test-sqrtm.R

# data
set.seed(123)
ret <- matrix(stats::rnorm(400), ncol = 4)
ret_cov <- stats::cov(ret)
ds <- eigen(ret_cov)

# test
test_that("sqrtm uses spectral decomposition", {
  expect_equal(sqrtm(ret_cov), ds$vectors %*% diag(sqrt(ds$values)) %*% t(ds$vectors))
})

test_that("sqrtm only work with quadratic objects", {
  expect_error(sqrtm(matrix(stats::rnorm(6), ncol = 2)))
})

Try the uncorbets package in your browser

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

uncorbets documentation built on May 29, 2024, 1:45 a.m.