View source: R/r_squared_vis.R
simulate | R Documentation |
Simulate a data frame for multiple regression.
simulate(n = 100, beta = c(5, 3, -2), r_squared = 0.8)
n |
number of observations. |
beta |
beta coefficients. Position one is the intercept, the rest are predictors. |
r_squared |
desired R-squared value. |
a data.frame.
get_r_squared <- function(desired) {
model <- lm(y ~ x1 + x2, data = simulate(r_squared = desired, n = 100))
return(summary(model)$r.squared)
}
df <- data.frame(desired_r_squared = seq(from = 0.05, to = 0.95, by = 0.05))
df$actual_r_squared <- sapply(df$desired_r_squared, FUN = get_r_squared)
plot(df)
abline(a=0, b=1, col="red", lty=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.