Last active
August 10, 2016 07:56
-
-
Save jirilukavsky/e8745c5a78a1d2f674d364e157852818 to your computer and use it in GitHub Desktop.
Quick power analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Power analysis examples to answer quick questions. | |
# - using pwr package in R | |
# - see also http://www.statmethods.net/stats/power.html | |
# -------------------------------------------------- | |
# setup | |
library(pwr) | |
p <- 0.05 | |
power <- 0.80 | |
# Summary of possible errors | |
cat("For given p/power, you have\n ", p * 100, "% chance to find an effect which is not there (Type 1)\n ", | |
100 * (1 - power), "% chance to miss an effect which is there (Type 2)") | |
# Two-sample t-test | |
# How many people for a given effect (in _each_ group) | |
d <- 0.2 | |
pwr.t.test(d = d, sig.level = p, power = power, type = "two.sample") | |
# Paired t-test | |
# How many people for a given effect | |
d <- 0.2 | |
pwr.t.test(d = d, sig.level = p, power = power, type = "paired") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment