Lecture 8 Notes – Statistical Inference for Two Parameters

Lecture 1: Two-Sample t-Test

Scope & Goals

• Compare the means μ<em>1,μ</em>2\mu<em>1,\,\mu</em>2 of two independent populations.

• By the end you should be able to

– derive / recall the test statistic for a two-sample t-test;

– calculate 100(1α)%100(1-\alpha)\% CIs for μ<em>1μ</em>2\mu<em>1-\mu</em>2.

Position in the “road-map” of inference

┌── One variable ──┐ ┌──────────── Two variables ───────────┐

│categorical→CI (p)CI\ (p) │ │both categorical→χ2\chi^2

│quantitative→CI (μ)CI\ (\mu)│ │one cat.+one quant.→ two-sample or paired t

│ │ │both quantitative→simple regression $t$ │

Prototype examples

– “Pregnancy & Smoking” (nicotine vs control; guinea-pig maze errors).

– “Do ravens fly to gunshots?” (later turns out to require paired test).

Terminology & Hypotheses

Population 1: RV X<em>1(μ</em>1,σ<em>1)X<em>1\sim(\mu</em>1,\sigma<em>1); Population 2: X</em>2(μ<em>2,σ</em>2)X</em>2\sim(\mu<em>2,\sigma</em>2).

Null H<em>0:μ</em>1=μ<em>2  (!!μ</em>1μ2=0)H<em>0: \mu</em>1=\mu<em>2\;(!\Leftrightarrow!\mu</em>1-\mu_2=0). One- or two-sided alternatives chosen a priori:

Ha:\ \mu1<\mu2,\;\mu1>\mu2,\;\text{or}\;\mu1\neq\mu_2.

Assumptions ("pooled" version)

  1. Two simple random samples; observations inside and across samples independent.

  2. Equal population SDs: σ<em>1=σ</em>2=σ\sigma<em>1=\sigma</em>2=\sigma (checked via similarity of s<em>1,s</em>2s<em>1,s</em>2).

  3. Either both samples are large (CLT) or both parent distributions \( \approx \) Normal.

Pooled variance estimator & standard error

S<em>p2=(n</em>11)S<em>12+(n</em>21)S<em>22n</em>1+n<em>22S<em>p^2=\frac{(n</em>1-1)S<em>1^2+(n</em>2-1)S<em>2^2}{n</em>1+n<em>2-2} SE(Xˉ</em>1Xˉ<em>2)=S</em>p1n<em>1+1n</em>2SE(\bar X</em>1-\bar X<em>2)=S</em>p\sqrt{\frac1{n<em>1}+\frac1{n</em>2}}

Test statistic

T=Xˉ<em>1Xˉ</em>2S<em>p1n</em>1+1n<em>2  H</em>0t<em>(n</em>1+n22)T=\frac{\bar X<em>1-\bar X</em>2}{S<em>p\sqrt{\dfrac1{n</em>1}+\dfrac1{n<em>2}}}\;\stackrel{H</em>0}{\sim}t<em>{\,(n</em>1+n_2-2)}

P-value rules

• Right-tail (Ha: \mu1>\mu2): P(Tt</em>obs)P(T\ge t</em>{obs})

• Left-tail (Ha: \mu1<\mu2): P(Tt</em>obs)P(T\le t</em>{obs})

• Two-tail (H<em>a:μ</em>1μ<em>2H<em>a: \mu</em>1\neq\mu<em>2): 2P(Tt</em>obs).2P(T\le -|t</em>{obs}|).

Robust to mild non-normality as long as Xˉ<em>1Xˉ</em>2\bar X<em>1-\bar X</em>2 is \($\approx\) Normal.

Confidence interval (level C)

CIC(\mu1-\mu2)=(\bar X1-\bar X2)\;\pm\;t^{\,df}\,Sp\sqrt{\dfrac1{n1}+\dfrac1{n2}}withwithdf=n1+n2-2andandt^*thetwosidedtquantilecoveringareaC.</p><p><strong>WorkedexampleGuineapignicotinestudy</strong><br></p><p>Datasummary:<br></p><p>Groupthe two-sided *t*-quantile covering area C.</p><p>• <strong>Worked example – Guinea-pig nicotine study</strong> <br></p><p>Data summary: <br></p><p>│Group│n\bar xsControl:10,23.4,12.3;Treatment:10,44.3,21.5.<br></p><p>Pooled│ → Control: 10, 23.4, 12.3; Treatment: 10, 44.3, 21.5. <br></p><p>– PooledSp=17.515(R).(R). –t{obs}=\dfrac{23.4-44.3}{17.515\sqrt{0.1+0.1}}=-2.668

– One-sided P-value \( \approx \) 0.0078 \( \Rightarrow \) strong evidence nicotine increases errors.

– 95 % CI: (-20.4,-4.4) \($ \to \) errors higher by 4–37 on average.

Unequal variances?

– If \sigma1\neq\sigma2butbutn1=n2,pooledtestisstillfine.<br></p><p>Largeimbalanceinboth, pooled test is still fine. <br></p><p>– Large imbalance in bothnandand\sigma \($ \to \) transform data or use Welch (not in MATH1041 curriculum).


Lecture 2: Paired t-Test

Motivation – samples are dependent (matching, before/after, twins…). Independence assumption of two-sample test fails.

Examples

– Ravens before/after gunshot (12 pairs).

– Speed-camera counts before vs after installation (4 pairs).

Strategy – reduce to a single sample of differences Di=X{1i}-X{2i}.Populationparameterofinterest:. Population parameter of interest:\muD=E(D).</p><p><strong>Assumptions</strong></p><ol><li><p>.</p><p>• <strong>Assumptions</strong></p><ol><li><p>npaireddifferencesareindependent.</p></li><li><p>Distributionofpaired differences are independent.</p></li><li><p>Distribution ofD \($ \approx \) Normal (or n large for CLT).

Test statistic & CI

T{paired}=\frac{\bar D}{SD/\sqrt n}\;\stackrel{H0}{\sim}t{\,n-1}withwithH0:\muD=0.<br></p><p>. <br></p><p>CIC(\muD)=\bar D\;\pm\;t^{*\,\,n-1}\,\dfrac{S_D}{\sqrt n}.

R implementation

t.test(x_after, x_before, paired=TRUE, alternative="greater")

Raven example recap

Differences: mean \bar D=1.083,SD, SDSD=1.884,,n=12..t{obs}=1.995,,p=0.036 \($ \to \) moderate evidence more ravens post-shot.

One-sided 95 % CI: (0.11,\infty)((\ge0.11ravenincrease).</p><p><strong>Speedcameraexample</strong><br></p><p>Differenceshuge(allnegative),0.11 raven increase).</p><p>• <strong>Speed-camera example</strong> <br></p><p>Differences huge (all negative),t_{obs}=4.95,,p=0.008,reduction, reduction\ge2222cars/month(onesided952222 cars/month (one-sided 95 % CI).</p><p>• <strong>Paired vs two-sample</strong> <br></p><p>– Matched design controls extraneous variation (e.g. "location" in ravens). <br></p><p>– But if data are actually independent, pairing halves degrees-of-freedom \($ \to \) loss of power.</p><p>• <strong>Intro to power</strong> <br></p><p>– Type I error\alpha,TypeIIerror, Type II error\beta,Power, Power1-\beta.<br></p><p>Bloodpressureexample:. <br></p><p>– Blood-pressure example:\sigma=12,,n=100/100 \($ \Rightarrow \) SE=1.7.<br></p><p>Rejectionregionfortwosided. <br></p><p>– Rejection region for two-sided\alpha=0.05: \(|\text{diff}|>3.33\).

– If true diff = -3 \( \to \) power \( \approx \) 42 % .

– Formula manipulation shows n\approx251pergroupneededfor80per group needed for 80 % power.</p><div data-type="horizontalRule"><hr></div><h4 id="591ad4e5-06ac-4ba6-b97d-81c3f9649962" data-toc-id="591ad4e5-06ac-4ba6-b97d-81c3f9649962" collapsed="false" seolevelmigrated="true">Lecture 3: Data Analysis for Two-Way Tables</h4><p>• <strong>Goal</strong> – Summarise and visualise the joint distribution of two categorical variables; compute marginal &amp; conditional distributions.</p><p>• <strong>Construction of a two-way (contingency) table</strong> <br></p><p>– Choose row and column variables, tally counts for each combination. <br></p><p>– Add row/column totals (margins) for marginal distributions.</p><p>• <strong>Key quantities</strong> <br></p><p>– <em>Marginal</em> distribution of a variable: row/column totals divided byn.</p><p><em>Conditional</em>distribution:distributionofonevariableatafixedleveloftheother,e.g..</p><p>– <em>Conditional</em> distribution: distribution of one variable at a fixed level of the other, e.g.P(\text{North}|\text{Moderately})=28/84=0.33.</p><p><strong>Graphicaldisplays</strong><br></p><p>Sidebysidebarcharts(splitbylevels).<br></p><p>Clusteredbarcharts(grouped).<br></p><p>Barchartofconditionalproportions(stackedwith100.</p><p>• <strong>Graphical displays</strong> <br></p><p>– Side-by-side bar charts (split by levels). <br></p><p>– Clustered bar charts (grouped). <br></p><p>– Bar chart of conditional proportions (stacked with 100 % scale).</p><p>• <strong>Illustrative data sets</strong></p><ol><li><p>Hemisphere (N/S) \( \times \) Stress Level (4 levels).

  • Airline (Virgin/QANTAS) \( \times \) Lateness category.

  • Cancer Type \($ \times \) Cancer Site.

  • Interpretation – Compare conditional distributions; if patterns differ, variables likely associated (quantified formally in Lecture 4).


    Lecture 4: Chi-Square Test of Independence

    Purpose – Test H_0of<em>noassociation</em>(independence)betweentwocategoricalvariablesinanof <em>no association</em> (independence) between two categorical variables in anr\times ctable.</p><p><strong>Assumptions</strong></p><ol><li><p>Observationsindependent(usuallySRSorrandomiseddesign).</p></li><li><p>Expectedcountineverycelltable.</p><p>• <strong>Assumptions</strong></p><ol><li><p>Observations independent (usually SRS or randomised design).</p></li><li><p>Expected count in every cell\ge10(ruleofthumb).Combinelevelsifviolated.</p></li></ol><p><strong>Expectedcountsformula</strong><br></p><p>(rule of thumb). Combine levels if violated.</p></li></ol><p>• <strong>Expected counts formula</strong> <br></p><p>E_{ij}=\frac{(\text{row }i\text{ total})(\text{column }j\text{ total})}{n}</p><p><strong>Teststatistic</strong><br></p><p></p><p>• <strong>Test statistic</strong> <br></p><p>X^2=\sum{i=1}^r\sum{j=1}^c\frac{(O{ij}-E{ij})^2}{E{ij}}UnderUnderH0: X^2\sim\chi^2_{df},\;df=(r-1)(c-1).</p><p><strong>Pvalue</strong>Righttailprobability</p><p>• <strong>P-value</strong> – Right-tail probabilityP(\chi^2{df}\ge X^2{obs}).</p><p><strong>Chisquaredistributionfacts</strong><br></p><p>Domain.</p><p>• <strong>Chi-square distribution facts</strong> <br></p><p>– Domain(0,\infty),rightskew.<br></p><p>Mean, right-skew. <br></p><p>– Mean=df,variance, variance=2df.</p><p>As.</p><p>– Asdf\uparrow the curve becomes more symmetric.

    Worked example – Hemisphere \( \times \) Stress

    – 4 \( \times \) 2 table, df=3.<br></p><p>. <br></p><p>–X^2_{obs}=6.59,,p=0.086 \($ \Rightarrow \) weak evidence of association.

    – All expected counts \ge10 \( \to \) assumptions OK.

    Cancer Type \( \times \) Site example

    – 3\( \times \)3 table, one expected count <10 \\()cautionnoted.<br></p><p>\to \\) caution noted. <br></p><p>–X^2_{obs}=6.56,,df=4,,p=0.161 \( \to \) no evidence of association.

    Airline Lateness example

    – Original 3\( \times \)2 table had small counts; merged to 2\($ \times \)2.

    – X^2_{obs}=13.17,,df=1,,p<0.001 \($ \to \) very strong association.

    Software summary (R)

    – Build table: tab&lt;-table(var1,var2) or as.table(cbind(...)).

    chisq.test(tab) returns statistic, df, p-value, expected counts, residuals.

    addmargins(tab) appends row/column totals.

    Quick reference: R functions vs data type

    │One categorical│prop.test() │

    │One quantitative│t.test() (or z.test if \sigma known) │

    │Cat + Quant│t.test(independent or paired) │

    │Cat + Cat│chisq.test() │


    Bonus: Non-Parametric Sign Test

    When? – Very small paired sample, distribution of differences skewed or with outliers \($ \to \) Normal assumption dubious.

    Procedure

    – Define X =numberofpositivedifferencesamongnumber of positive differences amongnpairs.<br></p><p>Undernoeffectmedian0,pairs. <br></p><p>– Under “no effect” median 0,X\sim Bin(n,0.5).</p><p>Compute.</p><p>– ComputeP-value from tail(s) of Binomial.

    Speed-camera revisited (n = 4)

    – All four sites show reduction \($ \to \) x_{obs}=4.</p><p>.</p><p>–P=0.0625 (best possible with n=4).

    – Conclusion: only weak evidence; paired t test was more powerful.

    Trade-off – Non-parametric tests safer but usually less powerful and target medians, not means.


    Chapter Wrap-Up & Keywords

    • You can now:

    – Perform and interpret two-sample & paired t tests.

    – Build and read two-way tables, compute marginal / conditional distributions.

    – Conduct \chi^2 tests for independence and check their assumptions.

    – Understand basics of statistical power & sample-size planning.

    – Recognise situations needing non-parametric alternatives.

    • Core formulas:

    – Two-sample T statistic & CI (pooled).

    – Paired T statistic & CI.

    – Expected counts E_{ij}.</p><p>.</p><p>–\chi^2statisticanddegreesoffreedom.</p><p>Keywords:twosampletest,pooledvariance,paired,twowaytable,joint/marginal/conditionaldistribution,observedvsexpectedcounts,statistic and degrees-of-freedom.</p><p>• Keywords: two-sample test, pooled variance, paired, two-way table, joint / marginal / conditional distribution, observed vs expected counts,\chi^2$$ distribution, sign test, statistical power.