Skip to content

Instantly share code, notes, and snippets.

@wviechtb
Created June 2, 2023 14:53
Show Gist options
  • Save wviechtb/3834b707caf50948f15c314d2a26a84c to your computer and use it in GitHub Desktop.
Save wviechtb/3834b707caf50948f15c314d2a26a84c to your computer and use it in GitHub Desktop.
Back-calculate the pooled SD from means, group sizes, and the p-value
# means, SDs, and group sizes
m1 <- 52
m2 <- 40
sd1 <- 6
sd2 <- 4
n1 <- 20
n2 <- 40
# pooled SD
sdp <- ((n1-1)*sd1^2 + (n2-1)*sd2^2) / (n1 + n2 - 2)
sdp
# independent samples t-test and corresponding p-value
tval <- (m1 - m2) / (sdp * sqrt(1/n1 + 1/n2))
pval <- 2*pt(abs(tval), df=n1+n2-2, lower.tail=FALSE)
pval
# back-calculate the pooled SD from the p-value, means, and group sizes
tval <- qt(pval/2, df=n1+n2-2, lower.tail=FALSE)
(m1 - m2) / (tval * sqrt(1/n1 + 1/n2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment