bt <- bigarx_boot(USArrests, B = 200, seed = 123, progress = FALSE) test_that("la estimacion puntual coincide con el biplot original", { f <- bigarx(USArrests) t <- bt$table ine <- t[t$tipo == "inercia", "estimacion"] expect_equal(ine, f$inertia$inercia[1:3]) co <- t[t$tipo == "coordenada" & t$eje == "Eje1", "estimacion"] expect_equal(co, unname(f$cols[, 1])) cal <- t[t$tipo == "calidad", "estimacion"] expect_equal(cal, unname(rowSums(f$quality_cols[, 1:2]))) }) test_that("bootstrap reproducible con semilla y estructura correcta", { bt2 <- bigarx_boot(USArrests, B = 200, seed = 123, progress = FALSE) expect_equal(bt$table, bt2$table) expect_equal(bt$B, 200) expect_true(all(bt$table$inferior <= bt$table$superior)) expect_equal(sum(bt$table$tipo == "angulo_variables"), choose(4, 2)) }) test_that("los angulos estan entre 0 y 180 grados", { a <- bt$replicates[, grepl("^angulo", colnames(bt$replicates))] expect_true(all(a >= 0 & a <= 180)) }) test_that("la alineacion de signos evita intervalos inflados", { # Assault carga fuerte en el eje 1: su intervalo no debe cruzar el cero t <- bt$table r <- t[t$tipo == "coordenada" & t$elemento == "Assault" & t$eje == "Eje1", ] expect_true(r$inferior > 0 || r$superior < 0) }) test_that("intervalos normales usan el error estandar", { bn <- bigarx_boot(USArrests, B = 200, seed = 1, ci = "normal", progress = FALSE) t <- bn$table expect_equal(t$superior - t$estimacion, qnorm(0.975) * t$ee) }) test_that("con datos simulados, el intervalo del angulo cubre el valor poblacional", { set.seed(42) n <- 300 z1 <- rnorm(n); z2 <- rnorm(n) X <- cbind(a = z1, b = z1 + 0.3 * rnorm(n), c = z2, d = z2 + 0.3 * rnorm(n)) b <- bigarx_boot(X, B = 300, seed = 2, progress = FALSE) t <- b$table ang_ab <- t[t$tipo == "angulo_variables" & t$elemento == "a-b", ] ang_ac <- t[t$tipo == "angulo_variables" & t$elemento == "a-c", ] expect_lt(ang_ab$superior, 30) # muy correlacionadas: angulo pequeno expect_true(ang_ac$inferior < 90 + 15 && ang_ac$superior > 90 - 15) # independientes: ~90 }) test_that("summary, print y graficos del bootstrap", { expect_output(print(bt), "bootstrap") expect_output(summary(bt, type = "calidad"), "calidad") pdf(NULL); on.exit(dev.off()) expect_invisible(plot(bt)) expect_invisible(plot(bt, type = "angulo_variables")) skip_if_not_installed("ggplot2") expect_s3_class(ggplot2::autoplot(bt), "ggplot") expect_s3_class(ggplot2::autoplot(bt, type = "calidad"), "ggplot") }) test_that("errores del bootstrap", { expect_error(bigarx_boot(USArrests, B = 10), "al menos 50") })