context("Regression Info")
test_that("Extract regression information", {
x <- rnorm(100, mean = 2, sd = 2)
y <- 100 * x + 2 * rnorm(100, sd = 10) + rnorm(100)
reg <- lm(y ~ x)
a <- lm.reginfo(reg, c("n", "adj.rsq"))[["value"]]
r2 <- unlist(summary(reg)["adj.r.squared"])
names(r2) <- NULL
expect_equal(
a,
data.frame(key = c("n", "adj.rsq"), stat = c(100, round(r2, 2)),
stringsAsFactors = FALSE)
)
})
test_that("Make table of reg info", {
x <- rnorm(100, mean = 2, sd = 2)
z <- c(rep(10, 30), rep(2, 30), rep(-10, 40))
y <- 3*x + z + rnorm(100)
reg1 <- lm(y ~ x)
reg2 <- lm(y ~ z)
info <- list(lm.reginfo(reg1, c("n", "adj.rsq")),
lm.reginfo(reg2, c("n", "adj.rsq")))
tab <- reginfotable(info)
r21 <- round(unlist(summary(reg1)["adj.r.squared"]), 2)
r22 <- round(unlist(summary(reg2)["adj.r.squared"]), 2)
names(r21) <- NULL
names(r22) <- NULL
out <- data.frame(
stat = c("Adjusted R2", "N"), stat = c(r21, 100), stat = c(r22, 100),
stringsAsFactors = FALSE) %>% setNames(c("name", "stat", "stat"))
expect_equal(tab, out)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.