Statistical inference : Infering means

Bongani Ncube(3002164)

2025-07-07

Statistical inference

  • Make inferences (an interpretation) about the true parameter value \(\beta\) based on our estimator/estimate
  • Test whether our underlying assumptions (about the true population parameters, random variables, or model specification) hold true.

Testing does not

  • Confirm with 100% a hypothesis is true
  • Confirm with 100% a hypothesis is false
  • Tell you how to interpret the estimate value (Economic vs. Practical vs. Statistical Significance)

Hypothesis: Translate an objective in better understanding the results in terms of specifying a value (or sets of values) in which our population parameters should/should not lie.

  • Null hypothesis (\(H_0\)): A statement about the population parameter that we take to be true in which we would need the data to provide substantial evidence that against it.
    • Can be either a single value (ex: \(H_0: \beta=0\)) or a set of values (ex: \(H_0: \beta_1 \ge 0\))
    • Will generally be the value you would not like the population parameter to be (subjective)
      • \(H_0: \beta_1=0\) means you would like to see a non-zero coefficient
      • \(H_0: \beta_1 \ge 0\) means you would like to see a negative effect
    • “Test of Significance” refers to the two-sided test: \(H_0: \beta_j=0\)
  • Alternative hypothesis (\(H_a\) or \(H_1\)) (Research Hypothesis): All other possible values that the population parameter may be if the null hypothesis does not hold.

Type I Error

Error made when \(H_0\) is rejected when, in fact, \(H_0\) is true.
The probability of committing a Type I error is \(\alpha\) (known as level of significance of the test)

Type I error (\(\alpha\)): probability of rejecting \(H_0\) when it is true.

Legal analogy: In U.S. law, a defendant is presumed to be “innocent until proven guilty”.
If the null hypothesis is that a person is innocent, the Type I error is the probability that you conclude the person is guilty when he is innocent.


Type II Error

Type II error level (\(\beta\)): probability that you fail to reject the null hypothesis when it is false.

In the legal analogy, this is the probability that you fail to find the person guilty when he or she is guilty.

Error made when \(H_0\) is not rejected when, in fact, \(H_1\) is true
The probability of committing a Type II error is \(\beta\) (known as the power of the test)

Questions

  1. Testing Confirms with 100% a hypothesis is true or false?
  2. Type II error is the probability that you fail to reject the null hypothesis when it is true .
What is a p-value?
  1. What is true about a 95% confidence interval of the mean?

Sampling

Random sample of size n: A collection of n independent random variables taken from the distribution X, each with the same distribution as X.

In R

Sample mean

\[ \bar{X}= \frac{\sum_{i=1}^{n}X_i}{n} \]

Find the mean age for the patients above

The mean age to 1 decimal place is

more simply

Sample Median

\(\tilde{x}\) = the middle observation in a sample of observation order from smallest to largest (or vice versa).

If n is odd, \(\tilde{x}\) is the middle observation,
If n is even, \(\tilde{x}\) is the average of the two middle observations.

  • The median age for the patients is ?

Sample variance

\[ S^2 = \frac{\sum_{i=1}^{n}(X_i = \bar{X})^2}{n-1}= \frac{n\sum_{i=1}^{n}X_i^2 -(\sum_{i=1}^{n}X_i)^2}{n(n-1)} \]

Sample standard deviation \[ S = \sqrt{S^2} \]

Sample proportions

\[ \hat{p} = \frac{X}{n} = \frac{\text{number in the sample with trait}}{\text{sample size}} \] \[ \widehat{p_1-p_2} = \hat{p_1}-\hat{p_2} = \frac{X_1}{n_1} - \frac{X_2}{n_2} = \frac{n_2X_1 = n_1X_2}{n_1n_2} \]

Estimators

Point Estimator

\(\hat{\theta}\) is a statistic used to approximate a population parameter \(\theta\)


Point estimate
The numerical value assumed by \(\hat{\theta}\) when evaluated for a given sample


Unbiased estimator
If \(E(\hat{\theta}) = \theta\), then \(\hat{\theta}\) is an unbiased estimator for \(\theta\)

  1. \(\bar{X}\) is an unbiased estimator for \(\mu\)
  2. \(S^2\) is an unbiased estimator for \(\sigma^2\)
  3. \(\hat{p}\) is an unbiased estimator for p
  4. \(\widehat{p_1-P_2}\) is an unbiased estimator for \(p_1- p_2\)
  5. \(\bar{X_1} - \bar{X_2}\) is an unbiased estimator for \(\mu_1 - \mu_2\)

Note: \(S\) is a biased estimator for \(\sigma\)

Distribution of the sample mean

If \(\bar{X}\) is the sample mean based on a random sample of size n drawn from a normal distribution X with mean \(\mu\) and standard deviation \(\sigma\), the \(\bar{X}\) is normally distributed, with mean \(\mu_{\bar{X}} = \mu\) and variance \(\sigma_{\bar{X}}^2 = Var(\bar{X}) = \frac{\sigma^2}{n}\). Then the standard error of the mean is: \(\sigma_{\bar{X}}= \frac{\sigma}{\sqrt{n}}\)

The T.test

When \(\sigma^2\) is estimated by \(s^2\), then

\[ \frac{\bar{y}-\mu}{s/\sqrt{n}} \sim t_{n-1} \]

Then, a \(100(1-\alpha) \%\) confidence interval for \(\mu\) is obtained from:

\[ 1 - \alpha = P(-t_{\alpha/2;n-1} \le \frac{\bar{y}-\mu}{s/\sqrt{n}} \le t_{\alpha/2;n-1}) \\ = P(\bar{y} - (t_{\alpha/2;n-1})s/\sqrt{n} \le \mu \le \bar{y} + (t_{\alpha/2;n-1})s/\sqrt{n}) \]

And the interval is

\[ \bar{y} \pm (t_{\alpha/2;n-1})s/\sqrt{n} \]

and \(s/\sqrt{n}\) is the standard error of \(\bar{y}\)

If the experiment were repeated many times, \(100(1-\alpha) \%\) of these intervals would contain \(\mu\)

Confidence Interval \(100(1-\alpha)%\) Sample Sizes
Confidence \(\alpha\), Error d
Hypothesis Testing
Test Statistic
When \(\sigma^2\) is known, X is normal (or \(n \ge 25\)) \(\bar{X} \pm z_{\alpha/2}\frac{\sigma}{\sqrt{n}}\) \(n \approx \frac{z_{\alpha/2}^2 \sigma^2}{d^2}\) \(z = \frac{\bar{X}-\mu_0}{\sigma/\sqrt{n}}\)
When \(\sigma^2\) is unknown, X is normal (or \(n \ge 25\)) \(\bar{X} \pm t_{\alpha/2}\frac{s}{\sqrt{n}}\) \(n \approx \frac{z_{\alpha/2}^2 s^2}{d^2}\) \(t = \frac{\bar{X}-\mu_0}{s/\sqrt{n}}\)

Example of one sample t.test

patients suffering from clinical depression
patient 1 2 3 4 5 6 7 8
Days 51 41 62 33 28 43 37 44

\[\sum X=339\] \[\bar{X}=42.375\]

Hypothesis Testing

  • \(H_0 : \mu=43\)
  • \(H_1 : \mu \neq 43\)

\[T=\frac{\bar{X}-\mu}{\frac{\sigma}{\sqrt{n}}}\]

\[T=\frac{42.375-43}{\frac{10.60913}{\sqrt{8}}}\] To 3 decimal places what is the value of T?

\(T=\)

since it is a two tailed test we divide percentage by 2

\[t_{8-1}(\frac{5\%}{2})=t_{7}(0.025)=2.365\]

Conclusion

Since \(t_{7}(0.025)>|T|\) it is found in the rejection region hence we reject the null hypothesis and conclude that this group of patients is significantly from the previous group

Example in R

  • mean = 43
  • mean < 43
  • mean = 50

More practical examples

Example in R

  • mean = 50

here we set the alternative to two.sided

Questions

  1. What is the mean MARK?
  2. What is the test statistic?
  3. we have degrees of freedom.
  4. the p-value is significant?
  • mean < 50

we set the alternative to

  • mean > 50

Manually

\[\bar{X}=52.775\]

Hypothesis Testing

  • \(H_0 : \mu=50\)
  • \(H_1 : \mu \neq 50\)

\[T=\frac{\bar{X}-\mu}{\frac{\sigma}{\sqrt{n}}}\]

\[T=\frac{52.775-50}{\frac{9.478586}{\sqrt{200}}}\]

\[T= 4.140325\]

since it is a two tailed test we divide percentage by 2

\[t_{200-1}(\frac{5\%}{2})=t_{199}(0.025)=2.365\]

Conclusion

  • We conclude that the mean is statistically significantly different from .

For Difference of Means (\(\mu_1-\mu_2\)), Independent Samples

\(100(1-\alpha)%\) Confidence Interval Hypothesis Testing
Test Statistic
When \(\sigma^2\) is known \(\bar{X}_1 - \bar{X}_2 \pm z_{\alpha/2}\sqrt{\frac{\sigma^2_1}{n_1}+\frac{\sigma^2_2}{n_2}}\) \(z= \frac{(\bar{X}_1-\bar{X}_2)-(\mu_1-\mu_2)_0}{\sqrt{\frac{\sigma^2_1}{n_1}+\frac{\sigma^2_2}{n_2}}}\)
When \(\sigma^2\) is unknown, Variances Assumed EQUAL \(\bar{X}_1 - \bar{X}_2 \pm t_{\alpha/2}\sqrt{s^2_p(\frac{1}{n_1}+\frac{1}{n_2})}\) \(t = \frac{(\bar{X}_1-\bar{X}_2)-(\mu_1-\mu_2)_0}{\sqrt{s^2_p(\frac{1}{n_1}+\frac{1}{n_2})}}\) Pooled Variance: \(s_p^2 = \frac{(n_1 -1)s^2_1 - (n_2-1)s^2_2}{n_1 + n_2 -2}\)
Degrees of Freedom: \(\gamma = n_1 + n_2 -2\)
When \(\sigma^2\) is unknown, Variances Assumed UNEQUAL \(\bar{X}_1 - \bar{X}_2 \pm t_{\alpha/2}\sqrt{(\frac{s^2_1}{n_1}+\frac{s^2_2}{n_2})}\) \(t = \frac{(\bar{X}_1-\bar{X}_2)-(\mu_1-\mu_2)_0}{\sqrt{(\frac{s^2_1}{n_1}+\frac{s^2_2}{n_2})}}\) Degrees of Freedom: \(\gamma = \frac{(\frac{s_1^2}{n_1}+\frac{s^2_2}{n_2})^2}{\frac{(\frac{s_1^2}{n_1})^2}{n_1-1}+\frac{(\frac{s_2^2}{n_2})^2}{n_2-1}}\)

two sample T-test

When you have a single explanatory variable which is qualitative and only have two levels, you can run a student’s T-test to test for a difference in the mean of the two levels. If appropriate for your data, you can choose to test a unilateral hypothesis. This means that you can test the more specific assumption that one level has a higher mean than the other, rather than that they simply have different means.Note that robustness of this test increases with sample size and is higher when groups have equal sizes

For the t-test, the t statistic used to find the p-value calculation is calculated as: \[t = \frac{(\overline{x_{1}}-\overline{x_{2}})}{\sqrt{\frac{s_{1}^2} n_{1} + \frac{s_{2}^2} n_{2}}}\]

where

\(\overline{x_{1}}\) and \(\overline{x_{2}}\) are the means of the response variable y for group 1 and 2, respectively,
\(s_{1}^2\) and \(s_{2}^2\) are the variances of the response variable y for group 1 and 2, respectively,
\(n_{1}\) and \(n_{2}\) are the sample sizes of groups 1 and 2, respectively.

NB: this applies if the variances are not equal

for equal variances we use the formula in the table above:

\[t = \frac{(\bar{X}_1-\bar{X}_2)-(\mu_1-\mu_2)_0}{\sqrt{s^2_p(\frac{1}{n_1}+\frac{1}{n_2})}}\] where the Pooled Variance: \[s_p^2 = \frac{(n_1 -1)s^2_1 + (n_2-1)s^2_2}{n_1 + n_2 -2}\]

Note that the t-test is mathematically equivalent to a one-way ANOVA with 2 levels.

Assumptions

If the assumptions of the t-test are not met, the test can give misleading results. Here are some important things to note when testing the assumptions of a t-test.

  1. Normality of data
    As with simple linear regression, the residuals need to be normally distributed. If the data are not normally distributed, but have reasonably symmetrical distributions, a mean which is close to the centre of the distribution, and only one mode (highest point in the frequency histogram) then a t-test will still work as long as the sample is sufficiently large (rule of thumb ~30 observations). If the data is heavily skewed, then we may need a very large sample before a t-test works. In such cases, an alternate non-parametric test should be used.
  2. Homoscedasticity
    Another important assumption of the two-sample t-test is that the variance of your two samples are equal. This allows you to calculate a pooled variance, which in turn is used to calculate the standard error. If population variances are unequal, then the probability of a Type I error is greater than α.
    The robustness of the t-test increases with sample size and is higher when groups have equal sizes.
    We can test for difference in variances among two populations and ask what is the probability of taking two samples from two populations having identical variances and have the two sample variances be as different as are \(s_{1}^2\) and \(s_{2}^2\).
    To do so, we must do the variance ratio test (i.e. an F-test).

Violation of assumptions

If variances between groups are not equal, it is possible to use corrections, like the Welch correction. If assumptions cannot be respected, you can transform your data (log or square root for example) or use the non-parametric equivalent of t-test, the Mann-Whitney test. Finally, if the two groups are not independent (e.g. measurements on the same individual at 2 different years), you should use a Paired t-test.

Example in R

here we set var.equal to

Compare Reading marks by gender

Compare in R

assume variances are equal so we set var.equal to

Questions

  1. What is the mean marks for the two groups? 52.82418 and
  2. What is the test statistic?
  3. we have degrees of freedom.
  4. The difference in means is significant?

Manually calculating

Define the hypothesis

  • \(H_0\) : \(\mu_{male} = \mu_{female}\)

  • the means are given in the output tables

Define significance level

  • determine at 5% level

\[t = \frac{(\bar{X}_1-\bar{X}_2)-(\mu_1-\mu_2)_0}{\sqrt{s^2_p(\frac{1}{n_1}+\frac{1}{n_2})}}\] where the Pooled Variance: \[s_p^2 = \frac{(n_1 -1)s^2_1 + (n_2-1)s^2_2}{n_1 + n_2 -2}\]

\[s_p^2 = \frac{(91 -1)10.50671 + (109-1)10.05783}{109 + 91 -2}\]

\[t = \frac{(52.82418-51.73394)}{\sqrt{10.26187(\frac{1}{91}+\frac{1}{109})}}\]

What is the conclusion?

Back to top