diff --git a/tests/testthat/test_kldggd.R b/tests/testthat/test_kldggd.R index 4991afff470dcbcf7dd3203259c1777f23ff62ba..6f4e7539404c063a1c36c53e9c6355b099d7c02a 100644 --- a/tests/testthat/test_kldggd.R +++ b/tests/testthat/test_kldggd.R @@ -70,7 +70,31 @@ kl21_d5 <- kldggd(Sigma2, beta2, Sigma1, beta1, eps = 1e-12) test_that("kl works (dim 5)", { expect_equal(attr(kl12_d5, "eps"), 1e-12) expect_equal(attr(kl21_d5, "eps"), 1e-12) - + expect_equal(as.numeric(kl12_d5), kl12Matlab_d5) expect_equal(as.numeric(kl21_d5), kl21Matlab_d5) }) + +# Dimension p = 6 + +beta1 <- 0.74 +beta2 <- 0.55 +Sigma1 = matrix(c(0.8, 0.3, 0.2, 0, 0, 0, 0.3, 0.2, 0.1, 0, 0, 0, + 0.2, 0.1, 0.2, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 , 0, 1), nrow = 6) +Sigma2 = matrix(c(1, 0.3, 0.2, 0, 0, 0, 0.3, 0.5, 0.1, 0, 0, 0, + 0.2, 0.1, 0.7, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3), nrow = 6) +kl12Matlab_d6 <- 3.367857801981060 +kl21Matlab_d6 <- 16.157323374492506 + +kl12_d6 <- kldggd(Sigma1, beta1, Sigma2, beta2, eps = 1e-5) +kl21_d6 <- kldggd(Sigma2, beta2, Sigma1, beta1, eps = 1e-6) + +test_that("kl works (dim 6)", { + expect_equal(attr(kl12_d6, "eps"), 1e-5) + expect_equal(attr(kl21_d6, "eps"), 1e-6) + + expect_equal(as.numeric(kl12_d6), kl12Matlab_d6) + expect_equal(as.numeric(kl21_d6), kl21Matlab_d6) +})