AII 600 midterm prep

Practice midterm. Fall 2026

The midterm is on Wednesday, 14 October, in class. You have 2 hours 30 minutes for 7 problems worth 100 points. It is pen and paper: bring one double-sided cheat sheet, printed or handwritten. No calculator, laptop, phone, watch, or AI assistant.

This page is a practice midterm. Each problem below is a twin of the exam problem with the same number: the same topic, the same kinds of parts, and the same point values, in a new setting with new numbers. If you can do these seven problems on paper and in time, you are ready for the exam.

How to use this page

  1. Sit it as an exam first. Set a timer for 2 hours 30 minutes, put the calculator away, and use only your cheat sheet. Budget about 1.5 minutes per point.
  2. Then mark your work. Each problem ends with a collapsed Solution box; click it to open. Mark yourself the way the exam is marked: a correct number with no work earns little credit, and a part that asks what a result means needs a full sentence.
  3. Close the gaps. Under each problem, a Review line points to the section of the study guide that builds the idea from the start, with worked examples and practice problems, and to an interactive lab where you can watch the idea move. If a part took far longer than its points allow, practice that skill until it is quick. The problem bank has more problems on each topic, with solutions.

The rules that shape the problems

  • No calculator, and none needed. The numbers are chosen so that the arithmetic is short, and fractions such as \(3/8\) are fine as final answers. When a part needs a value that is hard to compute by hand, such as \(0.975^{20}\) or a value of the sigmoid, the problem gives it. The study guide’s section on arithmetic without a calculator shows the shortcuts.
  • One normal fact. For a standard normal \(Z\), \(P(-1.96\le Z\le 1.96)=0.95\). Together with the symmetry of the normal curve, that is all the normal problem needs.
  • Show the reasoning. Define your events and random variables before you use them, and state every assumption you make, such as independence or a normal model.

Map of the exam

Problem Topic Points Study guide Lab
1 Joint, marginal, and conditional distributions 15 §2 Joint Table
2 Bayes rule and base rates 15 §3 Base-Rate
3 The binomial distribution 12 §5 Galton Board, Streaks
4 A normal model for a decision 14 §6 Normal Tails
5 Linear regression 22 §7, §8 Least Squares, Regression Model
6 Logistic regression 12 §9 Logistic Regression
7 Concepts: true or false 10 §10 Portfolio
Total 100

The material is the slides for Foundations and Estimation and regression through linear regression, and the logistic regression slides from the 7 October class. In the textbook, Bayes, Artificial Intelligence, and Deep Learning, the matching chapters are Chapter 1 (probability, through the normal distribution), Chapter 2 (Bayes rule), Chapter 12 (linear regression), and Chapter 13 (logistic regression). The exercises at the end of these chapters are good extra practice. Skip the ones that need a computer.

Problem 1: Joint, Marginal, and Conditional Distributions (15 points)

A call center records two numbers for each of its agents: the number of customer issues \(X\) the agent resolves per hour, and the number of weeks \(Y\) of training the agent received. The joint distribution over the center’s agents is below.

\(Y=1\) \(Y=2\) \(Y=3\) \(Y=4\)
\(X=4\) 0.10 0.10 0.04 0.02
\(X=6\) 0.10 0.10 0.16 0.04
\(X=8\) 0.00 0.10 0.20 0.04
  1. (2) Verify that this is a legal joint probability table. Then find the marginal distribution of \(X\) and the marginal distribution of \(Y\).
  2. (1) What is the probability that a randomly chosen agent had at least two weeks of training?
  3. (2) Compute the mean number of issues resolved per hour, \(E(X)\).
  4. (3) Find the conditional distribution of \(X\) given \(Y=3\) and the conditional mean \(E(X\mid Y=3)\). In one sentence, explain why \(E(X\mid Y=3)\) differs from \(E(X)\).
  5. (2) Are issues resolved and training independent? Justify your answer with a single cell of the table.
  6. (2) A randomly chosen agent is paid $15 per hour plus $0.50 for each issue resolved, and works 8 hours a day. What is the expected daily pay? Did you need to assume that the eight hours are independent? Explain.
  7. (3) The other conditional means are \(E(X\mid Y=1)=5\), \(E(X\mid Y=2)=6\), and \(E(X\mid Y=4)=6.4\). Average the four conditional means with weights \(P(Y=y)\) and compare the result with part (c). A manager then concludes: “More training always means more issues resolved.” Does the table support this claim? Give one reason to be careful before setting training policy from the \(Y=4\) column.

Review: study guide §1 for marginals and expected values, and §2 for conditional distributions and the law of total expectation. Lab: in the Joint Table Lab, load Happiness × Salary, click a column heading to condition on it, and watch the column rescale to a conditional distribution. Then press Make independent and compare the cells with the originals.

  1. Every entry is between 0 and 1, and the entries sum to \(0.26+0.40+0.34=1\). Marginal of \(X\) (row sums): \(P(X=4)=0.26\), \(P(X=6)=0.40\), \(P(X=8)=0.34\). Marginal of \(Y\) (column sums): \(P(Y=1)=0.20\), \(P(Y=2)=0.30\), \(P(Y=3)=0.40\), \(P(Y=4)=0.10\).
  2. \(P(Y\ge 2)=0.30+0.40+0.10=0.80\), or \(1-P(Y=1)=1-0.20=0.80\).
  3. \(E(X)=4(0.26)+6(0.40)+8(0.34)=1.04+2.40+2.72=6.16\) issues per hour.
  4. Divide the \(Y=3\) column by \(P(Y=3)=0.40\): \(P(X=4\mid Y=3)=0.04/0.40=0.1\), \(P(X=6\mid Y=3)=0.16/0.40=0.4\), \(P(X=8\mid Y=3)=0.20/0.40=0.5\). They sum to 1. Then \(E(X\mid Y=3)=4(0.1)+6(0.4)+8(0.5)=0.4+2.4+4=6.8\). Conditioning on three weeks of training moves weight to the top of the scale: half of these agents resolve 8 issues an hour, against 34% of all agents.
  5. Not independent. \(P(X=8, Y=1)=0\), but \(P(X=8)P(Y=1)=0.34\times 0.20=0.068\neq 0\). (Any cell where the product rule fails works, for example \(P(X=8\mid Y=3)=0.5\neq 0.34=P(X=8)\).)
  6. The day’s issues are \(X_1+\dots+X_8\), so \(E(\text{pay})=8(15)+0.50\times 8\times 6.16=120+24.64=\$144.64\). Independence is not needed: \(E(X_1+\dots+X_8)=E(X_1)+\dots+E(X_8)\) holds for any dependence between hours. What is needed is that each hour has the distribution in the table. Independence would matter for the variance of daily pay, not its mean.
  7. \(5(0.20)+6(0.30)+6.8(0.40)+6.4(0.10)=1+1.8+2.72+0.64=6.16\), which is \(E(X)\) from part (c): average within groups, then across groups (the law of total expectation). The claim is not supported: the mean rises from 5 to 6.8 over the first three weeks but falls to 6.4 at four weeks. Reasons for care (any one): only 10% of agents are in the \(Y=4\) column, so it may rest on few people; the table is an association, and who receives four weeks of training is not random (agents who struggled may have been kept in training longer), so it does not say what an extra week would do for a given agent.

How this is marked. In (d), dividing by \(P(X=\cdot)\) instead of \(P(Y=3)\) is the common error. In (g), full credit needs the check and one concrete reason.

Problem 2: Bayes Rule and Base Rates (15 points)

A university runs essays through a detector for AI-written text. The detector has the following properties.

  • If an essay was written by AI, the detector flags it with probability 0.8.
  • If an essay was written by the student, the detector flags it with probability 0.1.

A teaching assistant believes that 4% of the essays in a course are AI-written. The professor believes that 20% are. The detector flags Sam’s essay.

  1. (2) What are the sensitivity and the specificity of this detector?
  2. (4) Compute the teaching assistant’s probability that Sam’s essay is AI-written, and the professor’s. Show the law of total probability step and name each rule you use.
  3. (3) Redo part (b) in odds form, with the odds written as \(P(\text{AI})/P(\text{human})\). Compute the Bayes factor, each person’s prior odds, and each person’s posterior odds. Then find the prior probability of AI writing at which one flag makes “AI” and “human” equally likely.
  4. (2) A student newspaper writes: “The detector catches 80% of AI essays, so Sam’s essay is 80% likely to be AI-written.” Which conditional probability did the newspaper report, and which conditional probability answers the question? Name the error.
  5. (4) The essay is run through a second detector with the same error rates, and it also flags the essay. Assume the two results are independent given who wrote the essay. Update the teaching assistant’s probability. Then describe one realistic way this independence assumption could fail, and say whether the failure would make your updated probability too high or too low.

Review: study guide §3. Lab: in the Base-Rate Lab, set the prevalence to 4%, the sensitivity to 80%, and the specificity to 90%, and count how many of the positives are real. Press Positive again for the second detector, then move the prevalence to 20%.

Let \(A\) be “Sam’s essay is AI-written” and \(F\) “the detector flags it”. Given \(P(F\mid A)=0.8\) and \(P(F\mid \bar A)=0.1\).

  1. Sensitivity \(P(F\mid A)=0.8\). Specificity \(P(\bar F\mid \bar A)=1-0.1=0.9\).

  2. Law of total probability, then Bayes rule \(P(A\mid F)=P(F\mid A)P(A)/P(F)\).

    Teaching assistant: \(P(F)=0.8(0.04)+0.1(0.96)=0.032+0.096=0.128\), so \(P(A\mid F)=0.032/0.128=1/4=0.25\).

    Professor: \(P(F)=0.8(0.20)+0.1(0.80)=0.16+0.08=0.24\), so \(P(A\mid F)=0.16/0.24=2/3\approx 0.67\).

    Same detector and same flag, but a 25% and a 67% posterior. The prior does much of the work.

  3. Bayes factor \(P(F\mid A)/P(F\mid\bar A)=0.8/0.1=8\). Teaching assistant: prior odds \(0.04/0.96=1/24\), posterior odds \(8/24=1/3\), probability \((1/3)/(1+1/3)=1/4\). Professor: prior odds \(0.2/0.8=1/4\), posterior odds \(8/4=2\), probability \(2/(1+2)=2/3\). Equal posterior odds of 1 need prior odds \(1/8\), so \(P(A)=1/9\approx 0.11\). One flag pushes an essay past 50% only if you already believed that more than 1 essay in 9 is AI-written.

  4. The newspaper reported \(P(F\mid A)=0.8\), the sensitivity. The question is \(P(A\mid F)\), which is \(0.25\) for the teaching assistant. This is the prosecutor’s fallacy, also called the base rate fallacy: it confuses \(P(\text{evidence}\mid\text{guilty})\) with \(P(\text{guilty}\mid\text{evidence})\) and ignores how rare AI essays are. Under the teaching assistant’s prior, \(0.096/0.128=0.75\): three flags in four land on essays the student wrote.

  5. With independent results the Bayes factors multiply: posterior odds \(=\frac{1}{24}\times 8^2=\frac{64}{24}=\frac{8}{3}\), so \(P(A\mid F_1,F_2)=8/11\approx 0.73\). (Same answer using \(1/4\) as the new prior: \(0.8(0.25)/[0.8(0.25)+0.1(0.75)]=0.2/0.275=8/11\).) Independence fails if both detectors react to the same features of human writing, for example a formal, repetitive style or non-native English. Then a human-written essay that one detector flags is more likely than 10% to be flagged by the other, the second Bayes factor is smaller than 8, and \(8/11\) is too high. (The dependence can also run the other way: if AI essays that one detector catches are more likely than 80% to be caught by the other, the Bayes factor is larger than 8 and \(8/11\) is too low. For an essay that may be human-written, the shared false alarm is the realistic worry.)

How this is marked. Reporting 0.8 anywhere in (b) earns no credit for that part. In (c), odds in the class orientation, \(P(\text{human})/P(\text{AI})\), are fine if used consistently: Bayes factor \(1/8\), prior odds 24 and 4, posterior odds 3 and \(1/2\). In (e), full credit needs a mechanism and the direction that follows from it.

Problem 3: The Binomial Distribution (12 points)

A sales representative makes 4 cold calls an hour. Each call ends in a sale with probability 0.1. Let \(X\) be the number of sales in an hour.

  1. (2) Explain why \(X\sim\mathrm{Binomial}(4, 0.1)\). Name the conditions that make it binomial, and say which of them is an assumption you would want to check.

  2. (3) Complete the table, where \(F(k)=P(X\le k)\).

    \(k\) 0 1 2 3 4
    \(P(X=k)\) ______ ______ ______ ______ ______
    \(F(k)\) ______ ______ ______ ______ ______
  3. (2) The representative earns a bonus for any hour with at least 2 sales. What is the probability that an hour earns the bonus?

  4. (2) Find \(E(X)\) and \(sd(X)\). Interpret \(E(X)\) in one sentence.

  5. (3) Each sale earns a commission of $50, and each call costs $3 (phone time and the fee for the lead). Find the expected net earnings per call and per hour. A second list of leads converts with probability 0.05 per call, at the same cost per call. Find the expected net earnings per hour on this list. Not calling earns $0. Should the representative call the second list?

Review: study guide §5, and §4 for the expected value of a sum. Lab: in the Galton Board Lab, set the rows of pegs to 4 and the chance of bouncing right to 0.1. Each ball’s bin is \(X\). Turn on the exact expected counts and drop 1,000 balls: about 52 of them should land in bins 2 to 4. The Streaks Lab shows the same distribution at work on real streaks.

  1. Each call is a trial with two outcomes, sale (success) or no sale. The number of trials is fixed, \(n=4\). The success probability is the same on every call, 0.1. And the calls must be independent: the outcome of one call does not change the chance on the next. Then \(X\), the number of successes, is \(\mathrm{Binomial}(4,0.1)\). Independence and a constant \(p\) are the assumptions to check: a representative rattled by a rejection, or a list sorted with the best leads first, would break them.

  2. \(P(X=k)=\binom{4}{k}(0.1)^k(0.9)^{4-k}\), with \(\binom{4}{k}=1,4,6,4,1\) and \(0.9^2=0.81\), \(0.9^3=0.729\), \(0.9^4=0.6561\). For example, \(P(X=1)=4(0.1)(0.729)=0.2916\) and \(P(X=2)=6(0.01)(0.81)=0.0486\).

    \(k\) 0 1 2 3 4
    \(P(X=k)\) 0.6561 0.2916 0.0486 0.0036 0.0001
    \(F(k)\) 0.6561 0.9477 0.9963 0.9999 1

    The probabilities sum to 1.

  3. \(P(X\ge 2)=1-F(1)=1-0.9477=0.0523\). About one hour in twenty earns the bonus.

  4. \(E(X)=np=4(0.1)=0.4\). \(Var(X)=np(1-p)=4(0.1)(0.9)=0.36\), so \(sd(X)=0.6\). Over many hours the representative averages 0.4 sales an hour, or 2 sales every 5 hours.

  5. One call earns $50 with probability 0.1 and costs $3 for sure, so its expected net is \(0.1(50)-3=5-3=\$2\). Expected values add, so an hour of 4 calls is worth \(4\times 2=\$8\). (Equivalently, the hour’s net is \(50X-12\), with mean \(50(0.4)-12=8\).) On the second list a call is worth \(0.05(50)-3=2.50-3=-\$0.50\), so an hour is worth \(4\times(-0.50)=-\$2\). That is below the $0 of not calling, so the representative should not call the second list, unless something the model leaves out, such as a lead who buys later, adds value.

How this is marked. In (b), an arithmetic slip carried consistently into (c) loses credit only once. In (e), full credit needs both expected values and the decision.

Problem 4: A Normal Model for a Provider Decision (14 points)

An app company sends its requests to one of two cloud providers. The response time of a request, in milliseconds (ms), is approximately normal, with the following means and standard deviations.

Mean Std. dev.
Provider A 240 30
Provider B 220 50

The company’s service agreement requires a response time of at most 300 ms, and the company will choose the provider that is more likely to meet that requirement. Use the fact that for a standard normal \(Z\), \(P(-1.96\le Z\le 1.96)=0.95\), together with the symmetry of the normal distribution.

  1. (4) For each provider, compute the \(z\)-score of the 300 ms limit. Which provider is more likely to meet the requirement? Explain why the \(z\)-scores are enough to decide, without computing any probabilities. Is either provider’s probability of exceeding the limit below 0.025?
  2. (2) Provider B has the lower mean. Explain in one or two sentences why it still loses in part (a).
  3. (2) Keep Provider B’s mean at 220 ms. How small would its standard deviation have to be for B to be at least as likely as A to meet the 300 ms limit?
  4. (3) Suppose the company tightens the limit to 260 ms. Which provider is better now? At what limit are the two providers equally good? State the rule in one sentence: when does the mean decide the choice, and when does the standard deviation?
  5. (3) Provider A offers to guarantee a response time that its requests exceed only 2.5% of the time. What time can it guarantee? Opening the app’s home screen sends 20 requests to the provider; assume their response times are independent. Name the distribution of the number of requests that exceed the guaranteed time. What is the expected number, and what is the probability that at least one exceeds it when the home screen opens? You may use \(0.975^{20}\approx 0.60\).

Review: study guide §6, and §5 for part (e). Lab: in the Normal Tails Lab, set the mean to 240 and the SD to 30, shade \(X>b\) with \(b=300\), and read the tail probability. Then try a mean of 220 and an SD of 50, and repeat with \(b=260\) and \(b=270\).

  1. A: \(z=(300-240)/30=60/30=2.0\). B: \(z=(300-220)/50=80/50=1.6\). For each provider \(P(T>300)=P(Z>z)\), where \(T\) is the response time, and the area to the right of \(z\) shrinks as \(z\) grows. The limit sits further out in A’s upper tail, so A exceeds it less often: choose Provider A. By symmetry \(P(Z>1.96)=0.025\). A’s \(z=2.0\) is beyond 1.96, so A’s probability of exceeding 300 ms is below 0.025. B’s \(z=1.6\) is not, so B’s probability is above 0.025. (Software gives 0.023 for A and 0.055 for B.)
  2. The requirement is about the upper tail, not the center. B’s larger standard deviation spreads more probability above 300 ms: the limit is 2 standard deviations above A’s mean but only 1.6 above B’s.
  3. B ties A when \((300-220)/\sigma_B=2\), so \(\sigma_B=80/2=40\). B needs \(\sigma_B\le 40\) ms.
  4. At 260 ms: A has \(z=(260-240)/30=0.67\) and B has \(z=(260-220)/50=0.8\). Now the limit is further out in B’s tail, so B is less likely to exceed it: B is better. (Software: 0.25 for A, 0.21 for B.) The providers tie when \((c-240)/30=(c-220)/50\), that is \(50c-12{,}000=30c-6{,}600\), so \(c=270\) ms (both \(z=1\)). For a limit below 270 ms B wins; above 270 ms A wins. A limit near the center is decided by the mean; a limit far in the tail is decided by the standard deviation.
  5. The upper 2.5% of A’s distribution starts at \(240+1.96(30)=240+58.8=298.8\), so A can guarantee about 299 ms. \(N\sim\mathrm{Binomial}(20,0.025)\), with \(E(N)=20(0.025)=0.5\). \(P(N\ge 1)=1-0.975^{20}\approx 1-0.60=0.40\). A guarantee that holds for 97.5% of requests still fails on about 40% of home screen openings: at scale, users feel the tail. (A caution on the model: real response times are skewed to the right, with a long tail of slow requests, so a normal model understates how often very slow requests happen.)

Problem 5: Linear Regression (22 points)

Part A. Fitting a line by hand. A sleep study records, for five volunteers, the hours of sleep \(x\) the night before a test and the number of errors \(y\) each made on a proofreading test.

Volunteer 1 2 3 4 5
\(x\) (hours) 5 6 7 8 9
\(y\) (errors) 15 13 10 8 4
  1. (4) Compute the least squares slope and intercept, \(\hat b=\dfrac{\sum_i (x_i-\bar x)(y_i-\bar y)}{\sum_i (x_i-\bar x)^2}\) and \(\hat a=\bar y-\hat b\,\bar x\). Interpret the slope and the intercept in one sentence each, in the units of the problem.
  2. (3) Compute the five fitted values and residuals \(e_i=y_i-\hat y_i\). Check that the residuals sum to zero, and compute the sum of squared residuals. Which volunteer is furthest from the line, and did that volunteer make more or fewer errors than predicted?
  3. (3) Volunteer 5’s test is re-scored: 9 errors, not 4. Recompute \(\hat b\) and \(\hat a\). Next, go back to the original data and suppose instead that volunteer 3 made 5 more errors. What happens to \(\hat b\) and \(\hat a\) now? Explain why the two changes have such different effects.

Part B. Reading a fitted model. A regression of the price of a used car on its mileage, for 200 cars of one model, gave the output below. Price is in thousands of dollars and miles is in thousands of miles. The cars in the data have between 20 and 150 thousand miles. The residual standard error, 2.5, is the estimate of \(\sigma\), the standard deviation of price around the line.

Call: lm(formula = price ~ miles)

Coefficients:
            Estimate
(Intercept)   30.000
miles         -0.150

Residual standard error: 2.5
  1. (2) Interpret the slope in dollars. Predict the price of a car with 60,000 miles.
  2. (2) Interpret the intercept. A dealer wants to advertise it as “the price of this model when new.” Should the dealer? Why or why not?
  3. (3) The model assumes \(\text{price}\mid\text{miles}\sim N(\beta_0+\beta_1\,\text{miles},\,\sigma^2)\). Recall that a normal random variable is within 1.96 standard deviations of its mean with probability 0.95. Give a range that should contain about 95% of sale prices of cars with 60,000 miles. One such car sold for $31,000. Compute its residual and standardized residual (the residual, in thousands of dollars, divided by 2.5), and say what you would do about this car.

Part C. Checking the model.

Figure 1: Standardized residuals plotted against x for three different fitted lines.
  1. (3) Figure 1 shows standardized residuals from three different straight-line fits. For each panel, say whether the straight-line model looks adequate. If it does not, name the problem and one remedy.
  2. (2) Least squares chooses the line that minimizes the sum of squared residuals. Under what assumption about the errors is this the same line as the one that maximizes the likelihood? Suppose one car’s price in Part B is entered with an extra zero, as $210,000 instead of $21,000. What happens to the least squares line, and why?

Review: study guide §7 for parts (a) to (e) and §8 for parts (f) to (h). Labs: in the Least Squares Lab, turn on the point \((\bar x,\bar y)\), drag a point at the right edge up, and watch the slope; then drag a point near the middle by the same amount. In the Regression Model Lab, turn on the \(\pm 2\sigma\) band and check that about 95% of the points fall inside it.

  1. \(\bar x=7\), \(\bar y=10\). Deviations: \(x_i-\bar x=-2,-1,0,1,2\) and \(y_i-\bar y=5,3,0,-2,-6\). \(\sum(x_i-\bar x)(y_i-\bar y)=-10-3+0-2-12=-27\) and \(\sum(x_i-\bar x)^2=10\). So \(\hat b=-2.7\) and \(\hat a=10-(-2.7)(7)=10+18.9=28.9\). Each additional hour of sleep goes with about 2.7 fewer errors on the test. The intercept, 28.9 errors, is the predicted count after zero hours of sleep; no volunteer slept less than 5 hours, so it is an extrapolation with no real meaning.
  2. \(\hat y=15.4,\ 12.7,\ 10.0,\ 7.3,\ 4.6\) and \(e=-0.4,\ 0.3,\ 0,\ 0.7,\ -0.6\). The sum is \(-0.4+0.3+0+0.7-0.6=0\). Sum of squared residuals \(=0.16+0.09+0+0.49+0.36=1.10\). Volunteer 4 is furthest from the line: 0.7 more errors than predicted.
  3. With \(y_5=9\): the sum of cross products changes by \((x_5-\bar x)\times 5=2\times 5=10\), to \(-17\), so \(\hat b=-1.7\); \(\bar y\) rises to 11, so \(\hat a=11-(-1.7)(7)=11+11.9=22.9\). One re-scored test flattens the slope by a full error per hour. With volunteer 3 making 5 more errors: the cross products change by \((x_3-\bar x)\times 5=0\), so \(\hat b=-2.7\) is unchanged; \(\bar y\) rises to 11, so \(\hat a=11+18.9=29.9\) and the whole line shifts up by 1 error. A point’s pull on the slope is proportional to its distance from \(\bar x\). A point at the edge of the \(x\) range tilts the line; a point at the center only shifts it.
  4. The slope is in thousands of dollars per thousand miles: each additional 1,000 miles lowers the predicted price by \(0.150\times 1000=\$150\), or 15 cents a mile. Prediction: \(30-0.150(60)=30-9=21\), that is $21,000.
  5. The intercept, $30,000, is the predicted price of a car with zero miles. The data stop at 20,000 miles, so it is an extrapolation of the line, not an observed price. New cars are sold in a different market, and cars lose value fastest early, so the line need not hold near zero. Should the dealer quote it? No: to learn the new price, look at new-car prices.
  6. Under the normal model about 95% of prices fall within \(1.96\sigma\) of the line: \(21\pm 1.96(2.5)=21\pm 4.9\), or $16,100 to $25,900 (\(\pm 2\sigma\) gives $16,000 to $26,000; either is fine). Residual: \(31-21=10\), that is $10,000. Standardized: \(10/2.5=4.0\). Under the normal model a residual at least 4 standard deviations above the line has probability about 1 in 30,000. Check the record first: a typo in price or mileage (with 6,000 miles the prediction would be \(30-0.9=29.1\) and the residual only 1.9). If the record is right, the car has something the model does not see, such as a rare trim or a new engine. Do not delete it just because it is large.
  7. Panel A: one standardized residual near \(-5\), the rest within about \(\pm 2\). An outlier: investigate that observation (a recording error?), refit without it to see how much the line moves, and if the value is real, keep it and report both fits. Panel B: no pattern, all values within about \(\pm 2.5\). Adequate. Panel C: an upside-down U, negative at both ends and positive in the middle. The conditional mean is curved and the line misses it systematically. Add \(x^2\) or transform a variable.
  8. Assume the errors are independent and normal with the same variance, \(Y_i\mid x_i\sim N(a+bx_i,\sigma^2)\). Then \(-\log L(a,b)=\frac{1}{2\sigma^2}\sum_i (y_i-a-bx_i)^2+C\), so maximizing the likelihood and minimizing the sum of squares give the same line. Against the line from the clean data, the mistyped price has a residual of \(210-21=189\) thousand dollars. Its square, about 36,000, is thousands of times larger than a typical squared residual of \(2.5^2\approx 6\). Squaring makes one large error dominate the sum, so the line moves toward that point: up, and tilted if the car’s mileage is far from the average mileage (part (c)). Check the data for typos before you fit.

How this is marked. In (f), keeping the residual in dollars ($10,000) is fine if it is divided by $2,500. In (g), each panel needs a verdict and, if the line fails, a problem and a remedy. In Panel A, “delete the outlier” without checking it earns partial credit.

Problem 6: Logistic Regression (12 points)

An email filter models whether an email is spam (\(y=1\)) or not (\(y=0\)). The fitted logistic regression is \[z=\log\frac{p}{1-p}=-1+1\,\text{links}-2\,\text{contact},\qquad p=\sigma(z)=\frac{1}{1+e^{-z}},\] where \(\text{links}\) is the number of links in the email, and \(\text{contact}\) is 1 if the sender is in the recipient’s contacts and 0 if not. Here log is the natural logarithm. Use the table below and the symmetry \(1-\sigma(z)=\sigma(-z)\); you need no other values.

\(z\) \(-3\) \(-2\) \(-1\) \(0\) \(1\) \(2\) \(3\)
\(\sigma(z)\) 0.05 0.12 0.27 0.50 0.73 0.88 0.95
\(\log\sigma(z)\) \(-3.0\) \(-2.1\) \(-1.3\) \(-0.69\) \(-0.31\) \(-0.13\) \(-0.05\)
  1. (2) Email A has 1 link and comes from a sender who is not in the contacts. Email B has 1 link and comes from a contact. Compute \(z\) and the probability of spam for each.
  2. (3) Interpret the coefficient 1 on links in one sentence. A colleague reads it as “each link makes spam 1 percentage point more likely.” Correct the colleague. How many links does a sender in the contacts offset?
  3. (2) For senders not in the contacts, compare the change in the probability of spam from 1 to 2 links with the change from 3 to 4 links. Both changes add 1 to \(z\). Why are the changes in probability different?
  4. (3) The rule “flag as spam when \(p\ge 0.5\)” made two mistakes. Email C, with 3 links from a sender not in the contacts, was a legitimate newsletter (\(y=0\)). Email D, with no links from a contact, was a scam sent from the contact’s hacked account (\(y=1\)). Compute the model’s probability of spam for each, and each log loss, \(-y\log p-(1-y)\log(1-p)\). The rule counts each as one error. Why does the log loss charge them differently?
  5. (2) For one email, write the probability of the observed outcome \(y\) as a function of \(p\). Explain why fitting the model by minimizing the total log loss over the training emails is maximum likelihood.

Review: study guide §9. Lab: in the Logistic Regression Lab, use Predict at a spread to read the win probability at spreads 0, 4, 8, 12, and 16. Each step of 4 points adds the same 0.62 to the log-odds, and the probability rises by less and less.

  1. A: \(z=-1+1(1)-2(0)=0\), so \(p=\sigma(0)=0.50\). B: \(z=-1+1(1)-2(1)=-2\), so \(p=\sigma(-2)=0.12\). Same links, and a known sender cuts the probability of spam from 50% to 12%.
  2. Holding the sender fixed, each additional link raises the log-odds of spam by 1. (Equivalently, each link multiplies the odds of spam by \(e\approx 2.7\).) It is not a change in probability: how much \(p\) moves depends on where the email starts on the S-curve, and \(p\) can never pass 1. A sender in the contacts lowers the log-odds by 2, the same as 2 fewer links, so it offsets 2 links.
  3. From 1 to 2 links, \(z\) goes from 0 to 1 and \(p\) from 0.50 to 0.73, up 0.23. From 3 to 4 links, \(z\) goes from 2 to 3 and \(p\) from 0.88 to 0.95, up 0.07. The change in log-odds is the same, but the sigmoid is steepest at \(z=0\), where \(p=0.5\), and flattens toward 0 and 1. A coefficient moves the log-odds by a fixed amount, not the probability.
  4. C: \(z=-1+3-0=2\), so \(p=0.88\). It was legitimate, \(y=0\), so the loss is \(-\log(1-p)\), and \(1-p=0.12=\sigma(-2)\): the loss is 2.1. D: \(z=-1+0-2=-3\), so \(p=0.05\). It was spam, \(y=1\), so the loss is \(-\log p=-\log\sigma(-3)=3.0\). Both are errors under the 0.5 rule, and a count of errors charges each one. The log loss charges D more because the model was more confident about D: it gave the true outcome only a 5% chance, against 12% for C. Log loss rewards probabilities that are honest about uncertainty and punishes confident mistakes.
  5. \(P(Y=y\mid p)=p^y(1-p)^{1-y}\), which is \(p\) if \(y=1\) and \(1-p\) if \(y=0\). Its negative log is \(-y\log p-(1-y)\log(1-p)\), the log loss. For independent emails the likelihood is the product of these probabilities, so the total log loss is minus the log-likelihood. Minimizing the total log loss maximizes the likelihood, just as least squares maximizes the likelihood under normal errors (Problem 5(h)).

How this is marked. In (b), “1 percentage point” or “100%” earns no credit; full credit needs log-odds and the offset of 2 links. “Each link multiplies the odds by \(e\)” is also correct.

Problem 7: Concepts (10 points)

Answer TRUE or FALSE and give a one-sentence justification. Each item is worth 1 point. An answer without a justification earns no credit. Where you need it, use the fact that for a standard normal \(Z\), \(P(-1.96\le Z\le 1.96)=0.95\).

  1. If the odds against \(A\) are 4 to 1, then \(P(A)=0.2\).
  2. If \(Cov(X,Y)=0\), then \(X\) and \(Y\) are independent.
  3. If \(X\) and \(Y\) are independent with \(Var(X)=4\) and \(Var(Y)=9\), then \(Var(X-Y)=-5\).
  4. If \(P(A)=0.3\), then \(P(A \text{ and } B)\le 0.3\).
  5. There is a 20% chance of rain tomorrow. A picnic goes ahead with probability 0.5 if it rains and with probability 0.9 if it does not. Then the probability that the picnic goes ahead is 0.82.
  6. If \(Var(X)=Var(Y)=4\) and the correlation between \(X\) and \(Y\) is \(0.5\), then \(Var(X+Y)=8\).
  7. A banner ad is clicked with probability 1/50 on each view, independently. If it is shown 50 times, it is certain to be clicked at least once.
  8. If \(X\sim N(\mu,\sigma^2)\), then \(P(\mu-1.96\,\sigma<X<\mu)=0.475\).
  9. If \(X\sim N(3, 4)\), then \(2X+1\sim N(7, 8)\). (Here \(N(\mu,\sigma^2)\).)
  10. If a least squares line has an intercept, its residuals sum to zero.

Review: study guide §10, then the section behind each item: (d) and (g) in §1; (a) and (e) in §3; (b), (c), and (f) in §4; (h) and (i) in §6; (j) in §7. Lab for (c) and (f): in the Portfolio Lab, move the correlation slider and watch the cross term in the variance of the mix change sign.

  1. TRUE. Odds against of 4 to 1 mean \(O(A)=(1-P(A))/P(A)=4\), so \(P(A)=1/(1+O(A))=1/5=0.2\).
  2. FALSE. Covariance measures only linear dependence. If \(X\) is \(-2,-1,1,2\) with probability \(1/4\) each and \(Y=|X|\), then \(Cov(X,Y)=E(X|X|)-E(X)E(|X|)=(-4-1+1+4)/4-0=0\), but \(Y\) is a function of \(X\).
  3. FALSE. Variances of independent terms add, even when you subtract: \(Var(X-Y)=Var(X)+Var(Y)=13\). A variance can never be negative.
  4. TRUE. “\(A\) and \(B\)” is contained in \(A\), so \(P(A\text{ and }B)\le P(A)=0.3\).
  5. TRUE. Law of total probability: \(P(\text{picnic})=0.5(0.2)+0.9(0.8)=0.10+0.72=0.82\).
  6. FALSE. \(Cov(X,Y)=\rho\,sd(X)\,sd(Y)=0.5(2)(2)=2\), so \(Var(X+Y)=4+4+2(2)=12\). The value 8 drops the covariance term, which is right only when the correlation is 0.
  7. FALSE. \(P(\text{at least one click})=1-(49/50)^{50}\), which is less than 1 because \((49/50)^{50}>0\). (It is about 0.64.) The expected number of clicks is \(50(1/50)=1\), but an expected count of 1 is not a guarantee.
  8. TRUE. \(P(\mu-1.96\sigma<X<\mu+1.96\sigma)=0.95\), and by symmetry half of it lies below \(\mu\): \(0.475\).
  9. FALSE. \(E(2X+1)=2(3)+1=7\), but \(Var(2X+1)=2^2(4)=16\): constants come out squared, and adding 1 does not change the spread. So \(2X+1\sim N(7,16)\).
  10. TRUE. With an intercept, least squares makes the residuals sum to zero: the line passes through \((\bar x,\bar y)\), and the residuals above and below it balance. You checked this in Problem 5(b).