Regression Workflows
Prediction Scenario
Apply Coefficients
A fitted model becomes useful when its coefficients are applied to a new case.
Program
Play the script to change the planned study hours and see the predicted score.
prediction_scenario.R
Replay: real traced execution (multi-file project)
new_hours <- 5
intercept <- 43
slope <- 9
predicted <- intercept + slope * new_hours
label <- paste("pred", predicted, sep = ":")
cat(label, "\n", sep = "")
new_hours <- 4
intercept <- 43
slope <- 9
predicted <- intercept + slope * new_hours
label <- paste("pred", predicted, sep = ":")
cat(label, "\n", sep = "")
new_hours <- 6
intercept <- 43
slope <- 9
predicted <- intercept + slope * new_hours
label <- paste("pred", predicted, sep = ":")
cat(label, "\n", sep = "")
new_hours ← 5
1new_hours <- 52intercept <- 43values this step5new_hoursintercept ← 43
1new_hours <- 52intercept <- 433slope <- 9values this step43interceptslope ← 9
2intercept <- 433slope <- 94predicted <- intercept + slope * new_hoursvalues this step9slopepredicted ← 88
3slope <- 94predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")values this step88predicted43intercept9slope5new_hourslabel ← pred:88
4predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")values this steppred:88label88predictedcat(label, " ", sep = "")
5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")outputpred:88values this steppred:88label
new_hours ← 4
1new_hours <- 42intercept <- 43values this step4new_hoursintercept ← 43
1new_hours <- 42intercept <- 433slope <- 9values this step43interceptslope ← 9
2intercept <- 433slope <- 94predicted <- intercept + slope * new_hoursvalues this step9slopepredicted ← 79
3slope <- 94predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")values this step79predicted43intercept9slope4new_hourslabel ← pred:79
4predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")values this steppred:79label79predictedcat(label, " ", sep = "")
5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")outputpred:79values this steppred:79label
new_hours ← 6
1new_hours <- 62intercept <- 43values this step6new_hoursintercept ← 43
1new_hours <- 62intercept <- 433slope <- 9values this step43interceptslope ← 9
2intercept <- 433slope <- 94predicted <- intercept + slope * new_hoursvalues this step9slopepredicted ← 97
3slope <- 94predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")values this step97predicted43intercept9slope6new_hourslabel ← pred:97
4predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")values this steppred:97label97predictedcat(label, " ", sep = "")
5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")outputpred:97values this steppred:97label
prediction
A prediction plugs a new predictor value into the fitted equation.
intercept
`intercept` is the baseline value when the predictor is zero.
slope
`slope * new_hours` adds the predictor contribution.