#set document(title: "12.8 Prediction", author: "Rachel Webb") #set page(width: 8.5in, height: auto, margin: 1in) #import "@preview/cetz:0.5.2" #set text(font: ("STIX Two Text", "Libertinus Serif", "New Computer Modern"), size: 10.5pt, lang: "en") #show math.equation: set text(font: ("STIX Two Math", "New Computer Modern Math")) #set par(justify: true, leading: 0.62em, spacing: 0.9em) #set enum(spacing: 1.1em) // room between list items so tall inline fractions don't collide #set list(spacing: 1.1em) #set table(stroke: 0.5pt + rgb("#c7ccd3")) #let BLUE = rgb("#183B6F") // brand navy — section bars + example/solution labels (white on navy 11.09:1) #let ORANGE = rgb("#A94509") // brand primary-700 — AA-safe deep orange for TEXT (5.93:1 on white; raw brand #F37021 is 2.94:1 and must never carry text) #let RED = rgb("#DC2626") // brand error-600 #let GREEN = rgb("#059669") // brand success-600 (decoration only; small green text uses green-text #007942) #show heading.where(level: 1): it => block(width: 100%, above: 0pt, below: 16pt, fill: gradient.linear(BLUE, rgb("#2C5AA0")), inset: (x: 14pt, y: 12pt), radius: 3pt, text(fill: white, weight: "bold", size: 19pt, it.body)) #show heading.where(level: 2): it => block(width: 100%, above: 18pt, below: 10pt, fill: BLUE, inset: (x: 10pt, y: 6pt), radius: 2pt, text(fill: white, weight: "bold", size: 12pt, it.body)) #show heading.where(level: 3): it => text(fill: ORANGE, weight: "bold", size: 12.5pt, it.body) #show heading.where(level: 4): it => text(fill: BLUE, weight: "bold", size: 10.5pt, it.body) #let examplebox(label, title, body) = block(width: 100%, breakable: true, fill: rgb("#EFF1F5"), stroke: 0.5pt + rgb("#CFDDF0"), radius: 4pt, inset: 10pt, above: 12pt, below: 12pt)[ #block(below: 6pt)[#box(fill: BLUE, inset: (x: 6pt, y: 2pt), radius: 2pt, text(fill: white, weight: "bold", size: 8.5pt, label)) #h(0.4em) #strong[#title]] #body] // rail = decorative left rule (raw brand token); labelcolor = AA-safe label text shade #let notebox(label, rail, labelcolor, tint, body) = block(width: 100%, breakable: true, fill: tint, stroke: (left: 3pt + rail), inset: (left: 10pt, rest: 8pt), radius: (right: 4pt), above: 11pt, below: 11pt)[ #text(fill: labelcolor, weight: "bold", size: 7.5pt, tracking: 0.5pt)[#upper(label)] #linebreak() #body] #let solutionbox(body) = block(above: 4pt, below: 8pt)[ #text(fill: BLUE, weight: "bold", size: 8.5pt)[Solution] #linebreak() #body] #let figph(msg) = block(width: 100%, height: 60pt, fill: rgb("#f6f7f9"), stroke: (paint: rgb("#c7ccd3"), dash: "dashed"), radius: 4pt, inset: 10pt)[ #align(center + horizon, text(fill: rgb("#889"), style: "italic", size: 9pt, msg))] // Standardize inlined figure sizes: measure the natural CeTZ canvas, then scale to a // consistent envelope (aspect-aware; see build_typst.py FIG_* constants). Unlike the // print preamble, dimensions are FLOORED: in an editor a user can trim a figure to a // degenerate 1-D shape (a bare line), and w/h or tw/w would then divide by zero. #let _STD_W = 3.5 #let _WIDE_W = 5.6 #let _MAX_H = 3.4 #let _ASPECT_WIDE = 2.2 #let _UPSCALE_MAX = 1.15 #let stdfig(body) = context { let m = measure(body) let w = calc.max(m.width / 1in, 0.01) let h = calc.max(m.height / 1in, 0.01) let tw = if w / h > _ASPECT_WIDE { _WIDE_W } else { _STD_W } let s = calc.min(tw / w, _MAX_H / h, _UPSCALE_MAX) align(center, box(scale(x: s * 100%, y: s * 100%, reflow: true, body))) } #show figure: set block(breakable: false) #set figure(gap: 8pt) #show figure.caption: set text(size: 8.5pt, fill: rgb("#555")) == 12.8#h(0.6em)Prediction We can now use the least squares regression equation for prediction. #examplebox("Example 1")[][ Use the regression equation to predict the grade for a student who has studied for 18 hours for their exam using the previous data. Hours Studied for Exam 20 16 20 18 17 16 15 17 15 16 15 17 16 17 14 Grade on Exam 89 72 93 84 81 75 70 82 69 83 80 83 81 84 76 #solutionbox[ We found the regression equation #math.equation(block: false, alt: "y hat equals 26.742 plus 3.216346 x")[$hat(y) = 26.742 + 3.216346 x$]. The #math.equation(block: false, alt: "x")[$x$]-variable is the hours studied so let #math.equation(block: false, alt: "x equals 18")[$x = 18$] hours. #math.equation(block: false, alt: "y hat")[$hat(y)$] is the symbol for the predicted #math.equation(block: false, alt: "y")[$y$]. Substitute #math.equation(block: false, alt: "x equals 18")[$x = 18$] into the regression equation and you get: #math.equation(block: false, alt: "y hat equals 26.742 plus 3.216346 times 18 equals 84.636228")[$hat(y) = 26.742 + 3.216346 · 18 = 84.636228$]. We would estimate the student’s grade to be 84.6 when they studied 18 hours. This is a point estimate for the grade on the exam for a student that studied 18 hours. ] ] === Prediction Interval We can find a special type of confidence interval to estimate the true value of #math.equation(block: false, alt: "y")[$y$] called the #strong[prediction interval]. The prediction interval is the confidence interval for the actual value of #math.equation(block: false, alt: "y")[$y$]: #math.equation(block: true, alt: "y hat ± t sub α / 2 times s the square root of open parenthesis 1 plus the fraction 1 over n plus the fraction open parenthesis x minus x bar close parenthesis squared over S S sub x x close parenthesis")[$hat(y) ± t_(α / 2) · s sqrt(( 1 + frac(1, n) + frac(( x − overline(x) )^(2), S S_(x x)) ))$] where #math.equation(block: false, alt: "y hat")[$hat(y)$] is the predicted value of #math.equation(block: false, alt: "y")[$y$] for the given value of #math.equation(block: false, alt: "x")[$x$]. #examplebox("Example 2")[][ Using the previous data, find and interpret the 95% prediction interval for a student who studies 18 hours. \# The book notes Excel and the TI-83/84 have NO built-in prediction interval. \# One line of R closes that gap. hours \<- c(20,16,20,18,17,16,15,17,15,16,15,17,16,17,14) grade \<- c(89,72,93,84,81,75,70,82,69,83,80,83,81,84,76) fit \<- lm(grade ~ hours) coef(fit) \# b0 = 26.742, b1 = 3.216346 predict(fit, data.frame(hours = 18), interval = "prediction") \# 84.64 with 95% PI \[75.66, 93.61\] #solutionbox[ From the question, #math.equation(block: false, alt: "x equals 18")[$x = 18$]. From previous examples we found that #math.equation(block: false, alt: "y hat equals 26.742 plus 3.216346 times 18 equals 84.636228")[$hat(y) = 26.742 + 3.216346 · 18 = 84.636228$] and #math.equation(block: false, alt: "s equals 3.935892")[$s = 3.935892$]. Find the critical value from the invT using #math.equation(block: false, alt: "d f equals n minus 2 equals 13")[$d f = n − 2 = 13$]; we get #math.equation(block: false, alt: "t sub α / 2 equals 2.160369")[$t_(α / 2) = 2.160369$]. Make sure to go out at least 6 decimal places in between steps. Ideally, never round between steps. Use the 2-Var Stats from your calculator to find the sums and then substitute values back into the equation to get #math.equation(block: true, alt: "84.636228 ± 2.1600369 times 3.935892 the square root of open parenthesis 1 plus the fraction 1 over 15 plus the fraction open parenthesis 18 minus 16.6 close parenthesis squared over 41.6 close parenthesis; ⇒ 84.636228 ± 8.9723; ⇒ 75.6639 less than y less than 93.6085")[$84.636228 ± 2.1600369 · 3.935892 sqrt(( 1 + frac(1, 15) + frac(( 18 − 16.6 )^(2), 41.6) )) \ ⇒ #h(1em) 84.636228 ± 8.9723 \ ⇒ #h(1em) 75.6639 < y < 93.6085$] We are 95% confident that the predicted exam grade for a student that studies 18 hours is between 75.6639 and 93.6085. A confidence interval can be more accurate (narrower) when you increase the sample size. Note that in the last example, the predicted grade for an individual student could have been anywhere from a C to an A grade. If you wanted to predict #math.equation(block: false, alt: "y")[$y$] with more accuracy, then you would want to sample more than 15 students to get a smaller margin of error. The confidence interval for a mean will have a smaller margin of error than for an individual’s predicted value. Excel, the TI-83 and 84 do not have built in prediction intervals. #strong[TI-89:] Enter the #math.equation(block: false, alt: "x")[$x$]-values in list1 and the #math.equation(block: false, alt: "y")[$y$]-values in list2, select \[F7\] Intervals, then select option 7:LinRegTInt… Use the Var-Link button to enter in list1 and list2 for the X List and Y List. Select Response in the drop-down menu for Interval. Enter in the #math.equation(block: false, alt: "x")[$x$]-value given in the question. Change the confidence level (C-Level) to match what was in the question, the \[Enter\]. Scroll down to Pred Int for the prediction interval. The calculator does not round between steps so if you rounded #math.equation(block: false, alt: "b sub 0")[$b_(0)$] and #math.equation(block: false, alt: "b sub 1")[$b_(1)$], for instance, when doing hand calculations, your answer may be slightly different than the calculator results. #figure(figph[Entering confidence levels in the Response interval type in the TI-89 Linear Regression T Test setup.], alt: "Entering confidence levels in the Response interval type in the TI-89 Linear Regression T Test setup.", caption: none) #strong[Extrapolation] is the use of a regression line for prediction far outside the range of values of the independent variable #math.equation(block: false, alt: "x")[$x$]. As a general rule, one should not use linear regression to estimate values too far from the given data values. The further away you move from the center of the data set, the more variable results become. For instance, we would not want to estimate a student’s grade for someone that studied way less than 14 hours or more than 20 hours. ] ]