Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Statistics - We can do better!

Statistics - We can do better!

A journey of a developer trying to learn how to apply statistics to an everyday problem.

Corey Purcell

April 03, 2014
Tweet

Other Decks in Programming

Transcript

  1. ! Programmers Need To Learn Statistics Or I Will Kill

    Them All http://zedshaw.com/essays/programmer_stats.html
  2. > summary(a) Min. 1st Qu. Median Mean 3rd Qu. Max.

    16.75 26.82 29.63 29.91 32.60 43.58 ! > summary(b) Min. 1st Qu. Median Mean 3rd Qu. Max. -15.48 16.90 31.07 30.12 43.42 80.86
  3. > summary(a) Min. 1st Qu. Median Mean 3rd Qu. Max.

    16.75 26.82 29.63 29.91 32.60 43.58 ! > summary(b) Min. 1st Qu. Median Mean 3rd Qu. Max. -15.48 16.90 31.07 30.12 43.42 80.86
  4. > summary(a) Min. 1st Qu. Median Mean 3rd Qu. Max.

    16.75 26.82 29.63 29.91 32.60 43.58 ! > summary(b) Min. 1st Qu. Median Mean 3rd Qu. Max. -15.48 16.90 31.07 30.12 43.42 80.86
  5. > summary(a) Min. 1st Qu. Median Mean 3rd Qu. Max.

    16.75 26.82 29.63 29.91 32.60 43.58 ! > summary(b) Min. 1st Qu. Median Mean 3rd Qu. Max. -15.48 16.90 31.07 30.12 43.42 80.86 ! > sd(a) [1] 4.787892 ! > sd(b) [1] 20.87684
  6. ! Definition: Power is the probability of rejecting the null

    hypothesis OpenIntro Statistics p. 195 The chance that your experiment is right (Almost!)
  7. > power.t.test ! Power calculations for one and two sample

    t tests
 > power.prop.test Power Calculations for Two-Sample Test for Proportions
  8. ! What’s a 2 sample T test? 2-Sample t-Test !

    Use the 2-sample t-test to compare the averages between two groups and determine if there is a significant difference between them or if the observed difference is due instead to random chance.
  9. > power.t.test Compute power of test, or determine parameters to

    obtain target power. ! power.t.test(n = NULL, delta = NULL, sig.level = 0.05, power = NULL, type = c(“two.sample”, “one.sample”, “paired”), alternative = c(“two.sided","one.sided"), strict = FALSE) ! Exactly one of the parameters n, delta, power, sd, and sig.level must be passed as NULL, and that parameter is determined from the others. Notice that the last two have non-NULL defaults so NULL must be explicitly passed if you want to compute them.
  10. ! WOW 3% chance I’m right? > power.t.test(n = 50,

    delta = 0.01) ! Two-sample t test power calculation ! n = 50 delta = 0.01 sd = 1 sig.level = 0.05 power = 0.02803757 alternative = two.sided ! NOTE: n is number in *each* group
  11. ! n = Sample Size power.t.test(n = NULL, delta =

    NULL, sd = 1, sig.level = 0.05, power = NULL, type = c(“two.sample”, “one.sample”, “paired”), alternative = c(“two.sided","one.sided"), strict = FALSE)
  12. ! delta = True difference in means power.t.test(n = NULL,

    delta = NULL, sd = 1, sig.level = 0.05, power = NULL, type = c(“two.sample”, “one.sample”, “paired”), alternative = c(“two.sided","one.sided"), strict = FALSE)
  13. power.t.test(n = NULL, delta = NULL, sd = 1, sig.level

    = 0.05, power = NULL, type = c(“two.sample”, “one.sample”, “paired”), alternative = c(“two.sided","one.sided"), strict = FALSE) ! sd = Standard deviation
  14. ! sig.level = Significance level (Type I error probability) power.t.test(n

    = NULL, delta = NULL, sd = 1, sig.level = 0.05, power = NULL, type = c(“two.sample”, “one.sample”, “paired”), alternative = c(“two.sided","one.sided"), strict = FALSE)
  15. ! power = Power of test (1 minus Type II

    error probability) power.t.test(n = NULL, delta = NULL, sd = 1, sig.level = 0.05, power = NULL, type = c(“two.sample”, “one.sample”, “paired”), alternative = c(“two.sided","one.sided"), strict = FALSE)
  16. ! type = type of t test 2 sample, 1

    sample or paired power.t.test(n = NULL, delta = NULL, sd = 1, sig.level = 0.05, power = NULL, type = c(“two.sample”, “one.sample”, “paired”), alternative = c(“two.sided","one.sided"), strict = FALSE)
  17. ! alternative = One- or two-sided test power.t.test(n = NULL,

    delta = NULL, sd = 1, sig.level = 0.05, power = NULL, type = c(“two.sample”, “one.sample”, “paired”), alternative = c(“two.sided","one.sided"), strict = FALSE)
  18. ! strict = Use strict interpretation in two- sided case

    power.t.test(n = NULL, delta = NULL, sd = 1, sig.level = 0.05, power = NULL, type = c(“two.sample”, “one.sample”, “paired”), alternative = c(“two.sided","one.sided"), strict = FALSE)
  19. ! Let’s try something > power.t.test(n = 50, delta =

    0.01, sd = 0.01) ! Two-sample t test power calculation ! n = 50 delta = 0.01 sd = 0.01 sig.level = 0.05 power = 0.9986074 alternative = two.sided ! NOTE: n is number in *each* group
  20. ! 99.86% > power.t.test(n = 50, delta = 0.01, sd

    = 0.01) ! Two-sample t test power calculation ! n = 50 delta = 0.01 sd = 0.01 sig.level = 0.05 power = 0.9986074 alternative = two.sided ! NOTE: n is number in *each* group
  21. ! 70% not bad > power.t.test(n = 50, delta =

    0.01, sd = 0.02) ! Two-sample t test power calculation ! n = 50 delta = 0.01 sd = 0.02 sig.level = 0.05 power = 0.6968888 alternative = two.sided ! NOTE: n is number in *each* group
  22. ! 105 samples were needed > power.t.test(power=0.95, delta = 0.01,

    sd = 0.02) ! Two-sample t test power calculation ! n = 104.928 delta = 0.01 sd = 0.02 sig.level = 0.05 power = 0.95 alternative = two.sided ! NOTE: n is number in *each* group
  23. ! “The result was significant with p<0.05, so there’s only

    a 1 in 20 chance it’s a fluke!”, please beat them over the head with a statistics textbook for me. http://www.statisticsdonewrong.com/conclusion.html