tests/testthat/test-typesq1CompSymm.R

context("q1CompSymm")

## ============================================================================
## check that for this covariance class, 'covMat' gives the
## same result whatever be the class of input used
## "factor", "character" or "integer"
## ============================================================================

set.seed(314159)
         
SchoolLevels <- c("Bad", "Mean", "Good")

School <- factor(1L:3L, labels = SchoolLevels)

## covariance change parameter value
myCov <- q1CompSymm(School, input = "School", cov = "homo",
                    intAsChar = FALSE)
coef(myCov) <- c("rho" = runif(1), "sigma2" = rexp(1))

dfInt <- data.frame(School = sample(3, size = 40, replace = TRUE))
CInt <- covMat(myCov, X = dfInt)

dfChar <- within(dfInt, School <- SchoolLevels[School])  
CChar <- covMat(myCov, X = dfChar)

dfFact <- within(dfChar, School <- factor(School, levels = SchoolLevels))  
CFact <- covMat(myCov, X = dfFact)

err <- max(c(max(abs(CInt - CChar)), max(abs(CInt - CFact))))
test_that(desc = "Identical covariances using int, char or factor: ",
          code = expect_true(err < 1e-10))

err <- max(c("IntChar" = max(abs(attr(CInt, "gradient") -
                                     attr(CChar, "gradient"))),
             "IntFact" = max(abs(attr(CInt, "gradient") -
                                     attr(CFact, "gradient")))))
test_that(desc = "Identical cov. Gradients using int, char or factor: ",
          code = expect_true(err < 1e-10))

Try the kergp package in your browser

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

kergp documentation built on May 29, 2024, 10:25 a.m.