tests/testthat/test_MDmiss.R

context("Mahalanobis distance with missing values")
library(modi)

test_that("MDmiss without missings outputs the same result as mahalanobis (stats)", {
  A <- matrix(c(2, 4, 3, 13, 5, 8), nrow = 3, ncol = 2, byrow = TRUE)
  expect_equal(MDmiss(A, apply(A, 2, mean), var(A)), mahalanobis(A, apply(A, 2, mean), var(A)))
})

Try the modi package in your browser

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

modi documentation built on March 31, 2023, 8:35 p.m.