Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Section 3.5 — Two-sample hypothesis tests

This notebook contains the code examples from Section 3.5 Two-sample hypothesis tests of the No Bullshit Guide to Statistics.

Notebook setup


[notice] A new release of pip is available: 26.2.1 -> 26.2.2
[notice] To update, run: pip install --upgrade pip
Note: you may need to restart the kernel to use updated packages.
<Figure size 640x480 with 0 Axes>
datasets/ directory already exists.

\def\stderr#1{\mathbf{se}_{#1}} \def\stderrhat#1{\hat{\mathbf{se}}_{#1}} \def\Mean{\textbf{mean}} \def\Var{\textbf{var}} \def\Std{\textbf{std}} \def\Freq{\textbf{freq}} \def\RelFreq{\textbf{relfreq}} \def\CI#1{\textbf{CI}_{#1}} \def\CIL#1{\textbf{L}_{#1}} \def\CIU#1{\textbf{U}_{#1}} \def\ci#1{\textbf{ci}_{#1}} \def\cil#1{\textbf{l}_{#1}} \def\ciu#1{\textbf{u}_{#1}} \def\DMeans{\textbf{dmeans}} \def\Prop{\textbf{prop}} \def\DProps{\textbf{dprops}} \def\Err{ {\Large \varepsilon}} \def\calN{\mathcal{N}} \def\Tdist{\mathcal{T}} \def\Expon{\mathrm{Expon}}

(this cell contains the macro definitions like sex‾\stderr{\overline{\mathbf{x}}}, se^\stderrhat{}, mean\Mean, ...)

Definitions

  • Populations. We’ll label the two unknown populations XX and YY. and assume the arbitrary model family M\mathcal{M} with mean parameter X∼M(μX)X \sim \mathcal{M}(\mu_X) and Y∼M(μY)Y \sim \mathcal{M}(\mu_Y).

  • Parameters. The means of the two populations μX\mu_X and μY\mu_Y are unknown, and what we want to study...

  • Samples. We assume the two samples x=(x1,x2,…,xn)\mathbf{x} = (x_1, x_2, \ldots, x_n) and y=(y1,y2,…,ym)\mathbf{y} = (y_1, y_2, \ldots, y_m) are randomly selected from the populations XX and YY.

  • Estimate (statistic) d^=x‾−y‾\hat{d} = \overline{\mathbf{x}} - \overline{\mathbf{y}}: the difference between means of the two samples x\mathbf{x} and y\mathbf{y}.

  • Estimator dmeans\DMeans: the function that computes the difference between means from two samples, d^=dmeans(x,y)=x‾−y‾\hat{d} = \DMeans(\mathbf{x},\mathbf{y}) = \overline{\mathbf{x}} - \overline{\mathbf{y}}. the function we use to compute the estimate d^\hat{d}.

  • Sampling distribution D^=dmeans(X,Y)\hat{D} = \DMeans(\mathbf{X}, \mathbf{Y}): the difference between means computed from two random samples X\mathbf{X} and Y\mathbf{Y}.

Comparing two groups

Description of the problem: compare two group based on sample means computed from each group.

Computing pp-values

<Figure size 700x200 with 2 Axes>

Simulation examples

3.5.1 Difference between means estimator

We’ll now discuss an estimators that is specific for the comparison of the two groups.

  • estimator: d^=dmeans(xA,xB)=mean(xA)−mean(xB)=x‾A−x‾B\hat{d} = \DMeans(\mathbf{x}_A, \mathbf{x}_B) = \Mean(\mathbf{x}_A) - \Mean(\mathbf{x}_B) = \overline{\mathbf{x}}_A - \overline{\mathbf{x}}_B

  • gives an estimate for the difference between population means: Δ=μA−μB\Delta = \mu_A - \mu_B

Example N

array([106.44, 109.33, 128.65, 143.69, 101.26, 123.04, 124.42, 123.01, 119.87, 143.45, 137.78, 116.6 ])
array([103.5 , 119.83, 64.77, 89.24, 116.95, 140.71, 90.8 , 112.8 , 63.44, 94.81, 93.17, 89.6 , 97.9 , 91.02, 115.49])
<Figure size 500x160 with 1 Axes>
(123.12782102038774, 13.761594639978442, 98.93506558107863, 20.322124432018075)

Compute the difference between sample means by calling dmeans.

24.19275543930911

Example 3: comparison of electricity prices

Let’s compute the difference between means of the East and West electricity prices.

9 11.8 10 10.0 11 11.0 12 8.6 13 8.3 14 9.4 15 8.0 16 6.8 17 8.5 Name: price, dtype: float64
9.155555555555557
2.1691358024691367
0 7.7 1 5.9 2 7.0 3 4.8 4 6.3 5 6.3 6 5.5 7 5.4 8 6.5 Name: price, dtype: float64
6.155555555555556
0.6846913580246915

Let’s calculate the mean of the prices in the East and the West:

(9.155555555555557, 6.155555555555556)

To calculate the difference between means, we can simply subtract these two numbers d^=x‾W−x‾E\hat{d} = \overline{\mathbf{x}}_W - \overline{\mathbf{x}}_E, or simply call the function dmeans which computes the estimate d^=DMeans(pricesW,pricesE)\hat{d} = \textbf{DMeans}(\tt{pricesW}, \tt{pricesE}).

3.000000000000001

According to this estimate, the average price Rob can expect in the East end is three cents cheaper, on average, as compared to the average electricity price in the West.

Sampling distribution of the difference between means

We assume the two groups are normally distributed random variables XX and YY:

X∼N ⁣(μX,σX)andY∼N ⁣(μY,σY).X \sim \mathcal{N}\!\left(\mu_X, \sigma_X \right) \qquad \textrm{and} \qquad Y \sim \mathcal{N}\!\left(\mu_Y, \sigma_Y \right).

Definitions:

  • x=(x1,x2,…,xn)\mathbf{x} = (x_1, x_2, \ldots, x_{n})=xsample: a sample of size nn from XX

  • y=(y1,y2,…,ym)\mathbf{y} = (y_1, y_2, \ldots, y_{m})=ysample: a sample of size mm from YY.

  • x‾=mean(x)\overline{\mathbf{x}} = \Mean(\mathbf{x}): the observed mean in the first group

  • y‾=mean(y)\overline{\mathbf{y}} = \Mean(\mathbf{y}): the observed mean in the second group

  • sx2=var(x)s_{\mathbf{x}}^2 = \Var(\mathbf{x}): the sample variance from the first group

  • sy2=var(y)s_{\mathbf{y}}^2 = \Var(\mathbf{y}): the sample variance from the second group

  • d^=dmeans(x,y)=x‾−y‾\hat{d} = \DMeans(\mathbf{x}, \mathbf{y}) = \overline{\mathbf{x}} - \overline{\mathbf{y}}: the difference between means estimate, which is an estimate of the true different between population means Δ=μX−μY\Delta = \mu_X - \mu_Y.

The sampling distribution of the estimator dmeans is defined as:

D^=dmeans(X,Y)=X‾−Y‾,\hat{D} = \texttt{dmeans}(\mathbf{X}, \mathbf{Y}) = \overline{\mathbf{X}} - \overline{\mathbf{Y}},

where X=(X1,X2,…,Xn)\mathbf{X} = (X_1, X_2, \ldots, X_{n}) and Y=(Y1,Y2,…,Ym)\mathbf{Y} = (Y_1, Y_2, \ldots, Y_{m}) are random samples.

Sampling distribution for known populations

<Figure size 500x160 with 1 Axes>
5.807648161384639

Analytical formula for the sampling distribution

Let’s now use probability theory to build a theoretical model for the sampling distribution of the difference-between-means estimator dmeans.

  • The central limit theorem tells us the sample mean within the two group are

    X‾∼N ⁣(μX,σXn)andY‾∼N ⁣(μY,σYm).\overline{\mathbf{X}} \sim \mathcal{N}\!\left(\mu_X, \tfrac{\sigma_X}{\sqrt{n}} \right) \qquad \textrm{and} \qquad \overline{\mathbf{Y}} \sim \mathcal{N}\!\left(\mu_Y, \tfrac{\sigma_Y}{\sqrt{m}} \right).
  • The rules of probability theory tells us that the difference of two normal random variables requires subtracting their means and adding their variance, so we get:

    D^∼N ⁣(μX−μY,  seD^),\hat{D} \sim \mathcal{N}\!\left( \mu_X - \mu_Y, \; \stderr{\hat{D}} \right),

    where the standard error of the estimator D^\hat{D} is:

    seD^=σX2n+σY2m.\stderr{\hat{D}} = \sqrt{ \tfrac{\sigma^2_X}{n} + \tfrac{\sigma^2_Y}{m} }.
seD = 5.774945887192364
<Figure size 500x160 with 1 Axes>

Approximation using Student’s tt-distribution

Recall the plug-in principle allows us to obtain approximate statistical formulas by replacing population parameters with estimates computed from samples. Applying the plug-in principle to the formula sed^\stderr{\hat{d}}, we obtain a formula for the estimated standard error of the difference between means estimator:

se^d^=sx2n+sy2m=se^x‾2+se^y‾2  .\stderrhat{\hat{d}} = \sqrt{ \frac{s_{\mathbf{x}}^2}{n} + \frac{s_{\mathbf{y}}^2}{m} } = \sqrt{ \stderrhat{\overline{\mathbf{x}}}^2 + \stderrhat{\overline{\mathbf{y}}}^2 }\;.

We can now build a model for the sampling distribution of the difference between means estimator based on Student’s tt-distribution:

TD^    ∼    T(νd,  loc ⁣= ⁣Δ,  scale ⁣= ⁣se^d^)  =  se^d^⋅T(νd)  +  Δ,T_{\widehat{D}} \;\; \sim \;\; \mathcal{T}(\nu_d, \; \tt{loc}\!=\!\Delta, \; \tt{scale}\!=\!\stderrhat{\hat{d}}) \; = \; \stderrhat{\hat{d}} \cdot \mathcal{T}(\nu_d) \; + \; \Delta,

where T(νd)\mathcal{T}(\nu_d) is Student’s tt-distribution with νd\nu_d degrees of freedom.

The degrees of freedom of is obtained by the following formula

νd    =    (se^x‾2+se^y‾2)2se^x‾4n−1+se^y‾4m−1  .\nu_d \;\; = \;\; \frac{ (\stderrhat{\overline{\mathbf{x}}}^2 + \stderrhat{\overline{\mathbf{y}}}^2)^2 } { \frac{\stderrhat{\overline{\mathbf{x}}}^4}{n-1} + \frac{\stderrhat{\overline{\mathbf{y}}}^4}{m-1} }\;.

Let’s write a Python function that calculates the degrees of freedom parameter.

Example N (continued): analytical approximation

stdX = 13.761594639978442
stdY = 20.322124432018075
sehatD = 6.5813656142388375
dfD = 24.43259380268516
dhat = 24.19275543930911
<Figure size 500x160 with 1 Axes>

Bootstrap approximation to the sampling distribution

First compute bootstrap estimates for mean in each group

Next we compute the difference between means from bootstrap samples

<Figure size 500x160 with 1 Axes>

We can obtain the bootstrap estimate of the standard error se^d^∗\stderrhat{\hat{d}}^* by calculating the standard deviation of the bootstrap distribution.

6.341245623022366

Example 7: difference between electricity prices

Let’s return to Bob’s dataset of electricity prices collected from charging stations in the East and West parts of his city. We’ll assume the prices in the two parts of the city are normally distributed and described by the models XW∼N(μW,σW)X_W \sim \mathcal{N}(\mu_W, \sigma_W) and XE∼N(μE,σE)X_E \sim \mathcal{N}(\mu_E, \sigma_E).

We have two samples pricesW=xW\tt{pricesW} = \mathbf{x}_W and pricesE=xE\tt{pricesE} = \mathbf{x}_E from these prices

(9.155555555555557, 6.155555555555556)
3.000000000000001
(1.5621388471508475, 9, 0.8776547030454391, 9)
0.5972674401486562
12.59281702723103
<Figure size 500x160 with 1 Axes>

Bootstrapped sampling distribution of the difference between means

First compute bootstrap estimates for mean in each group

Next we compute the difference between means from bootstrap samples

<Figure size 500x160 with 1 Axes>

We can obtain the bootstrap estimate of the standard error se^d^∗\stderrhat{\hat{d}}^* by calculating the standard deviation of the bootstrap distribution.

0.5653843908460382

Note this value is very similar to the value se^d^=0.598\stderrhat{\hat{d}}=0.598 that we obtained from the analytical approximation formula. This shows that the bootstrap procedure is a viable alternative to the calculation based on analytical approximations.

3.5.2 Confidence interval for the difference between means

Example 3: confidence interval for difference in electricity prices

The difference between sample means d^=x‾W−x‾E\hat{d} = \overline{\mathbf{x}}_W - \overline{\mathbf{x}}_E is:

3.000000000000001

The estimate d^\hat{d} will be the center of the confidence interval.

Now let’s compute the parameters we need to know to calculate the standard error of the sampling distribution.

(1.5621388471508475, 9, 0.8776547030454391, 9)
0.5972674401486562
12.59281702723103
[1.9396575883680864, 4.060342411631915]

Bootstrap confidence interval

[2.0666666666666655, 3.933888888888892]

Reusable procedure

Empirical coverage probability evaluation

Coverage proportion of analytical approx. CIs: 0.93
Coverage proportion of bootstrap CIs: 0.92

3.5.3 Permutation test for comparing two populations

The permutations test is a computational approach for comparing two group. The permutation test takes it’s name from the action of mixing up the group-membership labels and computing a statistic which is a way to generate samples from the null hypothesis in situations where the null hypothesis states there is no difference between two groups.

Permutations

array([4, 6, 3, 7, 2, 1, 5])
array([6, 3, 2, 1, 5, 7, 4])

Resampling under the null hypothesis

(array([4, 6, 3]), array([7, 2, 1, 5]))
(array([6, 3, 2]), array([1, 5, 7, 4]))

The function resample_under_H0 gives us a way to generate samples from the null hypothesis. We can then compute the value of the dmeans statistic for these samples. We used the assumption of “no difference” under the null hypothesis, and translated this to the “forget the labels” interpretation.

Example 5P: electricity prices

The probability model under the alternative hypothesis describes two populations with different parameters:

HA:XW=N(μW,σW)andXE=N(μE,σE)H_A: \qquad X_W = \mathcal{N}({\color{blue}{\mu_W}, \sigma_W}) \quad \textrm{and} \quad X_{E} = \mathcal{N}({\color{orange}{\mu_{E}}, \sigma_{E}})

Under the null hypothesis the populations have the same mean:

H0:XW=N(μ0,σW)andXE=N(μ0,σE)H_0: \qquad X_W = \mathcal{N}({\color{red}{\mu_0}, \sigma_W}) \quad \textrm{and} \quad X_{E} = \mathcal{N}({\color{red}{\mu_0}, \sigma_{E}})
Loading...
Loading...
3.000000000000001

Our goal is to determine how likely or unlikely the observed value d^=3\hat{d}=3 is under the null hypothesis H0H_0. This means we need to obtain the sampling distribution of D^\hat{D} under H0H_0, which we can do using the permutation test.

Let’s look at some of the differences we can expect to observe under H0H_0.

1.6444444444444448

Running a permutation test

We can repeat the resampling procedure 10000 times to get the sampling distribution of D^0\widehat{D}_0 under H0H_0, as illustrated in the code procedure below.

<Figure size 500x160 with 1 Axes>

Now that we have the sampling distribution D^0\widehat{D}_0, we can see where the observed value d^=3\hat{d}= 3 =dprice falls within this distribution. The pp-value is the probability of observing value dprice=3 or more extreme under the null hypothesis.

0.0002
<Figure size 500x160 with 1 Axes>

Effect size estimates

3.000000000000001

The bootstrap confidence interval for the effect size ciΔ,0.9∗\ci{\Delta,0.9}^* tells us a range of plausible values for the effect size.

[2.0777777777777775, 3.9555555555555557]

The 90% confidence interval ciΔ,0.9∗=[2.08,3.96]\ci{\Delta,0.9}^* = [2.08, 3.96] describes an interval of numbers that should contain the difference between group means Δ\Delta at least 90% of the time:

PrX({Δ∈ciΔ,0.9∗})≥0.9.\textrm{Pr}_{\mathbf{X}}\big(\{ \Delta \in \ci{\Delta,0.9}^* \}\big) \geq 0.9.

Reusable function

0.0002

Example 1P: permutation test on the known population

0.0016
0.0021997800219978004

Example 3P: lecture and debate curriculums

Loading...
Loading...
8.319642857142867

Our goal is to determine how likely or unlikely this observed value d^s=8.32\hat{d}_s=8.32 is under the null hypothesis H0H_0. This means we need to obtain the sampling distribution of D^0\hat{D}_0 under H0H_0, which we can do using the permutation test.

0.1117
pvalue = 0.1117
<Figure size 500x160 with 1 Axes>

3.5.4 Analytical approximation methods

We’ll now look at another approach for computing the sampling distribution of the difference between means estimator, using an analytical approximations based on Student’s tt-distribution. This is called the “two-sample tt-test” and it is procedure most commonly taught approach in STATS 101 courses.

How likely or unlikely is the observed difference d=3d=3 under the null hypothesis H0H_0?

  • Analytical approximations are math models for describing the sampling distribution under H0H_0

    • Real sampling distributions: obtained by repeated sampling from H0H_0

    • Analytical approximation: math model based on estimated parameters

  • Based on this assumption we can use the theoretical model for the difference between group means (we assumed the two unknown populations are normally distributed), we can obtain a closed form expression for the sampling distribution of D0D_0.

  • In particular, the probability model for the two groups under H0H_0 are:

    H0:X=N(μ0,σX)andY=N(μ0,σY),H_0: \qquad X = \mathcal{N}({\color{red}{\mu_0}}, \sigma_X) \quad \textrm{and} \quad Y = \mathcal{N}({\color{red}{\mu_0}}, \sigma_Y), \quad

    from which we can derive the model for D=X‾−Y‾D = \overline{\mathbf{X}} - \overline{\mathbf{Y}}:

    D0∼N ⁣(0,  sed^)D_0 \sim \mathcal{N}\!\left( {\color{red}{0}}, \; \stderr{\hat{d}} \right)

    In words, the sampling distribution of the difference between group means is normally distributed with mean Δ=0\Delta = 0 and standard deviation se^d^\stderrhat{\hat{d}}, described by the formula:

    sed^=σX2n+σY2m  .\stderr{\hat{d}} % \; = \; \sqrt{ \stderr{\overline{\mathbf{x}}}^2 + \stderr{\overline{\mathbf{y}}}^2 } = \sqrt{ \tfrac{\sigma_X^2}{n} + \tfrac{\sigma_Y^2}{m} }\;.

    The standard error of the difference between means depends on the variance of the two groups σX2\sigma_X^2 and σY2\sigma_Y^2. Recall we’ve seen this expression earlier in Section 3.1 and Section 3.2 as well.

  • Problem 1: the population variances σX2\sigma_X^2 and σY2\sigma_Y^2 are unknown, and we only have the estimated variances sxs_{\mathbf{x}} and sys_{\mathbf{y}}, which we calculated from the samples x\mathbf{x} and y\mathbf{y}.

  • Solution 1: use plug in estimate and We can obtain an approximation to the standard error of the difference between means estimator using the plug-in principle, which states we can use search-and-replace the population parameters σX2\sigma_X^2 and σY2\sigma_Y^2 with the estimates sxs_{\mathbf{x}} and sys_{\mathbf{y}}:

    se^d^=sx2n+sy2m  .\stderrhat{\hat{d}} % \; = \; \sqrt{ \stderrhat{\overline{\mathbf{x}}}^2 + \stderrhat{\overline{\mathbf{y}}}^2 } = \sqrt{ \tfrac{s_{\mathbf{x}}^2}{n} + \tfrac{s_{\mathbf{y}}^2}{m} }\;.
  • Problem 2: the estimated standard error se^d^\stderrhat{\hat{d}} tends to underestimate the true standard error sed^\stderr{\hat{d}}, so when we use the basic normal model N ⁣(loc=0,scale=se^d^)\mathcal{N}\!\left(\tt{loc}=0, \tt{scale}=\stderrhat{\hat{d}} \right) the approximation is off (not enough weight in the tails).

  • Solution 2: use Student’s tt-distribution. We can define a new model for the D0=X‾−Y‾D_0 = \overline{\mathbf{X}} - \overline{\mathbf{Y}} based on Student’s tt-distribution:

    D0∼T ⁣(df=νd,  loc=0,  scale=se^d^)D_0 \sim \mathcal{T}\!\left(\tt{df}=\nu_d, \; \tt{loc}={\color{red}{0}}, \; \tt{scale}=\stderrhat{\hat{d}} \right)

    In words, the sampling distribution of the difference between group means can be modeled as Student’s tt-distribution with νd\nu_d degrees of freedom, centered at 0, with scale parameter se^d^\stderrhat{\hat{d}}.

  • The degrees of freedom parameter, denoted νd\nu_d (Greek letter nu) in equations (df in code) determines the “weight” in the tails of the distribution. It is computed by a complicated formula that depends on the sample sizes nn and mm, and the sample standard deviations sxs_{\mathbf{x}} and sys_{\mathbf{y}}.

<Figure size 700x200 with 2 Axes>

Example 5T: comparing East and West electricity prices

3.000000000000001

Two-sample t-test

We’ll now show the data, probability modeling, and calculation steps of the "two-sample tt-test for comparing group means. The two-sample tt-test is also known as Welch’s t-test.

0.5972674401486562
5.022875513276464
12.59281702723103
0.00025703383372176853

Effect size estimates

3.000000000000001

The confidence interval for the effect size ciΔ,0.9\ci{\Delta,0.9} tells us a range of plausible values for the effect size.

[1.9396575883680864, 4.060342411631915]

The 90% confidence interval ciΔ,0.9=[1.94,4.06]\ci{\Delta,0.9} = [1.94, 4.06] describes an interval of numbers that should contain the difference between group means Δ\Delta at least 90% of the time:

PrX({Δ∈ciΔ,0.9})≥0.9.\textrm{Pr}_{\mathbf{X}}\big(\{ \Delta \in \ci{\Delta,0.9} \}\big) \geq 0.9.

Reusable procedure for two-sample tt-test

Verify we get the same pp-value when using the standard error formula.

0.00025703383372176853

Example 1T: two-sample tt-test with known populations

0.0011643603109388243
obst = 3.6759476463316196
p-value = 0.0011643603109388243
<Figure size 500x160 with 1 Axes>

Example 6T: comparing rural and urban sleep scores

8.319642857142867
0.10307495448387399
0.10307495448387399
<Figure size 500x160 with 1 Axes>

Alternative calculation methods

Two-sample tt-test using pooled variance

Pooled variance formulas

Example 5T revisited with pooled variance

0.5972674401486562
5.022875513276464
16
0.00012497067987674888

Using scipy.stats for bootstrap confidence intervals

[2.0888888888888895, 3.9444444444444446]

Note the result is the same as ...

Confidence intervals using statsmodels

(1.9396575883680873, 4.060342411631915)

Note the result is the same as ...

In the above code example, the functions sms.DescrStatsW compute the descriptive statistics for the two samples, then sms.CompareMeans performs the comparison of means statistical analysis. We call the method tconfint_diff to extract the 90% confidence interval from the result.

As you can see, the numbers we obtain from the statsmodels is exactly the same as the confidence interval we computed manually.

Using pinguouin to compute confidence intervals

array([1.93965759, 4.06034241])

Using scipy.stats.permutation_test for permutation test

You can use the SciPy implementation of permutation test, by calling the function permutation_test to perform a permutation test, then obtain the pp-value.

0.00019998000199980003

Note the pp-value we obtained form the two methods may be different. This can happen when using the permutations test, because we use randomness as part of the calculation.

Using scipy.stats.ttest_ind for two-sample tt-tests

Alternatively, we can use scipy.stats.ttest_ind to obtain the pp-value.

Use equal_var=False to obtain the Welsh value.

0.0002570338337217615

Use equal_var=True to obtain the pooled variance value.

0.00012497067987678515

Using statsmodels for two-sample tt-tests

(5.022875513276465, 0.0002570338337217606, 12.592817027231032)
(5.022875513276465, 0.00012497067987678515, 16.0)

Explanations

Statistical modelling assumptions

  • INDEP:

  • NORMAL:

  • LARGEn:

  • EQVAR:

Standardized effect size

It is sometimes useful to report the effect size using a “standardized” measure for effect sizes.

Cohen’s dd is one such measure, and it is defined as the difference between two means divided by the pooled standard deviation.

d=x‾−y‾sp.d = \frac{\overline{\mathbf{x}} - \overline{\mathbf{y}} }{ s_{p} }.

where the pooled variance is defined as sp2=[(n−1)sx2+(m−1)sy2]/(n+m−2)s_{p}^2 = [(n -1)s_{\mathbf{x}}^2 + (m -1)s_{\mathbf{y}}^2]/(n + m -2).

We interpret the value of Cohen’s dd using the reference table of values:

Cohen’s dEffect size
0.01very small
0.20small
0.50medium
0.80large

Effect size for mean deviation of kombucha Batch 04 from expected value μK=1000\mu_K=1000.

2.367806224329099

Discussion

Comparison to resampling methods

Exercises

See notebook sec35_comparing_two_groups.ipynb.

CUT MATERIAL

Example sampling dist using pivotal transformation

Recall the sampling distribution of the difference between means rvTDprice. Here are some examples of equivalent calculations using standard tt-distribution.

(4.060342411631915, 47.641013149955555)
(0.9406438830093703, 4.556607350244164e-08)

NEW STUFF (TODO: merge with above)

TODO: distribute the following plots into appropriate subsections

Bootstrap approximation

[13.540768158298691, 34.5974768136927]

Analytical approximation

[12.940807861945025, 35.44470301667319]

Simulated sampling distribution under null

Sampling distribution from the permutation test

0.0011998800119988001
<Figure size 500x160 with 1 Axes>
0.0022

Sampling distribution from analytical approximation

<Figure size 500x160 with 1 Axes>
0.0011643603109388243