Probability and Statistics 201-SN1-RE • CEGEP, Montreal
Corrected exercises: linear regression and the chi-square test of independence (201-SN1-RE)
Here are ten corrected exercises on the relationship between two variables, element 4 of the CEGEP Probability and Statistics course 201-SN1-RE, preceded by twelve direct calculations.They cover the scatter plot, covariance, the linear correlation coefficient r, the least-squares regression line, the coefficient of determination r2, prediction by interpolation or extrapolation, influential points and residual analysis, then, for two qualitative variables, the contingency table, expected counts and the chi-square test of independence.
What the set covers, the traps it targets
They cover the scatter plot, covariance, the linear correlation coefficient r, the least-squares regression line, the coefficient of determination r2, prediction by interpolation or extrapolation, influential points and residual analysis, then, for two qualitative variables, the contingency table, expected counts and the chi-square test of independence.
As the course specification requires, the formulas are proved: the least-squares line and the fact that −1≤r≤1 (exercise 2), the invariance of r under a change of units (exercise 1), the product of the slopes of the two regression lines (exercise 3), the formula for expected counts (exercise 4), the P-value with two degrees of freedom by an integral (exercise 5) and the proportionality of the chi-square statistic to the sample size (exercise 7).
By the end, you can carry out a regression and a chi-square test on science data: the speed of sound, a spring, an absorbance calibration, hydrangeas and soil pH, common milkweed germination, climate and latitude, garter snakes, and a complete study of the salamanders of a forest (exercise 10). The pitfalls covered: reading r as a percentage (exercises 3 and 8), extrapolating outside the range (exercises 3, 6 and 10), judging a point on r alone (exercise 6), trusting r2 without looking at the residuals (exercise 9), testing a table whose expected counts are too small (exercise 7) and taking a failure to reject for a proof of independence (exercises 7 and 8).
The thread of the set: a measure of association answers the question of its own model, and no other. r and r2 measure alignment on a line, the chi-square statistic the departure from independence. We look at the data before the number, and we conclude without going beyond the study design or the measured range: the word “effect” is allowed only if the factor was assigned at random (exercise 5).
•WORKING SUMS: Sxx=∑(xi−x)2=∑xi2−n(∑xi)2, Sxy=∑(xi−x)(yi−y)=∑xiyi−n∑xi∑yi, and likewise Syy. Sample covariance: sxy=n−1Sxy, which depends on the units.
•LEAST-SQUARES LINE y^=ax+b: it minimizes ∑(yi−axi−b)2, the sum of the squared VERTICAL deviations; a=SxxSxy and b=y−ax, so it passes through (x,y). The sum of the residuals ei=yi−y^i is zero.
•CORRELATION: r=SxxSyySxy=sxsysxy, with no unit, between −1 and 1; it measures alignment on a line, nothing else. DETERMINATION: r2=1−SyySmin, the share of the variation in y explained by the linear relationship.
•PREDICTION: interpolation within the range of the observed x values; extrapolation beyond it, not guaranteed. A point far from x has high leverage: it can rotate the line without lowering r. Look at the scatter plot and the residuals before concluding.
•CHI-SQUARE TEST OF INDEPENDENCE: H0: the two qualitative variables are independent. Eij=nLiCj (L for the row total, C for the column total), χ2=∑E(O−E)2 computed on COUNTS, (ℓ−1)(c−1) degrees of freedom. Conditions: independent observations and every E≥5, otherwise combine neighbouring categories.
•CONCLUDING: reject H0 if χ2 exceeds the given critical value. A rejection establishes an association, a CAUSE only if the factor was assigned at random; a failure to reject does not prove independence. χ2 grows with n: it measures the evidence, not the strength of the relationship.
Calculations: working sums, the line, coefficients and chi-square
Exercise 0.1: Regression and chi-square: twelve direct calculations
12 answers to check
For each line, compute the requested quantity, without interpreting. Notation for the chapter: Sxy=∑(xi−x)(yi−y)=∑xiyi−n∑xi∑yi, Sxx=∑xi2−n(∑xi)2, least-squares line y^=ax+b with a=SxxSxy and b=y−ax, correlation coefficient r=SxxSyySxy, residual e=y−y^. For a contingency table, E=nL×C (L for the row total, C for the column total) and χ2=∑E(O−E)2.
a) n=6, ∑x=24, ∑y=90, ∑xy=402: compute Sxy.
b) n=5, ∑x=20, ∑x2=110: compute Sxx.
c) Sxy=42, Sxx=30, Syy=70: compute r.
d) r=−0.83: compute the coefficient of determination r2.
e) Sxy=−54, Sxx=36: compute the slope a.
f) a=2.4, x=5, y=18.5: compute the intercept b.
g) y^=0.36x+2.1: compute the predicted value for x=12.5.
h) y^=1.8x+4: compute the residual of the point (6,13.2).
i) Row total 60, column total 45, n=180: compute the expected count E of the cell.
j) O=22, E=15: compute the contribution E(O−E)2 of the cell.
k) Contingency table with 3 rows and 4 columns: give the number of degrees of freedom.
l) χ2=7.1 with 4 degrees of freedom, critical value 9.488 at the 5% significance level: what is the decision?
Show the solution
Answers
a)Sxy=42
b)Sxx=30
c)r≈0.917
d)r2≈0.689
e)a=−1.5
f)b=6.5
g)y^=6.6
h)e=−1.6
i)E=15
j)≈3.27
k)6 degrees of freedom
l)7.1<9.488: do not reject H0
a)
Sxy=402−624×90=402−360=42
b)
Sxx=110−5202=110−80=30
c)
r=30×7042=210042≈0.917
d)
r2=(−0.83)2=0.6889≈0.689
The sign disappears: the coefficient of determination does not give the direction of the relationship.
e)
a=36−54=−1.5
f)
b=18.5−2.4×5=6.5
The line passes through the mean point (5,18.5): that is exactly what this formula says.
g)
y^=0.36×12.5+2.1=4.5+2.1=6.6
h)
y^=1.8×6+4=14.8, so e=13.2−14.8=−1.6
The point lies below the line.
i)
E=18060×45=15
j)
15(22−15)2=1549≈3.27
k)
(3−1)(4−1)=6 degrees of freedom.
l)
7.1<9.488: the statistic does not fall in the critical region, so we do not reject H0.
We write: at the 5% level, the data do not allow us to conclude that there is a relationship. We do not write that the variables are independent.
Points are earned before the solution; after it, you can keep practising.
For you:
Tick the exercises you have done or want to review: a free account, no password, keeps your ticks and your right answers from one visit to the next, tells you which chapter to tackle next and lets you ask for the exercise you are missing. Create your space, an email is enough.
Part A: the basics (/50)
Exercise 1: Scatter plot, covariance and correlation coefficient: the speed of sound
11 answers to check
In the physics lab, the speed v of sound is measured in the air of a resonance tube, the air being brought in turn to six temperatures T. The measurements are rounded to the nearest metre per second.
The figure shows the scatter plot.
T (°C)
−10
0
10
15
25
30
v (m/s)
325
331
338
340
346
350
a) Describe the scatter plot: direction, form and strength of the relationship, and whether or not there is an isolated point.
b) Compute the means T and v, then the covariance sTv=n−11∑(Ti−T)(vi−v). State its unit.
c) Compute the standard deviations sT and sv, then the correlation coefficient r=sTsvsTv. Interpret it.
d) The units are changed: T′=αT+β and v′=γv+δ, with α>0 and γ>0. Prove that sT′v′=αγsTv and that the correlation coefficient is unchanged.
e) The temperature is now expressed in kelvins and the speed in kilometres per hour. Compute the new covariance and the new correlation coefficient.
f) Another team instead records the temperature as the gap below 30 °C, θ=30−T. What is the correlation coefficient between θ and v?
Show the solution
Answers
a)Increasing, linear, very strong, no isolated point
b)T≈11.67 °C, v≈338.33 m/s, sTv≈139.33 °C·m/s
c)sT≈15.06 °C, sv≈9.27 m/s, r≈0.9987: very strong increasing linear relationship
d)sT′v′=αγsTv, sT′=αsT, sv′=γsv, so r′=r
e)sT′v′≈501.6 K·km/h; r′≈0.9987
f)r≈−0.9987
a)
The points rise from left to right: the relationship is increasing.
They lie almost exactly on a line: the form is linear and the relationship very strong.
No point stands apart from the group, either horizontally or vertically.
This description is written BEFORE any calculation: it is what then justifies a linear correlation coefficient.
b)
T=670≈11.67 °C and v=62030≈338.33 m/s.
STv=∑Tivi−n∑Ti∑vi=24,380−670×2030≈696.67
sTv=5696.67≈139.33, in degrees Celsius metres per second.
The positive sign confirms the increasing direction. The value 139 says nothing about the strength of the relationship: it depends on the units, as question e shows.
Pitfall: dividing by n=6 gives 116.1. The question defines the sample covariance with n−1.
c)
sT=n−1STT=51133.33≈15.06 °C and sv=5429.33≈9.27 m/s.
r=15.06×9.27139.33≈0.9987
The coefficient is positive and very close to 1: the measurements lie almost perfectly on an increasing line.
It measures alignment, and only that: it does not say by how much the speed increases per degree; that is the role of the slope.
d)
Ti′−T′=α(Ti−T) and vi′−v′=γ(vi−v): the constants β and δ disappear from the deviations from the mean.
sT′v′=n−11∑α(Ti−T)γ(vi−v)=αγsTv
Likewise sT′=∣α∣sT=αsT and sv′=γsv, since α>0 and γ>0.
r′=αsTγsvαγsTv=r
The correlation coefficient has no unit: changing units does not change how the points are aligned.
e)
Kelvins: T′=T+273.15, so α=1. Kilometres per hour: v′=3.6v, so γ=3.6.
sT′v′=1×3.6×139.33≈501.6, in kelvin kilometres per hour.
r′=r≈0.9987
The covariance was multiplied by 3.6 although the relationship did not change: it therefore cannot be used to say whether a relationship is strong.
f)
θ=−T+30: this is a change of units with α=−1<0.
The proof in d then gives sθv=−sTv and sθ=∣−1∣sT=sT, hence r=−0.9987.
Pitfall: believing that the strength of the relationship has changed. Only the direction is reversed, because θ decreases when the temperature rises.
Points are earned before the solution; after it, you can keep practising.
For you:
Exercise 2: Proving the formulas of the least-squares line: the spring
7 answers to check
We have n points (xi,yi), the xi not all equal. For a line y=ax+b, the vertical deviation of point i is ei=yi−(axi+b), and we write S(a,b)=∑ei2. The least-squares line is the one that makes S(a,b) minimal. Notation: Sxx=∑(xi−x)2, Syy=∑(yi−y)2, Sxy=∑(xi−x)(yi−y) and r=SxxSyySxy.
Application: a spring is hung and its length L is measured under six forces F. The figure shows the scatter plot, an arbitrary line and its vertical deviations.
F (N)
0
1
2
3
4
5
L (cm)
12.0
14.1
15.9
18.2
19.8
22.0
a) Fix a. Show that S is a quadratic polynomial in b, minimal for b=y−ax. Deduce that the least-squares line passes through the mean point (x,y).
b) Show that with this choice of b, S=Syy−2aSxy+a2Sxx.
c) Deduce that S is minimal for a=SxxSxy, that this minimum equals Syy(1−r2), and then that −1≤r≤1.
d) Compute Sxx, Sxy, then the equation of the least-squares line of L as a function of F.
e) Interpret the slope and the intercept in the context of the spring, then deduce the spring constant k in N/m.
f) Compute Syy, then the minimum sum of squared deviations Syy(1−r2).
Show the solution
Answers
a)S is minimal for b=y−ax, so y=ax+b: the line passes through (x,y)
b)S=Syy−2aSxy+a2Sxx
c)a=SxxSxy, Smin=Syy(1−r2)≥0, so r2≤1
d)Sxx=17.5, Sxy=34.7; L^≈1.983F+12.04
e)Unstretched length ≈12.0 cm; 1.98 cm per newton; k≈50.4 N/m
f)Syy=68.9; Smin≈0.095 cm²
a)
Let ui=yi−axi, fixed numbers since a is fixed. Then S=∑(ui−b)2=nb2−2b∑ui+∑ui2.
This is a quadratic polynomial in b with leading coefficient n>0: its parabola opens upward, and its minimum is at the vertex.
dbdS=2nb−2∑ui=0⟺b=n∑ui=y−ax
With this b, ax+b=y: the mean point (x,y) is on the line, whatever a is, and therefore also on the optimal line.
b)
With b=y−ax, each deviation can be rewritten ei=(yi−y)−a(xi−x).
ei2=(yi−y)2−2a(xi−x)(yi−y)+a2(xi−x)2
Summing: S=Syy−2aSxy+a2Sxx.
c)
S is now a quadratic polynomial in a, with leading coefficient Sxx>0 (the xi are not all equal).
A sum of squares is positive or zero: Syy(1−r2)≥0, and Syy>0 as soon as the yi are not all equal, so r2≤1, that is, −1≤r≤1.
Better still: r=±1 exactly when Smin=0, that is, when all the points lie on the line. This is the proof that r measures ALIGNMENT.
It also shows why r2 is read as a proportion: 1−r2=SyySmin is the share of the variation in y that the line leaves unexplained.
d)
F=2.5 N and L=6102=17 cm.
Sxx=55−6152=17.5 and Sxy=289.7−615×102=34.7
a=17.534.7≈1.983 cm/N, then b=17−1.983×2.5≈12.04 cm.
L^≈1.983F+12.04
e)
The intercept is the predicted length with no force: the unstretched length of the spring, about 12.0 cm, in agreement with the measurement at 0 N.
The slope says that each additional newton stretches the spring by about 1.98 cm.
Hooke's law can be written L=L0+kF: the slope equals k1, so k=1.9831≈0.504 N/cm, or about 50.4 N/m.
This reading assumes that the spring stays within its elastic range, which the alignment of the six measurements makes plausible between 0 and 5 N, and only there.
Pitfall: taking the slope for the spring constant. Here L is on the vertical axis: the slope is the reciprocal of the spring constant, and it is in cm/N.
f)
Syy=1802.9−61022=68.9 and r=17.5×68.934.7≈0.99931.
Smin=68.9(1−r2)=68.9−17.534.72≈0.095 cm²
The same value comes from summing the squares of the six residuals, −0.043, 0.074, −0.109, 0.209, −0.174, 0.043: their sum is zero, as question a requires, and the sum of their squares is indeed 0.095.
No other line does better: the one in the figure, drawn by eye, gives a much larger sum.
Points are earned before the solution; after it, you can keep practising.
For you:
Exercise 3: Coefficient of determination, interpolation and extrapolation: an absorbance calibration
11 answers to check
To measure the iron content of drainage water from an old mine, the iron is converted into a red complex whose absorbance A is measured at 480 nm. Six standard solutions of known concentration c give the table below. We assume that, over this range, A is proportional to c up to a small offset (Beer-Lambert law, valid for dilute solutions).
The figure shows the standards and the absorbance of sample E.
c (mg/L)
0
2
4
6
8
10
A
0.003
0.098
0.204
0.297
0.399
0.505
a) Determine the least-squares line of A as a function of c.
b) Compute r and r2. Interpret r2 in one sentence.
c) Sample E has an absorbance of 0.352. Determine its iron concentration. Is this an interpolation or an extrapolation?
d) The raw, undiluted water gives A=1.72. Compute the concentration the line would give. Diluted five times, the same water gives A=0.398: deduce its concentration. Which of the two values should be kept?
e) A classmate instead computes the line of c as a function of A, c^=a′A+b′. Show that aa′=r2, compute a′ and compare it with a1.
Show the solution
Answers
a)A^≈0.05009c+0.0006
b)r≈0.99984, r2≈0.9997: the linear relationship explains 99.97% of the variation in A among the standards
c)cE≈7.02 mg/L, interpolation
d)Line: 34.3 mg/L, unreliable extrapolation; by dilution: 5×7.93≈39.7 mg/L, the value to keep
e)aa′=r2; a′≈19.96 versus a1≈19.97
a)
c=5 mg/L and A=61.506=0.251.
Scc=220−6302=70 and ScA=11.036−630×1.506=3.506
a=703.506≈0.05009 L/mg and b=0.251−0.05009×5≈0.0006.
A^≈0.05009c+0.0006
The intercept is almost zero, as proportionality predicts: the blank barely absorbs.
b)
SAA=0.553664−61.5062≈0.17566, so r=70×0.175663.506≈0.99984 and r2≈0.9997.
Interpretation: between 0 and 10 mg/L, the linear relationship with the concentration explains 99.97% of the variation in the absorbance of the standards; the remaining 0.03% comes from measurement error.
Pitfall: reading r=0.99984 as a percentage. It is r2, the proportion 1−SAASmin proved in exercise 2, that is read as a percentage.
c)
Invert the line: cE=0.050090.352−0.0006≈7.02 mg/L.
7.02 lies between 0 and 10, the limits of the calibration range: this is an interpolation, the only kind of prediction the standards guarantee.
d)
A=1.72 is far above the absorbance of the strongest standard, 0.505. The line would give c=0.050091.72−0.0006≈34.3 mg/L: this is an extrapolation.
Nothing in the standards says that proportionality holds beyond 10 mg/L. At high absorbances, the Beer-Lambert law often stops holding and the instrument measures poorly.
The diluted solution, on the other hand, falls within the range: c=0.050090.398−0.0006≈7.93 mg/L, so the raw water contains 5×7.93≈39.7 mg/L.
We keep 39.7 mg/L. The gap with 34.3 mg/L, about 14%, shows what the extrapolation would have cost: the actual response bends beyond the range, and the extended line underestimates the concentration.
Pitfall: believing that an r² of 0.9997 guarantees the line everywhere. It judges the alignment of the measured points, and of those points only.
e)
The two slopes are a=SccScA and a′=SAAScA.
aa′=SccSAAScA2=r2
a′=0.175663.506≈19.96 mg/L per unit of absorbance, versus a1≈19.97.
The two lines coincide only if r2=1. The line of y on x minimizes the VERTICAL deviations, the line of x on y the horizontal ones: they are not the same deviations.
For a calibration, we regress A on c and then invert: the concentrations of the standards are known precisely and the error lies in the measured absorbance. Here r2 is so close to 1 that both methods give 7.02 mg/L for E.
Points are earned before the solution; after it, you can keep practising.
For you:
Exercise 4: Contingency table and expected counts: the colour of hydrangeas
11 answers to check
A horticultural society records, in 200 gardens, the flower colour of a hydrangea (blue, purple or pink) and the soil type, classified by its pH: acidic (pH below 6), neutral (pH from 6 to 7) or alkaline (pH above 7). One hydrangea is recorded per garden.
The critical value of the chi-square distribution with 4 degrees of freedom at the 1% significance level is given: 13.277.
Colour \ soil
acidic
neutral
alkaline
Total
blue
38
14
6
58
purple
12
20
10
42
pink
10
26
64
100
Total
60
60
80
200
a) State the population, the two variables studied and their type.
b) Compute the percentage of blue flowers among the hydrangeas in acidic soil, in alkaline soil, then overall. What does the comparison suggest?
c) Let Li be the total of row i, Cj that of column j and n the overall total. Prove that, if colour and soil were independent, the expected count in cell (i,j) would be Eij=nLiCj.
d) Compute the expected counts of the cells (blue, acidic), (purple, neutral) and (pink, alkaline). Check that all the expected counts in the table are at least 5.
e) Show that, in each row, the expected counts have the same total as the observed counts. Deduce the number of cells that can be filled in freely, that is, the number of degrees of freedom.
f) Compute χ2, then conclude at the 1% level. Name the three cells that contribute the most.
Show the solution
Answers
a)Population: the hydrangeas of the 200 gardens; colour and soil type, two qualitative variables (soil type is ordinal)
b)63.3% in acidic soil, 7.5% in alkaline soil, 29.0% overall: the profiles differ clearly
c)Independence: P(Ai∩Bj)=P(Ai)P(Bj), estimated by nLi⋅nCj, hence Eij=n⋅nLi⋅nCj=nLiCj
The population is that of the hydrangeas in the gardens studied; the statistical unit is one hydrangea, one per garden.
The two variables, flower colour and soil type, are qualitative. Soil type is even ordinal, since its three classes follow the order of the pH values.
It is the qualitative nature of both variables that calls for a contingency table and a chi-square test, not a regression line.
b)
Acidic soil: 6038≈63.3% blue flowers. Alkaline soil: 806=7.5%. Overall: 20058=29.0%.
We compare percentages computed within each column, called profiles: the raw counts cannot be compared, since the columns do not have the same total.
If colour did not depend on soil, each column would have roughly the overall profile, 29% blue flowers. The gap between 63.3% and 7.5% suggests a relationship, which remains to be tested.
Pitfall: dividing 38 by 58, the row total. That gives the share of blue flowers that grow in acidic soil, a different question.
c)
Choose a hydrangea at random. Let Ai be the event “its colour is in row i” and Bj the event “its soil is in column j”.
The observed frequencies estimate P(Ai)≈nLi and P(Bj)≈nCj.
If the variables are independent, P(Ai∩Bj)=P(Ai)P(Bj)≈nLi⋅nCj.
Out of n hydrangeas, the expected count in the cell is therefore Eij=n⋅nLi⋅nCj=nLiCj.
d)
Eblue, acidic=20058×60=17.4, Epurple, neutral=20042×60=12.6 and Epink, alkaline=200100×80=40.
The smallest expected count is the one for the row and the columns with the smallest totals: 20042×60=12.6, shared by (purple, acidic) and (purple, neutral).
They are all at least 5: the condition for applying the test is met.
An expected count need not be a whole number: it is an expected average, not a count of hydrangeas.
e)
∑jEij=nLi∑jCj=nLi×n=Li: each expected row has the observed total. The same holds for each column.
Since the totals are fixed, it is enough to choose the cells of a sub-table with 2 rows and 2 columns: the last cell of each row and of each column follows.
The number of degrees of freedom is therefore (3−1)(3−1)=4.
f)
The nine contributions E(O−E)2 are, row by row: 24.39, 0.66, 12.75; then 0.03, 4.35, 2.75; then 13.33, 0.53, 14.40.
χ2≈73.20, far beyond the critical value 13.277: the hypothesis of independence is rejected at the 1% level.
The largest contributions come from (blue, acidic), 24.39, where 38 flowers are observed for 17.4 expected, from (pink, alkaline), 14.40, with 64 for 40, and from (pink, acidic), 13.33, with 10 for 30.
Conclusion: in these gardens, hydrangea colour is related to soil type; blue flowers dominate in acidic soil, pink ones in alkaline soil.
This is an observational survey: the test establishes the association, not its mechanism. The role of the soil is known from other sources, since soil aluminium is more available in acidic conditions, but other gardening practices could also follow the soil type.
Points are earned before the solution; after it, you can keep practising.
For you:
Exercise 5: The chi-square test of independence from start to finish: treatment and germination
10 answers to check
To restore a meadow suitable for the monarch butterfly, a laboratory wants to germinate common milkweed seeds. It assigns 150 seeds AT RANDOM to three treatments of 50 seeds each: no treatment (control), 30 days at 4 °C (cold), or a light abrasion of the seed coat (scarified). After 21 days, it counts the germinated seeds.
Critical values of the chi-square distribution with 2 degrees of freedom: 5.991 at the 5% level and 9.210 at the 1% level. For 2 degrees of freedom, the density of the chi-square distribution is f(x)=21e−x/2 for x≥0. The figure shows this density and the critical region at the 5% level.
Outcome \ treatment
control
cold
scarified
Total
germinated
22
38
30
90
not germinated
28
12
20
60
Total
50
50
50
150
a) State the null hypothesis H0 and the alternative hypothesis H1 in context.
b) Compute the six expected counts and check the condition for applying the test.
c) Compute the statistic χ2 and the number of degrees of freedom.
d) Conclude at the 5% level, then at the 1% level.
e) Prove that, for 2 degrees of freedom, P(χ2>c)=e−c/2. Check the critical value 5.991, then compute the P-value of the test.
f) Which cells contribute the most to χ2? Can we conclude that cold INCREASES germination? And that scarification has no effect?
Show the solution
Answers
a)H0: germination is independent of the treatment; H1: it depends on it
b)30 for each “germinated” cell, 20 for each “not germinated” cell; all ≥5
c)χ2=332≈10.67; 2 degrees of freedom
d)10.67>5.991 and 10.67>9.210: H0 is rejected at both levels
f)(not germinated, cold) and (not germinated, control), 3.20 each; yes to an effect of the treatment, since the trial is randomized; nothing is established for scarification alone
a)
H0: the outcome, germinated or not, is independent of the treatment; the proportion of seeds that germinate is the same under all three treatments.
H1: the outcome depends on the treatment; at least one treatment has a different germination proportion.
The chi-square test is global: its alternative says neither which treatment differs nor in which direction.
b)
Egerminated=15090×50=30 in each column, and Enot germinated=15060×50=20.
The six expected counts are all at least 5: the condition for applying the test is met.
We also check that each seed is counted only once and that the seeds respond independently of one another, which we assume here.
c)
The deviations O−E are −8, +8, 0 in the “germinated” row and +8, −8, 0 in the other.
χ2=3064+3064+0+2064+2064+0=332≈10.67
Degrees of freedom: (2−1)(3−1)=2.
d)
10.67>5.991: the statistic falls in the critical region, so H0 is rejected at the 5% level.
10.67>9.210: it is also rejected at the 1% level.
Conclusion: at the 1% level, the germination of common milkweed depends on the treatment received.
e)
P(χ2>c)=∫c+∞21e−x/2dx=M→+∞lim[−e−x/2]cM=e−c/2
e−5.991/2≈0.0500: this indeed gives back the 5% level.
P-value: p=P(χ2>10.67)=e−16/3≈0.0048.
If the treatment had no effect, a deviation at least this large would appear only about 5 times in 1000. Since p<0.01, we recover the decision of d.
Only the distribution with 2 degrees of freedom gives such a simple formula: for the others, we read a table or integrate numerically.
f)
The contributions are 2.13, 2.13, 0, then 3.20, 3.20, 0. The largest, 3.20, are (not germinated, cold), with 12 seeds for 20 expected, and (not germinated, control), with 28 for 20.
Cold gives 5038=76% germination versus 5022=44% for the control.
The seeds were assigned at random: apart from the treatment, nothing distinguishes the three batches except chance, which the test has just made an unlikely explanation. The relationship shown can therefore be interpreted as an effect of the treatment, under the conditions of this trial.
Scarification, with 60% germination, contributes 0. This does not prove that it has no effect: the global test was not designed to compare two treatments with each other, and not observing a difference is not proving the absence of an effect.
Pitfall: writing that a dependence proves a cause in any study. Here it is the random assignment that allows the word “effect”.
Points are earned before the solution; after it, you can keep practising.
For you:
Part B: problems and reasoning (/50)
Exercise 6: Outlier and influential point: latitude and temperature
13 answers to check
A climatology study records the mean annual temperature T of seven lowland stations (elevation below 200 m), spaced from south to north along the east coast of North America, as a function of their latitude x. The values are fictitious but plausible.
Two more stations are then proposed: M, a mountaintop station at 42 °N, at an elevation of about 2300 m, where T=−5 °C; P, a coastal Arctic station at 74 °N, where T=−10 °C. The figure shows the seven lowland stations and the points M and P, as open circles.
Latitude (°N)
30
34
38
41
45
48
52
T (°C)
21.0
16.5
14.0
10.5
7.5
3.5
1.5
a) For the seven lowland stations, compute the slope a and the intercept b of the least-squares line of T as a function of x, and the coefficient r.
b) M is added to the seven stations. Recompute r and the slope. Compare.
c) P is added to the seven stations, without M. Recompute r and the slope. Compare.
d) The slope can be written a=∑wixi−xyi−y with wi=Sxx(xi−x)2 for xi=x. Verify this expression, then compute the weight w of P in case c and that of M in case b. Explain why P weighs on the slope and M hardly at all.
e) Should M be removed from the study? And P? Justify each decision.
f) Using the line of the seven lowland stations, predict the mean temperature at 60 °N. Is this prediction reliable?
Show the solution
Answers
a)a≈−0.899 °C per degree, b≈47.65 °C, r≈−0.9962
b)With M: r≈−0.786, slope ≈−0.930: r drops, the slope barely moves
c)With P: r≈−0.984, slope ≈−0.704: r stays high, the slope changes by 22%
d)wP≈63.1%, wM≈0.15%: the weight grows as the square of the distance from x
e)M: set aside and reported, because its elevation places it in another population; P: the line is not extended to it, it is studied separately
f)T^≈−6.3 °C; extrapolation beyond 52 °N, not guaranteed
a=364.86−328.14≈−0.899 °C per degree of latitude, b=10.64+0.899×41.14≈47.65 °C.
r=364.86×297.36−328.14≈−0.9962: very strong decreasing linear relationship.
In the lowlands, the temperature drops on average by 0.9 °C per degree of latitude northward, over the observed range from 30 to 52 °N.
b)
With M, over eight stations: x=41.25, Sxx=365.5, SxT≈−339.88, STT≈511.47.
r≈−0.786 and the slope is ≈−0.930.
The coefficient collapses, r2 dropping from 0.992 to 0.618: M is an outlier, far below the line, about 15 °C colder than predicted for its latitude.
But the slope changes by only 3%: M lies in the middle of the latitudes, so it pulls the scatter plot down without rotating it.
c)
With P, over eight stations: x=45.25, Sxx=1309.5, SxT≈−921.63, STT≈670.22.
r≈−0.984 and the slope is ≈−0.704.
The coefficient stays very strong, but the slope goes from −0.899 to −0.704, that is, 22% less: a single point out of eight has rotated the line.
P is an influential point. Its temperature, −10 °C, is about 9 °C above what the lowland line predicts, −18.9 °C.
Pitfall: judging the effect of a point on r alone. The coefficient does not see that a line has rotated.
d)
wixi−xyi−y=Sxx(xi−x)(yi−y): the sum gives back SxxSxy=a, and a point with abscissa x contributes nothing.
The slope is therefore a weighted average of the slopes joining each point to the mean point, and the weights wi add up to 1.
For P: wP=1309.5(74−45.25)2≈0.631, that is, 63.1% of all the weight, on its own.
For M: wM=365.5(42−41.25)2≈0.0015, that is, 0.15%.
The weight of a point grows as the SQUARE of its distance from the mean of the x values: this is the leverage effect. A point far away in x decides the slope; a point in the centre hardly affects it, even when it is very far away in y.
e)
M: the mountaintop station does not belong to the population studied, the lowland stations. Its deviation is explained by a third variable, elevation: the temperature drops by several degrees per kilometre of altitude.
We therefore set it aside from this regression, SAYING so in the report and defining the population (elevation below 200 m). A point is never removed without saying which one and why.
P: the Arctic station does belong to the population, but it lies outside the range of latitudes over which the linear relationship was established. Its deviation suggests that the relationship changes beyond that range, under the influence of other factors such as the ocean.
We therefore do not extend the line to it: we present the line for 30 to 52 °N, and we point out that Arctic regions call for a separate study, with more stations.
In both cases, the decision comes from knowledge of the phenomenon, not from the wish to improve r.
f)
T^=−0.899×60+47.65≈−6.3 °C
60 °N lies outside the observed range, from 30 to 52 °N: this is an extrapolation.
Station P has just shown that the lowland relationship does not carry on unchanged toward the north. The value −6.3 °C is only an indication, to be confirmed by measurements.
Points are earned before the solution; after it, you can keep practising.
For you:
Exercise 7: The expected count condition and the effect of sample size: blood group and treatment
9 answers to check
An observational study follows 120 patients treated with an experimental antiviral drug (fictitious). For each patient, the blood group and the response to treatment after two weeks, favourable or not, are recorded. The researchers obviously did not assign the patients to blood groups.
For 2 degrees of freedom: critical value 5.991 at the 5% level, and P(χ2>c)=e−c/2.
Group \ response
favourable
not favourable
Total
O
30
24
54
A
31
15
46
B
7
7
14
AB
4
2
6
Total
72
48
120
a) Compute the expected counts of row AB. Can the chi-square test be applied to the table as it stands?
b) Groups B and AB are combined into a single row. Justify this grouping, write the new table and give its number of degrees of freedom.
c) Compute χ2 for the combined table and conclude at the 5% level.
d) Write the conclusion in context.
e) Prove that, if all the observed counts are multiplied by the same number k>0, the statistic χ2 is multiplied by k.
f) A study of 480 patients finds EXACTLY the same proportions in the combined table. Compute its χ2 and its P-value, and conclude. Is the relationship stronger than in the study of 120 patients?
Show the solution
Answers
a)3.6 and 2.4, below 5: test not applicable as it stands
b)B and AB both carry the B antigen; rows O, A, B or AB; (3−1)(2−1)=2 degrees of freedom
c)χ2≈1.70<5.991: do not reject H0
d)At the 5% level, these data do not show a relationship between blood group and response; they do not prove independence
e)O and E are multiplied by k, and so is each term E(O−E)2
f)χ2≈6.80>5.991, p≈0.033: rejection; same relationship, more evidence
a)
EAB, favourable=1206×72=3.6 and EAB, not favourable=1206×48=2.4.
These two expected counts are below 5: the condition for applying the test is not met, and the test cannot be applied to the table as it stands.
The reason: the statistic χ2 follows the chi-square distribution only APPROXIMATELY, and the approximation deteriorates when the expected counts are small. A small E in the denominator also inflates a contribution at the slightest deviation.
b)
Groups B and AB have in common that they carry the B antigen: combining them makes biological sense. A grouping is decided on the meaning of the categories, ideally before seeing the results, never in order to obtain a rejection.
New table: O, 30 and 24; A, 31 and 15; B or AB, 11 and 9, for a total of 20.
Expected counts: 32.4 and 21.6; 27.6 and 18.4; 12 and 8. They are all at least 5.
Degrees of freedom: (3−1)(2−1)=2. Combining has cost one degree of freedom, and part of the information about group AB.
χ2≈1.70, less than 5.991: H0 is not rejected at the 5% level.
P-value: e−1.70/2≈0.43. A deviation at least this large would appear nearly one time in two with no relationship at all.
d)
“At the 5% level, the data from these 120 patients do not allow us to conclude that there is a relationship between blood group and response to treatment.”
We do not write “blood group has no influence”: a weak relationship may exist and remain invisible with 120 patients. Not rejecting H0 means lacking evidence, not proving independence.
Pitfall: treating a failure to reject as a proof of the null hypothesis. Question f shows what happens with more patients.
e)
The new totals are kLi, kCj and kn, so Eij′=knkLikCj=kEij.
Summing, χ′2=kχ2. The degrees of freedom do not change, since the table keeps its dimensions.
f)
480=4×120: by e, χ2=4×1.70≈6.80.
6.80>5.991: H0 is rejected at the 5% level, with a P-value of e−6.80/2≈0.033.
The relationship is not stronger: the proportions are identical, for example 56% favourable responses among group O patients in both studies. What has changed is the amount of evidence: with 480 patients, the same deviation can no longer reasonably be explained by chance.
The chi-square test judges the EXISTENCE of a relationship, not its strength. To describe the strength, we compare the profiles: 4631≈67% favourable responses in group A versus 5430≈56% in group O.
Even when significant, this relationship remains observed, not produced by an intervention: blood group could be associated with another characteristic of the patients that does influence the response.
Points are earned before the solution; after it, you can keep practising.
For you:
Exercise 8: Five statements to correct
6 answers to check
Each of the following five statements, taken from lab reports, is false. For each one, choose the right correction, then explain the error in one or two sentences. Two points per statement.
a) “For the seven lowland stations of exercise 6, r=−0.996: latitude explains 99.6% of the temperature differences between these stations.”
b) “Between 10 and 60 °C, the activity of an enzyme and the temperature give r=0.01: temperature has no effect on this enzyme.”
c) “In exercise 7, the chi-square test on 120 patients does not reject H0 at the 5% level: blood group and response to treatment are therefore independent.”
d) “To save time, we apply the chi-square test to the percentages of the germination table of exercise 5 rather than to its counts: the conclusion is the same.”
e) “The spring of exercise 2 follows L^=1.983F+12.04 with r2=0.9986: under a force of 40 N, it will be 91.4 cm long.”
Show the solution
Answers
a)r2≈0.992: 99.2% of the variation in T is explained by the linear relationship with latitude
b)Bell-shaped relationship, very strong but nonlinear: r does not see it
c)Do not reject H0: no relationship shown, which does not prove independence
d)On the percentages of the total, χ2=10.67×150100≈7.11: the test is done only on counts
e)Extrapolation from 5 to 40 N: outside the range over which the spring was studied
a)
It is the coefficient of determination that is read as a percentage: r2=(−0.9962)2≈0.992.
Correction: “the linear relationship with latitude explains about 99.2% of the variation in mean temperature among these seven stations”.
“Explains” is meant in the statistical sense, a share of variance, and only for the lowland stations from 30 to 52 °N.
b)
r measures how well the points align on a LINE. The activity of an enzyme rises up to an optimal temperature and then drops: the scatter plot forms a bell, and its two halves cancel each other out in r.
Here, with the six measurements shown in the solution, r≈0.01 even though temperature takes the activity from 6 to 49: the relationship is strong, it is just not linear.
Correction: “r is almost zero: there is no LINEAR relationship; the scatter plot shows a bell-shaped relationship, with an optimum around 35 °C”.
Always look at the scatter plot before computing r.
c)
Not rejecting H0 means that the observed deviation remains compatible with chance, for these 120 patients.
Exercise 7 shows that with the same proportions over 480 patients, the test rejects H0: a weak relationship can escape a small sample.
Correction: “at the 5% level, these data do not allow us to conclude that there is a relationship”.
d)
The table in percentages of the total amounts to a sample of 100 seeds instead of 150.
By exercise 7, multiplying the counts by 150100 multiplies χ2 by 150100: 10.67×32≈7.11 instead of 10.67.
Here both values exceed 5.991, but with 1000 individuals, switching to percentages would divide χ2 by 10 and could reverse the decision.
Correction: “the chi-square test is always done on the observed counts; percentages are used to describe the profiles”.
e)
The calculation is right: 1.983×40+12.04≈91.4 cm. It is the prediction that is not.
The spring was studied from 0 to 5 N; 40 N is eight times the heaviest load measured. Beyond its elastic limit, a spring is permanently deformed and Hooke's law no longer applies.
Correction: “the line describes the spring between 0 and 5 N; under 40 N, we must measure, or know the elastic limit given by the manufacturer”.
An r² very close to 1 judges the alignment of the measured points, never what happens beyond them.
Statement b: six activity measurements, bell-shaped around an optimum near 35 °C; the relationship is very strong, and yet r≈0.01.
Points are earned before the solution; after it, you can keep practising.
For you:
Exercise 9: Problem: when the line does not fit, the mass and length of garter snakes
13 answers to check
A herpetology team captures six common garter snakes from the same population and measures their total length L and their mass m. The data are fictitious but plausible.
The figure shows the scatter plot.
L (cm)
30
40
50
60
70
80
m (g)
11
27
53
90
145
214
a) Compute the least-squares line of m as a function of L, as well as r2.
b) Compute the six residuals. Describe the sequence of their signs and say what it reveals about the linear model.
c) Consider the model m=kLp. Show that it becomes linear by setting X=lnL and Y=lnm, then compute the least-squares line of Y as a function of X and its coefficient r.
d) Deduce p and k, then predict the mass of a 65 cm garter snake with each of the two models.
e) Interpret the value of p: what would happen to the mass if the snake kept exactly the same shape as it grew?
Show the solution
Answers
a)m^≈4.017L−130.94; r2≈0.942
b)21.4; −2.7; −16.9; −20.1; −5.3; 23.6: positive at the ends, negative in the middle; linear model unsuitable
c)Y=pX+lnk; Y^≈3.021X−7.862, r≈0.99994
d)p≈3.02, k≈3.85×10−4; at 65 cm: 115 g (power) versus 130 g (line)
e)Shape preserved: m∝L3; p≈3 is consistent with growth that preserves shape
a)
L=55 cm and m=90 g; SLL=19,900−63302=1750 and SLm=36,730−6330×540=7030.
a=17507030≈4.017 g/cm and b=90−4.017×55≈−130.94 g, so m^≈4.017L−130.94.
Smm=78,580−65402=29,980, hence r=1750×29,9807030≈0.971 and r2≈0.942.
The coefficient is high; it does not yet justify anything. The line predicts 4.017×30−130.94≈−10.4 g for the smallest snake MEASURED, a negative mass: it gives m^<0 as soon as L<32.6 cm.
b)
Residuals e=m−m^, in order of length: 21.4, −2.7, −16.9, −20.1, −5.3, 23.6 g.
Their sum is zero, as for any least-squares line; it is their ORDER that speaks: positive at both ends, negative in the middle.
This U pattern, visible on the residual plot, says that the scatter plot is curved: the line passes below the points at the ends and above those in the middle.
The linear model is not appropriate, despite r² = 0.942.
Pitfall: judging a model on r² alone. A clearly curved scatter plot can give a high r²; only the scatter plot and the residuals show the shape.
c)
lnm=lnk+plnL, that is, Y=pX+lnk: a linear relationship between X and Y, with slope p and intercept lnk.
SXX≈0.66727 and SXY≈2.01580, so the slope is ≈3.021 and the intercept Y−3.021X≈−7.862.
r≈0.99994: the transformed points are aligned, and the residuals of this line no longer show any pattern.
d)
p≈3.02 and k=e−7.862≈3.85×10−4, in grams for L in centimetres: m≈3.85×10−4L3.02.
At 65 cm: power model, 3.85×10−4×653.02≈115 g; line, 4.017×65−130.94≈130 g.
Both predictions are interpolations, but the line overestimates: between 60 and 70 cm, its residuals are negative, so it passes above the points.
Pitfall: predicting with rounded values of the transformed slope and intercept. Keep all the decimals until k is computed.
e)
If the shape were preserved, all the lengths of the body would be multiplied by the same factor λ, the volume by λ3, and so would the mass, the density being roughly constant: m∝L3.
The slope obtained, p≈3.02, is very close to 3: the data are consistent with growth that preserves shape, called isometric growth.
With six snakes, we cannot claim that p is exactly 3: that would require a test on the slope, which goes beyond the minimum of the course specification, and more individuals.
It is the physical model, the volume, that suggested the right transformation: the number r² alone would never have indicated the shape.
Residuals of the line as a function of length: positive at both ends, negative in the middle, a U that betrays the curvature.
After taking logarithms: the six points are aligned, with slope 3.02.
Points are earned before the solution; after it, you can keep practising.
For you:
Exercise 10: Problem: a complete study, the salamanders of a forest
15 answers to check
An ecology team surveys the salamanders of a deciduous forest over one season. Each salamander captured is marked, so that no individual is counted twice. The data are fictitious but plausible.
Document 1: 200 salamanders classified by species (eastern red-backed, two-lined, spotted) and by capture habitat. Critical values of the chi-square distribution with 4 degrees of freedom: 9.488 at the 5% level, 13.277 at the 1% level.
Document 2: on eight plots of the wooded slope, the soil moisture x (in %) and the number y of red-backed salamanders found under boards laid on the ground. It is given before question d.
Species \ habitat
wooded slope
stream edge
temporary pond
Total
red-backed
34
22
24
80
two-lined
14
28
18
60
spotted
16
16
28
60
Total
64
66
70
200
a) Document 1. State H0, compute the expected counts of the three cells of the “red-backed” row and check the condition for applying the test.
b) Compute χ2 and the number of degrees of freedom. Conclude at the 5% level, then at the 1% level.
c) Name the two cells that contribute the most to the statistic and describe what they show.
d) Document 2. Compute the least-squares line of y as a function of x, then r and r2.
e) Predict the number of red-backed salamanders for a soil moisture of 35%, then of 10%. Comment.
f) Write the conclusion of the study in four sentences at most: what it shows, and what it does not show.
Show the solution
Answers
a)H0: species and habitat independent; 25.6; 26.4; 28; smallest E: 19.2≥5
b)χ2≈12.89, 4 degrees of freedom; rejection at 5%, no rejection at 1%
c)(two-lined, stream), 3.40, and (red-backed, slope), 2.76: each species is overrepresented in one habitat
d)y^≈0.349x−4.72; r≈0.939, r2≈0.882
e)7.5 salamanders at 35%; −1.2 at 10%, absurd extrapolation
f)Species-habitat association significant at 5%, and increasing linear relationship with moisture within the observed range; observational study: no causation shown, no validity outside the range
a)
H0: in this forest, the species of a salamander is independent of its capture habitat.
The smallest expected count is 20060×64=19.2: they all exceed 5.
Marking guarantees the other condition: each observation is a different individual. A salamander recaptured three times would have been counted three times and would have biased the test.
b)
The nine contributions are 2.76, 0.73, 0.57; then 1.41, 3.40, 0.43; then 0.53, 0.73, 2.33.
χ2≈12.89 with (3−1)(3−1)=4 degrees of freedom.
12.89>9.488: H0 is rejected at the 5% level. 12.89<13.277: it is not rejected at the 1% level.
The conclusion therefore depends on the level, which must be chosen BEFORE seeing the data. At the usual 5% level, we conclude that there is an association between species and habitat.
c)
The largest contribution, 3.40, is (two-lined, stream): 28 captures for 19.8 expected, that is, 6028≈47% of the two-lined salamanders were caught at the stream edge, versus 33% of all salamanders.
Next comes (red-backed, slope), 2.76: 34 captures for 25.6 expected.
Each species is overrepresented in a different habitat; the spotted salamander is also overrepresented near the ponds, with 2.33.
a=939.88328.13≈0.349 salamander per point of moisture, b=7.625−0.349×35.375≈−4.72.
r=939.88×129.88328.13≈0.939 and r2≈0.882: the linear relationship with moisture explains about 88% of the variation in the number of salamanders between plots.
The scatter plot shows neither curvature nor an isolated point, which justifies this linear model.
e)
At 35%: y^=0.349×35−4.72≈7.5 salamanders on average, an interpolation within the range 18 to 52%.
At 10%: y^=0.349×10−4.72≈−1.2, a NEGATIVE number of salamanders.
The absurd result signals the extrapolation: below 18%, no data say how the number varies. It probably tends toward 0 without ever becoming negative, and the line stops describing the phenomenon.
f)
In this forest, salamander species and habitat are associated at the 5% level (not at the 1% level), each species being overrepresented in one habitat; on the slope, the number of red-backed salamanders increases with soil moisture, by about 0.35 individual per point of moisture between 18 and 52%.
This is an observational study: it shows associations, not causes. Moisture varies with other factors, such as forest cover or dead wood, which could explain part of the relationship.
The results hold for this forest, this season and the observed moisture range; extending them elsewhere would require new plots, and attributing the effect to moisture would require an experiment in which moisture is varied.
Pitfall: concluding “moisture attracts salamanders” or “the stream edge produces two-lined salamanders”. The study design only allows the word “associated”.
Points are earned before the solution; after it, you can keep practising.
Something missing from this set?A type of exercise your teacher gives, a problem you are stuck on, a mistake you spotted: tell me, I read every request.
Sending goes through your free space: that is how I can answer you and tell you when the exercise is added. An email is enough, no password. Create your space.
Rather not create an account? Write to me directly.
Looking for a probability and statistics tutor in Montreal?
Get in touch for a first session. Regression and the chi-square test come back on the final exam as a complete study: the reasoning and the written conclusion are graded first, then the calculations, and that is exactly what we work on in a session.