Created
August 6, 2020 07:38
-
-
Save strengejacke/adc5e0494d8aa687f5921409a408285c to your computer and use it in GitHub Desktop.
Explained variance for models with and without intercept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(parameters) | |
library(performance) | |
library(ggplot2) | |
set.seed(123) | |
x <- 3 + rnorm(200) | |
y <- 4 + .5 * x + rnorm(100) | |
dat <- data.frame(x, y) | |
ggplot(dat, aes(x, y)) + | |
geom_point() + | |
stat_smooth(method = "lm", se = FALSE, color = "green") + | |
stat_smooth(formula = y ~ 0 + x, method = "lm", se = FALSE, color = "red") | |
m1 <- lm(y ~ x, data = dat) | |
m2 <- lm(y ~ 0 + x, data = dat) | |
model_parameters(m1) | |
model_parameters(m2) | |
compare_performance(m1, m2, rank = TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Created on 2020-08-06 by the reprex package (v0.3.0)