c("effectsize")
wants <- wants %in% rownames(installed.packages())
has <-if(any(!has)) install.packages(wants[!has])
set.seed(123)
100
N <- rnorm(N, 5, 20)
DV <- 0
muH0 <-t.test(DV, alternative="two.sided", mu=muH0)
One Sample t-test
data: DV
t = 3.7292, df = 99, p-value = 0.0003203
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
3.185669 10.430568
sample estimates:
mean of x
6.808118
library(effectsize)
cohens_d(DV)
Cohen's d | 95% CI
------------------------
0.37 | [0.17, 0.57]
c(18, 21)
Nj <- rnorm(Nj[1], 180, 10)
DVm <- rnorm(Nj[2], 175, 6)
DVf <- data.frame(DV=c(DVm, DVf),
tIndDf <-IV=factor(rep(c("f", "m"), Nj)))
t.test(DVf, DVm, alternative="less", var.equal=TRUE)
t.test(DV ~ IV, alternative="greater", var.equal=TRUE, data=tIndDf)
Two Sample t-test
data: DV by IV
t = 1.1137, df = 37, p-value = 0.1363
alternative hypothesis: true difference in means between group f and group m is greater than 0
95 percent confidence interval:
-1.230298 Inf
sample estimates:
mean in group f mean in group m
177.0479 174.6580
t.test(DV ~ IV, alternative="greater", var.equal=FALSE, data=tIndDf)
Welch Two Sample t-test
data: DV by IV
t = 1.1032, df = 34.359, p-value = 0.1388
alternative hypothesis: true difference in means between group f and group m is greater than 0
95 percent confidence interval:
-1.27206 Inf
sample estimates:
mean in group f mean in group m
177.0479 174.6580
Cohen’s \(d\) and Hedge’s \(g\)
library(effectsize)
cohens_d(DV ~ IV, data=tIndDf)
Cohen's d | 95% CI
-------------------------
0.36 | [-0.28, 0.99]
- Estimated using pooled SD.
hedges_g(DV ~ IV, data=tIndDf)
Hedges' g | 95% CI
-------------------------
0.35 | [-0.27, 0.97]
- Estimated using pooled SD.
20
N <- rnorm(N, mean=90, sd=15)
DVpre <- rnorm(N, mean=100, sd=15)
DVpost <- data.frame(DVpre, DVpost) tDepDf <-
t.test(Pair(DVpre, DVpost) ~ 1, alternative="less", data=tDepDf)
Paired t-test
data: Pair(DVpre, DVpost)
t = -2.9918, df = 19, p-value = 0.003748
alternative hypothesis: true difference in means is less than 0
95 percent confidence interval:
-Inf -6.739295
sample estimates:
mean of the differences
-15.96821
Equivalent: one-sample t-test for variable built of pair-wise differences
DVpre - DVpost
DVdiff <-t.test(DVdiff, alternative="less")
cohens_d(DVdiff)
Cohen's d | 95% CI
--------------------------
-0.67 | [-1.15, -0.18]
try(detach(package:effectsize))
R markdown - markdown - R code - all posts