Nothing
test_that("known past teachers are retained when their current scores are missing", {
d <- vam_fixture(nstudent = 36L, nyear = 2L)
affected <- d$year == 1 & d$teacher == "1"
students <- d$student[affected]
d$teacher[affected] <- "unobserved_current"
d$y[affected] <- NA
d$x[affected] <- NA
fit <- suppressWarnings(GPvam(d, ~as.factor(year)+x, persistence = "CP",
max.iter.EM = 3, verbose = FALSE))
column <- which(grepl("unobserved_current", colnames(fit$Z), fixed = TRUE))
expect_length(column, 1)
expected <- d$student[fit$observation] %in% students & d$year[fit$observation] == 2
expect_equal(as.numeric(fit$Z[, column]), as.numeric(expected))
expect_equal(fit$loglik, dense_reference(fit)$loglik, tolerance = 1e-7)
})
test_that("missing student periods and explicit missing scores give the same model", {
full <- vam_fixture(nstudent = 24L, nyear = 3L)
omitted <- c(2, 6, 17, 28, 51)
full$y[omitted] <- NA
full$teacher[omitted] <- NA
compact <- full[-omitted, ]
for (persistence in c("GP", "rGP", "CP", "VP", "ZP")) {
fit <- suppressWarnings(GPvam(full, ~as.factor(year)+x,
persistence = persistence, max.iter.EM = 4, verbose = FALSE))
other <- suppressWarnings(GPvam(compact, ~as.factor(year)+x,
persistence = persistence, max.iter.EM = 4, verbose = FALSE))
expect_equal(fit$loglik, other$loglik, tolerance = 1e-7)
expect_equal(as.numeric(fit$yhat), as.numeric(other$yhat), tolerance = 1e-7)
expect_equal(fit$loglik, dense_reference(fit)$loglik, tolerance = 1e-7)
}
})
test_that("small and large response scales retain coherent finite-iteration fits", {
d <- vam_fixture(nstudent = 24L, nyear = 2L)
for (reml in c(FALSE, TRUE)) {
for (scale in c(0.001, 1000)) {
scaled <- d
scaled$y <- d$y * scale
other <- suppressWarnings(GPvam(scaled, ~as.factor(year)+x, persistence = "CP",
REML = reml, max.iter.EM = 8, verbose = FALSE))
# Check the returned state against independent Gaussian equations rather
# than treating a capped iterate as an optimum. Converged scale behavior
# is checked separately in the numerical regression tests.
ref <- dense_reference(other)
expect_true(all(is.finite(other$loglik_history)))
expect_equal(other$loglik, ref$loglik, tolerance = 1e-7)
expect_equal(as.numeric(other$ybetas)/scale, ref$beta/scale, tolerance = 1e-7)
expect_equal(as.numeric(other$eta.hat)/scale, ref$eta/scale, tolerance = 1e-6)
}
}
})
test_that("residual covariance blocks correspond to actual students and years", {
d <- vam_fixture(nstudent = 24L, nyear = 3L)
d$y[c(2, 6, 17, 28, 51)] <- NA
for (persistence in c("GP", "rGP", "CP", "VP", "ZP")) {
fit <- suppressWarnings(GPvam(d, ~as.factor(year)+x,
persistence = persistence, max.iter.EM = 3,
verbose = FALSE))
observed <- d[fit$observation, , drop = FALSE]
same_student <- outer(observed$student, observed$student, "==")
expected <- fit$R_i[observed$year, observed$year] * same_student
expect_equal(unname(as.matrix(solve(fit$R.inv))), unname(expected),
tolerance = 1e-10, info = persistence)
expect_equal(as.numeric(fit$y), observed$y, tolerance = 0, info = persistence)
expect_equal(as.matrix(fit$X), model.matrix(~as.factor(year)+x, observed),
tolerance = 0, ignore_attr = TRUE, info = persistence)
}
})
test_that("reordering input rows leaves the fitted model unchanged", {
d <- vam_fixture(nstudent = 24L, nyear = 3L)
d$y[c(2, 6, 17, 28, 51)] <- NA
reordered <- d[rev(seq_len(nrow(d))), , drop = FALSE]
for (persistence in c("GP", "rGP", "CP", "VP", "ZP")) {
fit <- suppressWarnings(GPvam(d, ~as.factor(year)+x, persistence = persistence,
max.iter.EM = 4, verbose = FALSE))
other <- suppressWarnings(GPvam(reordered, ~as.factor(year)+x,
persistence = persistence, max.iter.EM = 4,
verbose = FALSE))
expect_equal(fit$loglik, other$loglik, tolerance = 1e-8, info = persistence)
expect_equal(fitted(fit), fitted(other)[names(fitted(fit))],
tolerance = 1e-8, info = persistence)
}
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.