Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Data Analysis with Python (pandas, polars, DuckDB)  Module 11 – Statistics an analyst uses every week

Correlation, trend lines and causation

Pearson and Spearman correlation in pandas, a trend line with numpy.polyfit, why one outlier changes both, and why correlation alone never shows a cause.

  • Intermediate
  • 25 minutes
  • Examples run with Python 3.14.8, pandas 3.0.6 and numpy 2.5.3
  • By MySmartCoPilot
Free core, Pro depth: 10 of 25 minutes free
Free: Values and ranks respond differently to one wrong row · A slope has units and an observed fitting range · The same rounded coefficient can hide different shapes · Association needs a design before it can identify a cause. With a pass: 2 in-depth parts and 3 interview answers, about 15 minutes.

What you will learn

  • Compute Pearson and Spearman correlations and know when each fits
  • Calculate and interpret a straight-line trend with numpy.polyfit
  • Explain confounding and why correlation is not causation
  • Use residuals to check whether a straight line is reasonable

Before you start

Correlation measures how closely two numeric columns move together, on a scale from −1 to 1. Pearson correlation: A dimensionless measure of linear association between paired varying measurements, on a scale from minus one to one. More in “Distributions, relationships and correlation charts” measures linear association. Spearman correlation: A coefficient of monotonic association obtained from paired ranks; unusual rank pairings can still affect it. applies it to ranks, measuring monotonic association; ranks limit an extreme value’s magnitude effect, but do not make it immune to unusual points. Trend lines add the size of the relationship: np.polyfit(x, y, 1) returns a slope in real units, such as 2.75 more marks for every extra hour of study. None of these numbers says why two columns move together. A third variable can drive both, which is why correlation is not causation, and why a plot comes before any coefficient. This lesson computes all three on invented data with pandas and NumPy, then shows where each one misleads.

Values and ranks respond differently to one wrong row

The data is invented: the hours 24 students studied in the week before a test, and their marks out of 100. A second run adds one row that a typing slip turned from 4.0 hours into 40.

Pearson and Spearman, with and without one slip Python · hours_marks.py
import pandas as pd

# Invented records of 24 students: hours of study in the week before a test, and the mark out of 100.
students = pd.DataFrame({
    "hours": [2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 17],
    "marks": [35, 42, 44, 38, 48, 49, 52, 52, 57, 48, 64, 64, 53, 64, 62, 53, 67, 63, 68, 66, 70, 76, 80, 76],
})
print("24 students")
print(students.corr(method="pearson").round(2).to_string())
print(f"spearman: {students['hours'].corr(students['marks'], method='spearman'):.2f}")

# One more row, typed as 40 hours instead of 4.0: a single data-entry slip.
slip = pd.concat([students, pd.DataFrame({"hours": [40], "marks": [41]})], ignore_index=True)
print("\nwith the slip (40 hours, 41 marks)")
for method in ("pearson", "spearman"):
    print(f"{method:<9} {slip['hours'].corr(slip['marks'], method=method):.2f}")
print("\nthe ranks Spearman correlates (last five rows):")
print(slip.rank().tail(5).to_string())
print(f"pearson of the ranks: {slip.rank().corr().iloc[0, 1]:.2f}")

Output

24 students
       hours  marks
hours   1.00   0.92
marks   0.92   1.00
spearman: 0.93

with the slip (40 hours, 41 marks)
pearson   0.24
spearman  0.74

the ranks Spearman correlates (last five rows):
    hours  marks
20   21.0   22.0
21   22.0   23.5
22   23.0   25.0
23   24.0   23.5
24   25.0    3.0
pearson of the ranks: 0.74

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 hours_marks.py

On the 24 original rows both correlations are high, 0.92 and 0.93: students who studied longer scored higher, and the pattern is close to a straight line. The slip changes the story. Pearson’s r falls to 0.24, because it weighs every point by its distance from the mean, and 40 hours is far from everything else. Spearman’s ρ falls only to 0.74. On ranks, the slip is just the student with the most hours and the third-lowest mark: one odd rank among 25, however extreme the value. The last line of the output confirms it: Pearson’s r of the ranks is Spearman’s ρ.

Pearson or Spearman
Criterion Pearson's rSpearman's ρ
Measures How close the points lie to a straight lineWhether y tends to rise or fall as x rises, in any shape
Computed on The valuesThe ranks of the values
One extreme value Can change it greatlyCan still change it
Curved but steadily rising data Below 1, though the pattern is perfect1 for a perfectly steady rise
In pandas df.corr() or df.corr(method="pearson")df.corr(method="spearman")

Use Pearson when the relationship looks straight and the data has no wild values, and Spearman for ranked data, skewed columns or curved but steady patterns. When the two disagree strongly, plot the data: the gap itself says that a few points or a curve are deciding the answer.

Follow the mistaken row through values and ranks:

Interactive · stage by stage One mistyped row changes both coefficients Follow the unchanged hours_marks.py data before and after the single-row slip.
One mistyped row changes both coefficients, step 3 of 3. Showing 24 students, Add 40-hour slip, Read ranks. In focus: Read ranks.24 studentsPearson 0.92; Spearman 0.93Add 40-hour slipPearson 0.24; Spearman 0.74Read rankshours 25; marks 3

The drawing shows the whole scene; its 3 steps are listed below.

Every step as text
  1. On the 24 invented original rows, Pearson rounds to 0.92 and Spearman to 0.93. Both summarize association rather than a cause.
  2. Adding the one mistaken 40-hour, 41-mark row changes Pearson to 0.24 and Spearman to 0.74. This is one erroneous observation, not a consistent conversion of all units.
  3. The slip is rank 25 for hours and rank 3 for marks. Ranks limit the effect of increasing the same extreme magnitude, but a discordant rank can still change Spearman substantially.

Checkpoint

Check: Values and ranks

  1. Question 1 of 2 What does Spearman compute before applying a Pearson-style coefficient?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: Ranks of the paired values

    Spearman measures monotonic association by correlating ranks. It does not automatically identify or delete errors.

  2. Question 2 of 2 One row is typed as 40 hours instead of 4.0. Does Spearman ignore it?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: No; its changed rank can affect the coefficient

    The actual example changes from 0.93 to 0.74, showing influence remains. Rank-based association is not an outlier-removal rule.

A slope has units and an observed fitting range

A correlation says how tight a relationship is; trend lines say how steep it is. np.polyfit(x, y, deg=1) fits the straight line with the smallest sum of squared vertical gaps and returns its coefficients, highest power first: the slope, then the intercept.

A trend line through the 24 students, and through the slip Python · trend_line.py
import numpy as np
import pandas as pd

students = pd.DataFrame({
    "hours": [2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 17],
    "marks": [35, 42, 44, 38, 48, 49, 52, 52, 57, 48, 64, 64, 53, 64, 62, 53, 67, 63, 68, 66, 70, 76, 80, 76],
})
slope, intercept = np.polyfit(students["hours"], students["marks"], deg=1)  # highest power first
print(f"marks = {intercept:.1f} + {slope:.2f} x hours")
print(f"each extra hour goes with {slope:.1f} more marks; 10 hours predict {intercept + slope * 10:.0f}")

residuals = students["marks"] - (intercept + slope * students["hours"])
print(f"residuals: mean {round(residuals.mean(), 2) + 0.0:.2f}, largest {residuals.abs().max():.1f} marks")
print(f"r squared: {students['hours'].corr(students['marks']) ** 2:.2f}")

# The same fit with the data-entry slip (40 hours, 41 marks) added.
hours = np.append(students["hours"], 40)
marks = np.append(students["marks"], 41)
slope_slip, intercept_slip = np.polyfit(hours, marks, deg=1)
print(f"with the slip: marks = {intercept_slip:.1f} + {slope_slip:.2f} x hours")

Output

marks = 35.0 + 2.75 x hours
each extra hour goes with 2.8 more marks; 10 hours predict 63
residuals: mean 0.00, largest 9.7 marks
r squared: 0.84
with the slip: marks = 53.4 + 0.40 x hours

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 trend_line.py

The rounded line is marks = 35.0 + 2.75 × hours, about 2.8 more marks per extra hour. At 10 hours the full-precision fit rounds to 63 marks; displayed coefficients give 62.5. A residual: An observed value minus its fitted prediction under a stated model, retaining the outcome’s units. is actual minus predicted mark; the largest absolute residual is 9.7. r², 0.84, is the share of the variation in marks that the line accounts for. The slip drags the slope down to 0.40, because a least-squares line, like Pearson’s r, gives an extreme point great weight. Read a slope only inside the range of the data, 2 to 17 hours here: for 40 hours the line would predict 145 marks on a test out of 100.

India-specific

Rent and property listings in Indian cities quote prices per square foot, so a trend line of monthly rent against area reads naturally as “₹20 more rent for every extra square foot”. Report the slope in those units, with the range of areas it was fitted on.

Linear Regression Calculator Paste two columns to get the least-squares line, R² and the residuals, with the working.

Compare interpolation with extrapolation:

Interactive · stage by stage A slope predicts inside the observed range Read the original polyfit coefficients and compare interpolation with the 40-hour extrapolation.
A slope predicts inside the observed range, step 3 of 3. Showing Fit coefficients, Predict 10 hours, Outside range. In focus: Outside range.Fit coefficientsslope 2.75; intercept 35.0Predict 10 hoursabout 63 marksOutside range40 hours predicts 145

The drawing shows the whole scene; its 3 steps are listed below.

Every step as text
  1. polyfit returns slope then intercept. The rounded fitted equation is 35.0+2.75×hours over the observed 2-to-17-hour range.
  2. At 10 hours the full-precision fitted line rounds to 63 marks. The displayed rounded coefficients give 62.5; their rounding explains the difference.
  3. At 40 hours it predicts 145 marks on a test out of 100, exposing the danger of extrapolating that straight line.

Checkpoint

Check: Slope, units and fit range

  1. Question 1 of 2 Which units does the study-hours trend slope carry?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: Marks per hour

    The slope converts a change in predictor hours into a fitted change in marks. A correlation is dimensionless; neither a slope nor a correlation is a causal probability.

  2. Question 2 of 2 The rounded line is marks=35+2.75×hours. What does it predict at 6 hours?

    Type a number.

    Show the answer: Question 2 of 2

    Answer: 51.5 marks (anything from 51.4 to 51.6 counts)

    35+2.75×6=51.5 marks within the observed range.

The same rounded coefficient can hide different shapes

Four scatter plots whose Pearson correlations round to 0.75: a noisy line, a bend, one far point and two groups.Four datasets, one correlation: r = 0.75A line with noisexyA curve that bends backxyOne far pointxyTwo separate groupsxy

Four datasets of 12 points each, with r rounded to 0.75 and their least-squares lines

Text description of the diagram

Each panel shows 12 points and its fitted dashed straight line. Pearson's correlation rounds to 0.75 in all four.

  1. A line with noise: the points scatter evenly around a rising straight line. Here the line describes the data well.
  2. A curve that bends back: the points rise steeply, level off and then fall. The straight line runs below the points in the middle and above them at both ends.
  3. One far point: eleven points form a cloud with little observed linear association. A point far to the right and higher up dominates the pooled coefficient.
  4. Two groups of six points: one cluster low on the left, the other higher on the right. Within each cluster there is little observed linear association; group separation dominates the pooled coefficient.

All four invented datasets have r rounded to 0.75, and the same coefficient tells four different stories, the point Francis Anscombe made in 1973 with four datasets of his own. Only the first is a straight line with noise. The second is a curve that rises and falls back, the third is a cloud with no trend plus one far point, and the fourth is two groups with no trend inside either. A coefficient cannot tell these apart; a scatter plot does it at a glance, and the residuals of a trend line do it in numbers. In pandas, students.plot.scatter(x="hours", y="marks") draws one with matplotlib.

Scatter Plot Maker Plot two columns with a trend line and its equation before you trust a correlation.

Compare what the matching number hides:

Interactive · stage by stage Four shapes share a rounded correlation Compare the original datasets behind the retained scatter plots rather than treating 0.75 as a complete description.
Four shapes share a rounded correlation, step 3 of 3. Showing Noisy line, Curve or far point, Two groups. In focus: Two groups.Noisy liner rounds to 0.75Curve or far pointr rounds to 0.75Two groupsr rounds to 0.75

The drawing shows the whole scene; its 3 steps are listed below.

Every step as text
  1. The noisy line has a Pearson coefficient that rounds to 0.75. The recorded output and scatter points show the shape the coefficient omits.
  2. A curve that bends back and a cloud plus one far point also round to 0.75. They require different diagnoses despite that matching display.
  3. The two-cluster dataset also rounds to 0.75. Plotting groups and the joint shape is necessary before interpreting a pooled line.

Key idea

Plot paired measurements before interpreting a coefficient.

Checkpoint

Check: Shape beyond a coefficient

  1. Question 1 of 2 Does Pearson 0.75 uniquely identify a noisy straight-line shape?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: No; several different shapes can produce it

    The retained four datasets demonstrate several shapes with the same rounded coefficient. Residual and group patterns are separate information.

  2. Question 2 of 2 A coefficient matches across a curve and two clusters. What should be examined next?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: The scatter shape and group structure

    Plots expose bends, unusual points and clusters that the coefficient compresses. More decimal places do not reconstruct the joint shape.

Association needs a design before it can identify a cause

Temperature drives both ice-cream sales and air-conditioner sales, so the two correlate strongly without either causing the other.The day's top temperaturehotter days,more cupshotter days,more unitsIce-cream cupssoldAir conditionerssoldstrong correlation,no cause either way

A confounder at work. Temperature drives both sales series

Text description of the diagram

Three boxes. At the top is the day's top temperature. Arrows lead from it to two boxes below: ice-cream cups sold, and air conditioners sold. Hotter days sell more of both.

A dashed line without arrowheads joins the two sales boxes. It stands for their strong correlation: on days when one shop sells many ice creams, the other sells many air conditioners. Neither causes the other; both follow the temperature, the confounder.

Two columns can correlate strongly without either one affecting the other. On hot days an ice-cream parlour sells more cups and an appliance shop sells more air conditioners, so over a summer the two sales series rise and fall together. Temperature is a confounder: A variable relevant to both an exposure and an outcome that can mix an observed association with a different causal explanation.: a third variable that drives both. Other routes to a correlation without the causation you might read into it:

  • Reverse causation: the effect runs the other way, as when extra classes go with low marks because struggling students are the ones sent to them.
  • Shared trends: two series that both grow over time correlate strongly, whatever they measure.
  • Selection: the rows were filtered on something related to both columns, which creates or hides a pattern.

Causation needs a design that rules these out, such as an A/B test with random assignment, or an analysis that holds the confounders fixed and says which ones it could not measure.

Trace how the proposed common cause affects both columns.

Interactive · stage by stage A shared cause drives two observed series Trace the retained temperature diagram; arrows and association represent different claims.
A shared cause drives two observed series, step 3 of 3. Showing Common driver, Two effects, Observed association. In focus: Observed association.Common drivertemperatureTwo effectsice cream and AC salesObserved associationdoes not isolate cause

The drawing shows the whole scene; its 3 steps are listed below.

Every step as text
  1. Temperature is the proposed common cause in the synthetic example. Its effect can reach both measured sales columns.
  2. Both ice-cream and air-conditioner sales respond to that driver, producing association without one sales series causing the other.
  3. A coefficient alone cannot choose among confounding, reverse direction, trends or selection. A causal interpretation needs a justified design and its assumptions.

Checkpoint

Check: Association and causes

  1. Question 1 of 2 Does a strong correlation by itself establish which column causes the other?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: No; several causal and selection explanations remain

    The coefficient summarizes association while the design must address causal alternatives. Its sign concerns co-movement, not direction of causation.

  2. Question 2 of 2 Two sales series both rise with temperature. What can their correlation alone establish?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Association in the observed sample

    A common driver can explain their co-movement. The observational coefficient does not identify an intervention effect.

Residuals and the four shapes, checked with numbers Pro: opens with a Pro, Premium or Ultimate pass

A trend line is only as good as the pattern it summarises, and residuals are how to check that pattern without looking. This part rebuilds the four datasets of the figure, computes the checks that tell them apart, and says what to do with each shape.

In this part:

  • Four rounded correlations match, while residuals differ
  • What to do with each shape, and the numbers that justify it
  • Why one row tilted the line: the slip’s share of the sums, worked out

3 diagrams · 1 runnable example (Python) · about 7 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

A correlation between two columns can come entirely from a third variable, from time itself or from the way the rows were chosen. All three are reproduced here in code that runs, with the checks that expose them, and an exercise asks you to judge three claims about a table of flats.

  • A hidden third variable reproduced: temperature behind two sales series
  • Shared growth reproduced: 1,000 unrelated pairs of trending series
  • Selection reproduced: a filter that creates a correlation
  • Your turn: three claims about 40 flats, checked with numbers

4 diagrams · 6 runnable examples (Python) · about 9 minutes

Opening this part with your pass…

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Practise: decide from the stated evidence

Practice that adapts to you

Practise this lesson

12 questions about 11 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 12 What does Spearman compute before applying a Pearson-style coefficient?

    Choose one answer.

    Show the answer: Question 1 of 12

    Answer: Ranks of the paired values

    Spearman measures monotonic association by correlating ranks. It does not automatically identify or delete errors.

  2. Question 2 of 12 Every study-hour value is consistently converted to minutes. What happens to its Pearson correlation with marks?

    Choose one answer.

    Show the answer: Question 2 of 12

    Answer: It stays the same under that positive linear unit conversion

    A positive affine rescaling preserves Pearson’s standardized association. Changing one erroneous row differs from consistently rescaling all observations.

  3. Question 3 of 12 Which units does the study-hours trend slope carry?

    Choose one answer.

    Show the answer: Question 3 of 12

    Answer: Marks per hour

    The slope converts a change in predictor hours into a fitted change in marks. A correlation is dimensionless; neither a slope nor a correlation is a causal probability.

  4. Question 4 of 12 Using the rounded line marks=35+2.75×hours, what is predicted at 8 hours?

    Type a number.

    Show the answer: Question 4 of 12

    Answer: 57 marks (anything from 56.9 to 57.1 counts)

    35+2.75×8=35+22=57 marks within the observed 2-to-17-hour range.

  5. Question 5 of 12 Does Pearson 0.75 uniquely identify a noisy straight-line shape?

    Choose one answer.

    Show the answer: Question 5 of 12

    Answer: No; several different shapes can produce it

    The retained four datasets demonstrate several shapes with the same rounded coefficient. Residual and group patterns are separate information.

  6. Question 6 of 12 Two datasets have the same rounded r, but one plot bends back and the other has two clusters. Which description is justified?

    Choose one answer.

    Show the answer: Question 6 of 12

    Answer: Their coefficient matches while their joint shapes differ

    The plot retains joint-shape information the scalar coefficient omits. A matching coefficient does not identify a unique model or causal mechanism.

  7. Question 7 of 12 Does a strong correlation by itself establish which column causes the other?

    Choose one answer.

    Show the answer: Question 7 of 12

    Answer: No; several causal and selection explanations remain

    The coefficient summarizes association while the design must address causal alternatives. Its sign concerns co-movement, not direction of causation.

  8. Question 8 of 12 Notifications and purchases correlate across cities. What design better tests whether extra notifications change purchases?

    Choose one answer.

    Show the answer: Question 8 of 12

    Answer: A valid randomized comparison with an outcome and stopping rule chosen in advance

    A justified experiment separates a treatment contrast from shared city characteristics. An observational coefficient alone does not identify the intervention effect.

  9. Question 9 of 12 One mistyped row (40 hours instead of 4.0) takes Pearson's r of hours and marks from 0.92 to 0.24. Why does Spearman's ρ fall much less, to 0.74?

    Choose one answer.

    Show the answer: Question 9 of 12

    Answer: Spearman works on ranks, so the row counts as one odd rank however extreme its value

    Spearman's ρ is Pearson's r computed on the ranks. The slip becomes rank 25 for hours and rank 3 for marks: a clear misfit, but only one rank among 25. On the original values, 40 hours lies far from every other point and pulls Pearson's r towards zero on its own.

  10. Question 10 of 12 np.polyfit(hours, marks, 1) returns approximately [2.75, 35.0]. What mark does the line predict for a student who studied 6 hours?

    Type a number.

    Show the answer: Question 10 of 12

    Answer: 51.5 marks (anything from 51.4 to 51.6 counts)

    polyfit returns the slope first and the intercept second, so the line is marks = 35.0 + 2.75 × hours, and 6 hours give 35.0 + 16.5 = 51.5. Six hours lies inside the data's range of 2 to 17 hours, so the prediction stays where the line was fitted.

  11. Question 11 of 12 Two columns have a Pearson correlation of 0.75. What can you conclude without plotting them?

    Choose one answer.

    Show the answer: Question 11 of 12

    Answer: Not the shape; a noisy line, a curve, one far point or two groups can all give 0.75

    The four datasets of the figure all have r rounded to 0.75, and only one of them is a straight line with noise. A coefficient summarises a shape it cannot show, so plot first. Even r² = 0.56 describes shared variation, not a share of causes.

  12. Question 12 of 12 Which mechanisms can create a systematic observational association without the proposed causal link? Choose every one.

    Choose every answer that is right.

    Show the answer: Question 12 of 12

    Answer:

    • Rows kept only when they meet a condition related to both columns
    • Both columns growing over the same months
    • A third variable that drives both, such as the temperature

    A common cause, a common time trend and selection can all create observational association. Random assignment balances other characteristics in expectation under a valid design; it still permits chance imbalance and does not supply causal conclusions without the design assumptions.

Interview questions

  1. Fresher to mid · Warm-up

    When would you use Spearman's correlation instead of Pearson's?

    Use Spearman when the relationship rises or falls steadily but not in a straight line, when the data are ranks or ordered categories, or when a few extreme values could dominate. Pearson's r measures how close the points lie to a straight line, so a single outlier or a curve can pull it far from what most of the data shows: in the lesson, one typing slip took it from 0.92 to 0.24. Spearman's ρ is Pearson's r computed on the ranks, so it asks only whether one column tends to rise with the other, and the same slip moved it only to 0.74. Pearson keeps its place when the relationship is straight and the values matter, for example before fitting a straight trend line. When the two disagree a lot, plot the data before reporting either.

  2. Fresher to mid

    Across 200 cities, the number of app notifications sent and the number of purchases correlate at 0.8. Marketing wants to double notifications everywhere. What do you check before agreeing, and what would you propose instead?

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  3. Mid to senior

    A trend line of monthly sales against advertising spend, fitted on 18 months, has a slope of 3.1. The finance head wants to triple the advertising budget and expects three times the extra sales. What do you tell them?

    Model answer, Pro. First step and follow-ups

  4. Fresher to mid

    Monthly active users and the average support response time have both risen for 30 months, and they correlate at 0.93. A manager concludes that growth is slowing support down. How do you test that claim?

    Model answer, Pro. First step and follow-ups

Key takeaways

  • Pearson measures linear association; Spearman measures monotonic association on ranks, while unusual points can affect both.
  • np.polyfit(x, y, 1) returns the slope and the intercept; report the slope in units, inside the range of the data.
  • Datasets with the same correlation can have very different shapes: plot first.
  • Correlation is not causation: confounders, reverse causation, shared trends and selection all create correlations.

Terms in this lesson

confounder
A variable relevant to both an exposure and an outcome that can mix an observed association with a different causal explanation.
residual
An observed value minus its fitted prediction under a stated model, retaining the outcome’s units.
Spearman correlation
A coefficient of monotonic association obtained from paired ranks; unusual rank pairings can still affect it.

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.