Regression Workflows
Regression Slope
Fit a Trend
A regression workflow starts by estimating how much the response changes with one predictor.
Program
Play the script to adjust the last score and watch the fitted slope change.
regression_slope.R
bonus <-
hours <- c(1, 2, 3, 4)
score <- c(52, 61, 70, 79) + c(0, 0, 0, bonus)
fit <- lm(score ~ hours)
slope <- round(coef(fit)[["hours"]], 1)
label <- paste("slope", slope, sep = ":")
cat(label, "\n", sep = "")
bonus <-
hours <- c(1, 2, 3, 4)
score <- c(52, 61, 70, 79) + c(0, 0, 0, bonus)
fit <- lm(score ~ hours)
slope <- round(coef(fit)[["hours"]], 1)
label <- paste("slope", slope, sep = ":")
cat(label, "\n", sep = "")
bonus <-
hours <- c(1, 2, 3, 4)
score <- c(52, 61, 70, 79) + c(0, 0, 0, bonus)
fit <- lm(score ~ hours)
slope <- round(coef(fit)[["hours"]], 1)
label <- paste("slope", slope, sep = ":")
cat(label, "\n", sep = "")
linear model
`lm(score ~ hours)` estimates an intercept and a slope.
coefficient
`coef(fit)[["hours"]]` reads the predictor slope.
sensitivity
Changing one observation can change the fitted trend.