W3 - Testing Means - Choose Your Test
W3 - Testing Means - Choose Your Test
W3 - Testing Means - Choose Your Test
1.1 - One sample: Example research: Is the health of students significantly different than 6.5/10
1st Example: The average health differs between Dutch and non-Dutch students: YES equal variance.
2nd Example: The average health differs between males and females: NOT equal variance
1.3 - More than 2 samples: The average exam results differs between groups of nationality (1,2,3)
- HO: µdutc h=µgerman =µspanis hOR HO: β 1=β 2=β 3=0
- H1: µdutc h ≠ µgerman ≠ µspanis hOR: β 1 ≠ β 2 ≠ β 3 ≠ 0
Output:
One Sample t-test
data: data540$health
t = 2.7681, df = 49, p-value = 0.007936
alternative hypothesis: true mean is not equal to 6.5
95 percent confidence interval:
6.678663 7.625337
sample estimates:
mean of x
7.152
Step 3: Interpretation:
Extra (Optional): You can also use a linear model to obtain the same interpretations
Call:
lm(formula = health - 6.5 ~ 1, data = data540)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.6520 0.2355 2.768 0.00794 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.666 on 49 degrees of freedom
**Note that :
- The b-coefficient/estimate = 0.652 represents the difference between sample mean and
population mean: 7.152 (sample) – 6.5 (population) = 0.652
- T-value and P-Values are the same as the ones from the t-test, so you can also answer the
hypothesis using this lm method
- Step 0: Check equality of variances: See R code to see how I use the rule of thumb method or
be able to understand it from the text.
Output: (If you follow the codes from Teams, you might see differences as the data is random)
Ex1 : Yes equal variances -> Two sample t-test Ex2: Not Equal variances -> Welch t-test
Example 1 (dutch): Yes equal variances Example 2(gender): Not Equal variances
- P-Value >0.05 we don’t reject Ho - P-Value >0.05 we don’t reject Ho
- 0 within 95% C.I so we don’t reject H0 - 0 within 95% C.I so we don’t reject H0
Conclusion (using P-Value): Based on our Conclusion (using P-Value): Based on our
sample, we don’t have enough evidence to say sample, we don’t have enough evidence to say
that the average health between dutch and that the average health between female and
non-dutch are different. non-male are different.
Conclusion (using C.I): The values of the Conclusion (using C.I): The values of the
confidence interval represents the differences confidence interval represents the differences
in the means between dutch and non-dutch in the means between female and male.
Extra (Optional): You can also use a linear model to obtain the same interpretations
Output: Output:
Call: Call:
lm(formula = health ~ dutch_dummy, data = data540) lm(formula = health ~ gender_numerical, data = data540)
Residuals: Residuals:
Min 1Q Median 3Q Max Min 1Q Median 3Q Max
-3.8447 -1.1333 0.2053 1.1553 3.1417 -3.8750 -1.1462 0.2394 1.0250 2.6250
Coefficients: Coefficients:
Estimate Std. Error t value Pr(>|t|) Estimate Std. Error t value Pr(>|t|)
(Intercept) 7.2447 0.2716 26.673 <2e-16 *** (Intercept) 6.9462 0.3272 21.228 <2e-16 ***
dutch_dummy -0.3864 0.5544 -0.697 0.489 gender_numerical 0.4288 0.4723 0.908 0.368
--- ---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.674 on 48 degrees of freedom Residual standard error: 1.669 on 48 degrees of freedom
Multiple R-squared: 0.01002, Adjusted R-squared: - Multiple R-squared: 0.01689, Adjusted R-squared: -0.003596
0.01061 F-statistic: 0.8244 on 1 and 48 DF, p-value: 0.3684
F-statistic: 0.4857 on 1 and 48 DF, p-value: 0.4892
Interpretation: Interpretation:
Codes:
Call:
lm(formula = happy ~ group, data = data541)
Residuals:
Min 1Q Median 3Q Max
-2.0000 -0.5800 -0.2433 0.5333 2.1000
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.8667 0.8068 1.074 0.3107
groupGroup 2 3.0533 1.0205 2.992 0.0152 *
groupGroup 3 2.7333 1.0673 2.561 0.0306 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Interpretations:
- With the second part of the first output (F-test and associated P-Value) you can reject or not
H0 and say whether the averages between groups are different
In our example P-Value = 0.03 < 0.05 so we can reject H0 (the means are the same) so we can say
that the means are statistically different.
- With the first part of the output you can calculate the means for each group and you can
compare their means pairwise with the reference category one.
To see if there is a significant difference between group 2 and group 1(the reference) you look at the
P-Value of group 2 = 0.0152 < 0.05 so there is a significant difference between these 2 groups. You
can do the same to see whether there is a significant difference between group 3 and group1.
What if I want to see the difference between group 2 and 3 ? So I far I can’t compare them since the
reference category is group 1, so I need to do something: Look next:
Without pipe:
data123$group1 = ifelse(data$group == "Group 1", 1, 0)
data123$group2 = ifelse(data$group == "Group 2", 1, 0)
data123$group3 = ifelse(data$group == "Group 3", 1, 0)
- *** Note data = data (this second data is the name of your dataset)
Output:
summary(model2)
##
## Call:
## lm(formula = happy ~ group1 + group2, data = .)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.0000 -0.5800 -0.2433 0.5333 2.1000
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.6000 0.6987 5.152 0.000601 ***
## group1 -2.7333 1.0673 -2.561 0.030636 *
## group2 0.3200 0.9374 0.341 0.740662
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.397 on 9 degrees of freedom
## Multiple R-squared: 0.5233, Adjusted R-squared: 0.4174
## F-statistic: 4.941 on 2 and 9 DF, p-value: 0.03564
Interpretation: you can see that there is NOT significant difference between group 2 and group 3(the
reference) since the P-Value is = 0.074 > 0.05