A notebook made by Paul Amat, amat-design.com
Is this treatment effective?
H0:
H1:
library(readr)
data <- read_csv("data.csv", show_col_types = FALSE)
summary(data$score)
Min. 1st Qu. Median Mean 3rd Qu. Max.
6.36 18.75 30.25 30.31 41.45 54.78
summary(data$score.after)
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.73 25.77 36.77 35.66 44.20 59.82
mean(data$score.after)-mean(data$score)
[1] 5.3547
groups.diff <- data$score.after-data$score
par(mfrow=c(1,2))
hist(groups.diff, freq=FALSE)
curve(dnorm(x, mean=mean(groups.diff), sd=sd(groups.diff)), add=TRUE, col="red")
qqnorm(groups.diff)
qqline(groups.diff, col="red")
shapiro.test(groups.diff) # ok in jamovi
Shapiro-Wilk normality test
data: groups.diff
W = 0.98985, p-value = 0.1698
ks.test(groups.diff, "pnorm", mean(groups.diff), sd(groups.diff)) # ok in jamovi
Warning in ks.test(groups.diff, "pnorm", mean(groups.diff), sd(groups.diff)) :
ties should not be present for the Kolmogorov-Smirnov test
One-sample Kolmogorov-Smirnov test
data: groups.diff
D = 0.042962, p-value = 0.8541
alternative hypothesis: two-sided
boxplot(data$score, data$score.after)
t.test(data$score, data$score.after, paired=TRUE) # ok in jamovi
Paired t-test
data: data$score and data$score.after
t = -4.005, df = 199, p-value = 8.754e-05
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-7.991207 -2.718193
sample estimates:
mean of the differences
-5.3547
if(!require(effsize)) install.packages("effsize")
library(effsize)
(cohentest <- cohen.d(data$score.after, data$score, within = F, paired = T)) #ok jamovi
Cohen's d
d estimate: 0.2831969 (small)
95 percent confidence interval:
lower upper
0.1414240 0.4249699
if(!require(pwr)) install.packages("pwr")
library(pwr)
pwr.t.test(sig.level = 0.05, n = length(data$score)/2, d = cohentest$estimate, type = "paired")
Paired t test power calculation
n = 100
d = 0.2831969
sig.level = 0.05
power = 0.8007871
alternative = two.sided
NOTE: n is number of *pairs*
pwr.t.test(sig.level = 0.05, power = 0.8, d = cohentest$estimate, type = "paired")
Paired t test power calculation
n = 99.80326
d = 0.2831969
sig.level = 0.05
power = 0.8
alternative = two.sided
NOTE: n is number of *pairs*
The independence of observations is guaranteed by the recruitment process.
length(data$score) > 20
[1] TRUE
length(data$score.after) > 20
[1] TRUE
wilcox.test(data$score, data$score.after, correct = F, paired=TRUE) # ok jamovi
Wilcoxon signed rank test
data: data$score and data$score.after
V = 6932.5, p-value = 0.0002076
alternative hypothesis: true location shift is not equal to 0
Wilcoxon rank: to be used when the conditions are not respected and especially in the presence of extreme data.
if(!require(effectsize)) install.packages("effectsize")
library(effectsize)
rank_biserial(data$score, data$score.after) # to check
r (rank biserial) | 95% CI
----------------------------------
-0.23 | [-0.33, -0.12]