Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 37 ยท Projects and Practice

Mini-Project: Analyze a Dataset

Run a complete statistical analysis in Python: summary statistics, scatter plot, correlation, regression, confidence interval and a hypothesis test, then write a conclusion.

In this project you act as a data analyst. You will take a small dataset, explore it, model it, quantify uncertainty, test a claim, and report what you found, using every major tool from the second half of this track.

The data below are simulated, generated by a rule with random noise so that everyone gets the same numbers. They are not real measurements.

The scenario

A school runs a study with 40 students. For each, it records weekly study hours and the score on a final exam. The principal asks three questions:

  1. Is there a relationship between study time and score?
  2. What score would you predict for a student who studies 8 hours a week?
  3. The school's past mean score was 65. Is this year's mean different?

Step 1: Generate and summarize the data

Always begin by looking at the data and checking basic statistics.

Python Step 1: create the data and summarize it

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.

Step 2: Visualize and measure the relationship

Plot before computing. Then compute r and fit the regression line.

Python Step 2: scatter plot, correlation and regression line

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.

Describe what you see in words: direction, form, strength and outliers. Interpret the slope with units (points per extra hour), and note that 8 hours lies inside the observed range of 1 to 12, so it is interpolation.

Step 3: Check the model with residuals

Python Step 3: residual plot and sizes of errors

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.

Does the plot show a pattern or a funnel? If it looks random, the straight-line model is reasonable.

Step 4: A confidence interval and a hypothesis test

For question 3, test Hโ‚€: ฮผ = 65 against Hโ‚: ฮผ โ‰  65 and build a 95% interval. The sample is 40 students, so we use the t distribution with 39 degrees of freedom.

Python Step 4: confidence interval and t-test for the mean score

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.

With this seed the mean is 66.5, the interval (62.66, 70.34) contains 65, and the p-value is about 0.43, so there is no evidence that this year's mean differs from 65. The interval and the test always agree for a two-sided test at the matching level. Change the seed and see how often you would reach the opposite conclusion.

Step 5: Write the report

A good analysis ends with a short, honest write-up. A template:

Text
Question: ...
Data: 40 students (simulated), variables ...
Findings:
  - Relationship: r = ..., positive/strong/linear; each extra hour of study is associated with ... points.
  - Prediction: at 8 hours/week the model predicts about ... (typical error about ...).
  - Mean score: 95% CI (..., ...); test against 65 gives p = ... so ...
Limitations: observational data (association, not causation); simulated; extrapolation beyond 1-12 hours not supported.

Extend the project. Change the random seed and see how much the results move. Add an outlier and observe how r and the slope change. Increase the sample size to 400 and see how the interval narrows.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Why do we plot the data before calculating a correlation?

    r measures only linear association and is sensitive to outliers, so the picture is essential.
  2. 2. Our regression suggests more study hours go with higher scores. Can we say studying causes higher scores?

    Causation needs a controlled experiment or strong additional reasoning.
  3. 3. A 95% confidence interval for the mean is (66.1, 70.3). Testing Hโ‚€: ฮผ = 65 at the 5% level, you would...

    A two-sided 5% test rejects exactly when the hypothesized value lies outside the 95% interval.

Summary

  • A complete analysis: summarize, visualize, measure, model, check, quantify uncertainty, test, report.
  • Residual plots check the model; intervals and tests quantify uncertainty.
  • Report conclusions in context, with limitations.
  • Association does not prove causation.

Congratulations on finishing this part of the track. Return to the track overview to revisit any chapter.