Skip to content
Tutorials Center
My learning

Topics

Lesson 55 of 57 ยท Practice and Review

Practice Set: Regression, Bayes and Simulation

Ten practice problems on correlation, least squares, interpreting regression output, logistic odds, Bayesian updating, Monte Carlo and the bootstrap, with solutions.

The last practice set covers the modern end of the course: relationships between variables, Bayesian updating and computer-based methods. Work each problem by hand where a formula is given, and use code for the rest. The solutions are runnable; change the numbers and watch the answers move.

Part A: correlation and regression

Problem 1. For the data below (advertising spend x in thousands, sales y in units) compute the correlation, then fit the least-squares line and predict sales for x = 6.

x = 1, 2, 3, 4, 5, 7, 8 and y = 12, 15, 21, 22, 29, 35, 41

Problem 2. A regression output reports slope 2.8, standard error 0.7, with n = 27. Test whether the slope differs from zero and build a 95% CI.

Problem 3. A model of salary (in thousands) on years of experience and a binary degree (1 = holds degree) gives salary = 30 + 2.5ยทexperience + 8ยทdegree. Predict a 6-year person with a degree. Interpret the coefficient 8.

Problem 4. A logistic model gives log-odds โˆ’2 + 0.5ยทx. Find the probability at x = 4 and the odds ratio per unit of x.

Python Solutions for Part A

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Problem 3: holding experience fixed, people with a degree earn on average 8 thousand more than people without one. It is an association; self-selection and other confounders may play a role. Problem 4: at x = 4 the log-odds are exactly 0, so the probability is 0.5, and each extra unit of x multiplies the odds by about 1.65.

Part B: Bayesian reasoning

Problem 5. You believe a coin's chance of heads is Beta(2, 2). You see 9 heads in 12 flips. Give the posterior, its mean, and P(ฮธ > 0.5).

Problem 6. Two factories supply 60% and 40% of bulbs. Their defect rates are 2% and 5%. A bulb is found defective. What is the probability it came from the second factory?

Problem 7. A click-through rate has a Beta(1, 1) prior. Ad A gets 30 clicks in 300 views; ad B gets 45 in 320. What is the probability that B has the higher true rate?

Python Solutions for Part B

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In Problem 6 the second factory makes fewer bulbs but has the higher defect rate, so a defective bulb is more likely to be from it (62.5%) than its 40% share suggests. That shift from prior (40%) to posterior (62.5%) is Bayes' theorem in one line.

Part C: simulation and resampling

Problem 8. Estimate by simulation the probability that, in a family with 4 children (each equally likely a boy or girl), there are exactly 2 girls. Compare with the exact binomial value.

Problem 9. Waiting times (minutes) at a clinic: 12, 7, 25, 9, 14, 31, 8, 11, 19, 10. Use the bootstrap to get a 95% interval for the median waiting time.

Problem 10. Two groups: a = 5.1, 4.8, 6.0, 5.5, 5.2 and b = 6.1, 6.4, 5.9, 6.8, 6.3. Run a permutation test for the difference in means.

Python Solutions for Part C

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For a sample this small the bootstrap interval for the median is wide and discrete (it can only take a limited set of values built from the data): a reminder that very small samples carry little information, however clever the method.

Self-assessment

Score yourself honestly after the three practice sets in this chapter:

  • Could set up and solve without looking: the topic is solid.
  • Needed the solution for the first step: reread that lesson's key idea and redo the problem tomorrow.
  • Got the number but cannot explain it in words: that is the most common gap. Practice writing one-sentence interpretations.

Statistics is largely the skill of translating between a real question, a model, a number and a plain-language conclusion; each of the four steps deserves practice.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A regression slope has t = 4 with a large sample. What can you conclude?

    A t statistic of 4 means the slope is about four standard errors from zero, which is strong evidence against a zero slope. It does not establish causation.
  2. 2. Logistic log-odds equal 0 at some x. What is the probability?

    Log-odds of 0 correspond to odds of 1, so p = 1/(1+1) = 0.5.
  3. 3. Prior Beta(2, 2); data 9 heads and 3 tails. What is the posterior?

    Add 9 to alpha and 3 to beta: Beta(11, 5).
  4. 4. Why does a bootstrap interval for a median from only 10 observations look coarse?

    The resampled medians are built from a handful of data values, so the distribution is lumpy and uncertainty remains large.

Summary

  • Regression problems combine fitting (slope, intercept), inference (t, CI) and interpretation in context.
  • Logistic regression works on the log-odds scale; convert to probability with the sigmoid and read exp(ฮฒ) as an odds ratio.
  • Bayesian updating adds data to the prior; posterior simulation answers questions like P(B > A).
  • Simulation, bootstrap and permutation tests handle problems with no convenient formula, but they cannot create information that a tiny sample lacks.

Next: Statistics Formula Cheat Sheet