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.

new_hours
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 = "")
  1. new_hours ← 5

    1new_hours <- 52intercept <- 43
    values this step5new_hours
  2. intercept ← 43

    1new_hours <- 52intercept <- 433slope <- 9
    values this step43intercept
  3. slope ← 9

    2intercept <- 433slope <- 94predicted <- intercept + slope * new_hours
    values this step9slope
  4. predicted ← 88

    3slope <- 94predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")
    values this step88predicted43intercept9slope5new_hours
  5. label ← pred:88

    4predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")
    values this steppred:88label88predicted
  6. cat(label, " ", sep = "")

    5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")
    outputpred:88
    values this steppred:88label
  1. new_hours ← 4

    1new_hours <- 42intercept <- 43
    values this step4new_hours
  2. intercept ← 43

    1new_hours <- 42intercept <- 433slope <- 9
    values this step43intercept
  3. slope ← 9

    2intercept <- 433slope <- 94predicted <- intercept + slope * new_hours
    values this step9slope
  4. predicted ← 79

    3slope <- 94predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")
    values this step79predicted43intercept9slope4new_hours
  5. label ← pred:79

    4predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")
    values this steppred:79label79predicted
  6. cat(label, " ", sep = "")

    5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")
    outputpred:79
    values this steppred:79label
  1. new_hours ← 6

    1new_hours <- 62intercept <- 43
    values this step6new_hours
  2. intercept ← 43

    1new_hours <- 62intercept <- 433slope <- 9
    values this step43intercept
  3. slope ← 9

    2intercept <- 433slope <- 94predicted <- intercept + slope * new_hours
    values this step9slope
  4. predicted ← 97

    3slope <- 94predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")
    values this step97predicted43intercept9slope6new_hours
  5. label ← pred:97

    4predicted <- intercept + slope * new_hours5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")
    values this steppred:97label97predicted
  6. cat(label, " ", sep = "")

    5label <- paste("pred", predicted, sep = ":")6cat(label, "\n", sep = "")
    outputpred:97
    values 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.