Nothing
library(nlme, quietly = TRUE)
data(Socatt, package = "mlmRev")
Socatt$religion <- relevel(Socatt$religion, ref = "none")
Socatt$rv <- as.numeric(as.character(Socatt$numpos))
Socatt$rv <- scale(Socatt$rv) # a plot shows this is clearly non-normal
# ==============================================================================
context("wild bootstrap hccme = hc2 aux.dist = f1 (lme)")
# ==============================================================================
mySumm <- function(.) {
c(beta = fixef(.), sigma = as.numeric(.$sigma), sig01 = as.numeric(VarCorr(.)[1,2]))
}
nsim <- 10
test_that("two-level additive random intercept model",{
skip_on_cran()
## See p. 31 of Goldstein's book
vcmodA <- lme(mathAge11 ~ mathAge8 + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(vcmodA)
boo <- wild_bootstrap(model = vcmodA, .f = mySumm, B = nsim, hccme = "hc2", aux.dist = "mammen")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ------------------------------------------------------------------------------
test_that("two-level random intercept model without interaction",{
skip_on_cran()
## See p. 97 of Goldstein's book
rimod <- lme(mathAge11 ~ mathAge8c + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(rimod)
boo <- wild_bootstrap(model = rimod, .f = mySumm, B = nsim, hccme = "hc2", aux.dist = "mammen")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
test_that("two-level random intercept model with interaction",{
skip_on_cran()
## See p. 34 of Goldstein's book
vcmodC <- lme(mathAge11 ~ mathAge8 * schoolMathAge8 + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(vcmodC)
boo <- wild_bootstrap(model = vcmodC, .f = mySumm, B = nsim, hccme = "hc2", aux.dist = "mammen")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ------------------------------------------------------------------------------
test_that("two-level random coefficient model with interaction",{
skip_on_cran()
## See p. 35 of Goldstein's book
rcmod <- lme(mathAge11 ~ mathAge8c * schoolMathAge8 + gender + class,
random = ~ mathAge8c | school, data = jsp728)
orig.stats <- mySumm(rcmod)
boo <- wild_bootstrap(model = rcmod, .f = mySumm, B = nsim, hccme = "hc2", aux.dist = "mammen")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ==============================================================================
context("wild bootstrap hccme = hc2 aux.dist = f2 (lme)")
# ==============================================================================
mySumm <- function(.) {
c(beta = fixef(.), sigma = as.numeric(.$sigma), sig01 = as.numeric(VarCorr(.)[1,2]))
}
nsim <- 10
test_that("two-level additive random intercept model",{
skip_on_cran()
## See p. 31 of Goldstein's book
vcmodA <- lme(mathAge11 ~ mathAge8 + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(vcmodA)
boo <- wild_bootstrap(model = vcmodA, .f = mySumm, B = nsim, hccme = "hc2", aux.dist = "rademacher")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ------------------------------------------------------------------------------
test_that("two-level random intercept model without interaction",{
skip_on_cran()
## See p. 97 of Goldstein's book
rimod <- lme(mathAge11 ~ mathAge8c + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(rimod)
boo <- wild_bootstrap(model = rimod, .f = mySumm, B = nsim, hccme = "hc2", aux.dist = "rademacher")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
test_that("two-level random intercept model with interaction",{
skip_on_cran()
## See p. 34 of Goldstein's book
vcmodC <- lme(mathAge11 ~ mathAge8 * schoolMathAge8 + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(vcmodC)
boo <- wild_bootstrap(model = vcmodC, .f = mySumm, B = nsim, hccme = "hc2", aux.dist = "rademacher")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ------------------------------------------------------------------------------
test_that("two-level random coefficient model with interaction",{
skip_on_cran()
## See p. 35 of Goldstein's book
rcmod <- lme(mathAge11 ~ mathAge8c * schoolMathAge8 + gender + class,
random = ~ mathAge8c | school, data = jsp728)
orig.stats <- mySumm(rcmod)
boo <- wild_bootstrap(model = rcmod, .f = mySumm, B = nsim, hccme = "hc2", aux.dist = "rademacher")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ==============================================================================
context("wild bootstrap hccme = hc3 aux.dist = f1 (lme)")
# ==============================================================================
mySumm <- function(.) {
c(beta = fixef(.), sigma = as.numeric(.$sigma), sig01 = as.numeric(VarCorr(.)[1,2]))
}
nsim <- 10
test_that("two-level additive random intercept model",{
skip_on_cran()
## See p. 31 of Goldstein's book
vcmodA <- lme(mathAge11 ~ mathAge8 + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(vcmodA)
boo <- wild_bootstrap(model = vcmodA, .f = mySumm, B = nsim, hccme = "hc3", aux.dist = "mammen")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ------------------------------------------------------------------------------
test_that("two-level random intercept model without interaction",{
skip_on_cran()
## See p. 97 of Goldstein's book
rimod <- lme(mathAge11 ~ mathAge8c + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(rimod)
boo <- wild_bootstrap(model = rimod, .f = mySumm, B = nsim, hccme = "hc3", aux.dist = "mammen")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
test_that("two-level random intercept model with interaction",{
skip_on_cran()
## See p. 34 of Goldstein's book
vcmodC <- lme(mathAge11 ~ mathAge8 * schoolMathAge8 + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(vcmodC)
boo <- wild_bootstrap(model = vcmodC, .f = mySumm, B = nsim, hccme = "hc3", aux.dist = "mammen")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ------------------------------------------------------------------------------
test_that("two-level random coefficient model with interaction",{
skip_on_cran()
## See p. 35 of Goldstein's book
rcmod <- lme(mathAge11 ~ mathAge8c * schoolMathAge8 + gender + class,
random = ~ mathAge8c | school, data = jsp728)
orig.stats <- mySumm(rcmod)
boo <- wild_bootstrap(model = rcmod, .f = mySumm, B = nsim, hccme = "hc3", aux.dist = "mammen")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ==============================================================================
context("wild bootstrap hccme = hc3 aux.dist = f2 (lme)")
# ==============================================================================
mySumm <- function(.) {
c(beta = fixef(.), sigma = as.numeric(.$sigma), sig01 = as.numeric(VarCorr(.)[1,2]))
}
nsim <- 10
test_that("two-level additive random intercept model",{
skip_on_cran()
## See p. 31 of Goldstein's book
vcmodA <- lme(mathAge11 ~ mathAge8 + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(vcmodA)
boo <- wild_bootstrap(model = vcmodA, .f = mySumm, B = nsim, hccme = "hc3", aux.dist = "rademacher")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ------------------------------------------------------------------------------
test_that("two-level random intercept model without interaction",{
skip_on_cran()
## See p. 97 of Goldstein's book
rimod <- lme(mathAge11 ~ mathAge8c + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(rimod)
boo <- wild_bootstrap(model = rimod, .f = mySumm, B = nsim, hccme = "hc3", aux.dist = "rademacher")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
test_that("two-level random intercept model with interaction",{
skip_on_cran()
## See p. 34 of Goldstein's book
vcmodC <- lme(mathAge11 ~ mathAge8 * schoolMathAge8 + gender + class,
random = ~ 1 | school, data = jsp728)
orig.stats <- mySumm(vcmodC)
boo <- wild_bootstrap(model = vcmodC, .f = mySumm, B = nsim, hccme = "hc3", aux.dist = "rademacher")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ------------------------------------------------------------------------------
test_that("two-level random coefficient model with interaction",{
skip_on_cran()
## See p. 35 of Goldstein's book
rcmod <- lme(mathAge11 ~ mathAge8c * schoolMathAge8 + gender + class,
random = ~ mathAge8c | school, data = jsp728)
orig.stats <- mySumm(rcmod)
boo <- wild_bootstrap(model = rcmod, .f = mySumm, B = nsim, hccme = "hc3", aux.dist = "rademacher")
expect_equal(class(boo), "lmeresamp")
expect_equal(boo$observed, orig.stats)
expect_equal(unname(boo$stats$observed), unname(orig.stats))
expect_equal(nrow(boo$replicates), nsim)
expect_equal(ncol(boo$replicates), length(orig.stats))
expect_equal(boo$B, nsim)
expect_equal(boo$type, "wild")
expect_equal(boo$.f, mySumm)
})
# ------------------------------------------------------------------------------
# test_that("three-level random intercept model",{
# rmA <- lme(rv ~ religion + year, random = ~ 1 | district/respond, data = Socatt)
#
#
# mySumm <- function(.) {
# c(beta = fixef(.), sigma = as.numeric(.$sigma), sig01 = as.numeric(VarCorr(.)[1,2]))
# }
#
# orig.stats <- mySumm(rmA)
# boo <- parametric_bootstrap(model = rmA, .f = mySumm, B = nsim)
#
# expect_equal(class(boo), "boot")
# expect_equal(boo$t0, orig.stats)
# expect_equal(nrow(boo$t), nsim)
# expect_equal(ncol(boo$t), length(orig.stats))
# expect_equal(boo$B, nsim)
# expect_equal(boo$sim, "parametric")
# expect_equal(boo$statistic, mySumm)
# })
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.