What goes wrong if the relationship between \(x\) and \(y\) isn’t linear?
\(\hat\beta_1\) = 2 (95% CI: 1.79, 2.21)
\(\hat\beta_1\) = 0.11 (95% CI: -0.08, 0.3)
How can I add the fitted values \((\hat{y})\) to my data frame?
How can I add the residual values \((e)\) to my data frame?
How can I add the residual values \((e)\) to my data frame?
How can I create a scatterplot of the residuals vs the fitted values?
How can I create a scatterplot of the residuals vs the fitted values?
\(\sum e_i\) = 0
\(\sum e_i\) = 0
lm
in R)How can I create a scatterplot of the residuals vs the fitted values?
d4 <- tibble(x = rnorm(100),
y = 2 * x + x / 2 * rnorm(100, sd = 10))
m4 <- lm(y ~ x, data = d4)
d4 <- d4 |>
mutate(y_hat = fitted(m4),
e = residuals(m4))
ggplot(d4, aes(x = y_hat, y = e)) +
geom_point(color = "#86a293") +
geom_hline(yintercept = 0, color = "#86a293") +
labs(x = "Fitted value",
y = "Residual")
d5 <- tibble(x = runif(100, max = 10),
y = x * rnorm(100, sd = 10))
m5 <- lm(y ~ x, data = d5)
d5 <- d5 |>
mutate(y_hat = fitted(m5),
e = residuals(m5))
ggplot(d5, aes(x = y_hat, y = e)) +
geom_point(color = "#86a293") +
geom_hline(yintercept = 0, color = "#86a293") +
labs(x = "Fitted value",
y = "Residual")
What kind of plot could help us assess whether a variable’s distribution is Normal?