A notebook made by Paul Amat, amat-design.com
Do these two groups differ?
Means do not differ between groups/conditions.
H0: mu1 = mu2
H1: mu1 ≠ mu2
library(readr)
data <- read_csv("data.csv", show_col_types = FALSE)
group1 <- data[which(data$gender == "Man"), "score"]$score
group2 <- data[which(data$gender == "Woman"), "score"]$score
print("Man")
[1] "Man"
summary(group1)
Min. 1st Qu. Median Mean 3rd Qu. Max.
6.36 19.75 29.23 29.33 39.73 53.47
print("Woman")
[1] "Woman"
summary(group2)
Min. 1st Qu. Median Mean 3rd Qu. Max.
7.54 17.61 30.84 31.23 43.01 54.78
mean(group1)-mean(group2) # ok jamovi
[1] -1.89229
if(!require(ggplot2)) install.packages("ggplot2")
Le chargement a nécessité le package : ggplot2
library(ggplot2)
The independence of observations is guaranteed by the recruitment process.
res <- residuals(lm(score ~ gender, data),type="response")
par(mfrow=c(1,2))
hist(res, freq=FALSE)
curve(dnorm(x, mean=mean(res), sd=sd(res)), add=TRUE, col="red")
qqnorm(res)
qqline(res, col="red")
shapiro.test(res) # ok jamovi
Shapiro-Wilk normality test
data: res
W = 0.95743, p-value = 1.052e-05
bartlett.test(score ~ gender, data)
Bartlett test of homogeneity of variances
data: score by gender
Bartlett's K-squared = 1.9528, df = 1, p-value = 0.1623
library(car)
Le chargement a nécessité le package : carData
leveneTest(score ~ as.factor(gender), data, center = mean) # ok jamovi
Levene's Test for Homogeneity of Variance (center = mean)
Df F value Pr(>F)
group 1 4.1426 0.04315 *
198
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
In Levene test: if p-value is greater than 0.05, we do not reject H0 and we conclude that the variances of our two groups are homogeneous.
outliers <- function(x) {
qinf <- quantile(x, 0.25) - (IQR(x)*1.5)
qsup <- quantile(x, 0.75) + (IQR(x)*1.5)
x[x < qinf | x > qsup]
}
outliers(group1)
numeric(0)
outliers(group2)
numeric(0)
test <- t.test(score ~ gender, data, var.equal = T) # ok in jamovi
test
Two Sample t-test
data: score by gender
t = -1.0278, df = 198, p-value = 0.3053
alternative hypothesis: true difference in means between group Man and group Woman is not equal to 0
95 percent confidence interval:
-5.522961 1.738380
sample estimates:
mean in group Man mean in group Woman
29.33402 31.22631
test$conf.int
[1] -5.522961 1.738380
attr(,"conf.level")
[1] 0.95
This confidence interval encompasses the difference between the means of the groups. If the test is unilateral, one of the limits of the CI will be infinity.
if(!require(effsize)) install.packages("effsize")
library(effsize)
(cohentest <- cohen.d(score ~ gender, data)) #ok jamovi
Cohen's d
d estimate: -0.1454193 (negligible)
95 percent confidence interval:
lower upper
-0.4247985 0.1339598
Cohen’s d est faible si d = .20, modéré si d = .50, important si d = .80 . Le signe + ou - est donné par l’ordre des variables.
if(!require(pwr)) install.packages("pwr")
library(pwr)
pwr.t.test(sig.level = 0.05, n = length(data$score)/2, d = cohentest$estimate, type = "two.sample")
Two-sample t test power calculation
n = 100
d = 0.1454193
sig.level = 0.05
power = 0.1758886
alternative = two.sided
NOTE: n is number in *each* group
pwr.t.test(sig.level = 0.05, power = 0.8, d = cohentest$estimate, type = "two.sample")
Two-sample t test power calculation
n = 743.2836
d = 0.1454193
sig.level = 0.05
power = 0.8
alternative = two.sided
NOTE: n is number in *each* group
t.test(score ~ gender, data, var.equal = F) # ok in jamovi
Welch Two Sample t-test
data: score by gender
t = -1.0322, df = 196.72, p-value = 0.3033
alternative hypothesis: true difference in means between group Man and group Woman is not equal to 0
95 percent confidence interval:
-5.507772 1.723191
sample estimates:
mean in group Man mean in group Woman
29.33402 31.22631
if(!require(effsize)) install.packages("effsize")
library(effsize)
(cohentest <- cohen.d(score ~ gender, data, var.equal = F))
Cohen's d
d estimate: -0.1454193 (negligible)
95 percent confidence interval:
lower upper
-0.4247985 0.1339598
The independence of observations is guaranteed by the recruitment process.
length(group1) > 20 & length(group2) > 20
[1] TRUE
wilcox.test(score ~ gender, data, correct = F) # ok in jamovi
Wilcoxon rank sum test
data: score by gender
W = 4625, p-value = 0.3651
alternative hypothesis: true location shift is not equal to 0
if(!require(effectsize)) install.packages("effectsize")
library(effectsize)
rank_biserial(data$score, data$gender)
r (rank biserial) | 95% CI
---------------------------------
-0.07 | [-0.23, 0.09]