b:head_first_statistics:using_the_normal_distribution
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
b:head_first_statistics:using_the_normal_distribution [2021/12/20 23:22] – hkimscil | b:head_first_statistics:using_the_normal_distribution [2023/11/01 08:23] – [Apply a continuity correction] hkimscil | ||
---|---|---|---|
Line 288: | Line 288: | ||
===== Exercise ===== | ===== Exercise ===== | ||
Julie with 5" heels = 64 + 5 = 69 | Julie with 5" heels = 64 + 5 = 69 | ||
+ | Remember X ~ N(71, 20.25) | ||
+ | mean = 71 | ||
+ | variance = 20.25 | ||
+ | sd = 4.5 | ||
+ | z = (71-69)/4.5 | ||
z score = -0.44 | z score = -0.44 | ||
Line 301: | Line 306: | ||
</ | </ | ||
+ | <WRAP box> | ||
+ | rnorm | ||
+ | < | ||
+ | > set.seed(101) | ||
+ | > rnorm(5) | ||
+ | [1] -0.3260365 | ||
+ | > rnorm(5, mean=0, sd=1) | ||
+ | [1] 1.1739663 | ||
+ | > | ||
+ | </ | ||
+ | < | ||
+ | > set.seed(101) | ||
+ | > rnorm(5, mean=100, sd=10) | ||
+ | [1] 96.73964 105.52462 | ||
+ | > | ||
+ | </ | ||
+ | < | ||
+ | > set.seed(101) | ||
+ | > s1 <- rnorm(100, mean=100, sd=10) | ||
+ | > s1 | ||
+ | [1] 96.73964 105.52462 | ||
+ | [8] 98.87266 109.17028 | ||
+ | | ||
+ | [22] 107.08522 | ||
+ | [29] 104.67239 104.98136 108.94937 102.79152 110.07866 | ||
+ | | ||
+ | | ||
+ | | ||
+ | [57] 101.65381 111.29809 111.73722 | ||
+ | [64] 101.12458 104.22604 103.86835 | ||
+ | [71] 115.09897 116.19937 111.53158 | ||
+ | | ||
+ | | ||
+ | | ||
+ | [99] 104.97454 | ||
+ | > | ||
+ | > mean(s1) | ||
+ | [1] 99.62809 | ||
+ | > sd(s1) | ||
+ | [1] 9.34071 | ||
+ | > | ||
+ | </ | ||
+ | pnorm | ||
+ | qnorm | ||
+ | dnorm | ||
+ | < | ||
+ | > set.seed(101) | ||
+ | > dnorm(0) | ||
+ | [1] 0.3989423 | ||
+ | > dnorm(0, mean=0, sd=1) | ||
+ | [1] 0.3989423 | ||
+ | > dnorm(0, mean=0, sd=5) | ||
+ | [1] 0.07978846 | ||
+ | > | ||
+ | </ | ||
+ | pnorm | ||
+ | |||
+ | < | ||
+ | Mean <- 100 | ||
+ | Sd <- 10 | ||
+ | |||
+ | # X grid for non-standard normal distribution | ||
+ | x <- seq(-4, 4, length = 100) * Sd + Mean | ||
+ | |||
+ | # Density function | ||
+ | f <- dnorm(x, Mean, Sd) | ||
+ | |||
+ | plot(x, f, type = " | ||
+ | abline(v = Mean) # Vertical line on the mean | ||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | < | ||
+ | # mean: mean of the Normal variable | ||
+ | # sd: standard deviation of the Normal variable | ||
+ | # lb: lower bound of the area | ||
+ | # ub: upper bound of the area | ||
+ | # acolor: color of the area | ||
+ | # ...: additional arguments to be passed to lines function | ||
+ | |||
+ | normal_area <- function(mean = 0, sd = 1, lb, ub, acolor = " | ||
+ | x <- seq(mean - 3 * sd, mean + 3 * sd, length = 100) | ||
+ | | ||
+ | if (missing(lb)) { | ||
+ | lb <- min(x) | ||
+ | } | ||
+ | if (missing(ub)) { | ||
+ | ub <- max(x) | ||
+ | } | ||
+ | |||
+ | x2 <- seq(lb, ub, length = 100) | ||
+ | plot(x, dnorm(x, mean, sd), type = " | ||
+ | |||
+ | y <- dnorm(x2, mean, sd) | ||
+ | polygon(c(lb, | ||
+ | lines(x, dnorm(x, mean, sd), type = " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | normal_area(mean = 0, sd = 1, lb = -1, ub = 2, lwd = 2) | ||
+ | </ | ||
+ | {{: | ||
+ | < | ||
+ | pnorm(2) | ||
+ | pnorm(-1) | ||
+ | pnorm(2)-pnorm(-1) | ||
+ | ar <- round(pnorm(2)-pnorm(-1), | ||
+ | </ | ||
+ | < | ||
+ | > pnorm(2) | ||
+ | [1] 0.9772499 | ||
+ | > pnorm(-1) | ||
+ | [1] 0.1586553 | ||
+ | > pnorm(2)-pnorm(-1) | ||
+ | [1] 0.8185946 | ||
+ | > ar <- round(pnorm(2)-pnorm(-1), | ||
+ | > | ||
+ | </ | ||
+ | < | ||
+ | m.s <- 100 | ||
+ | sd.s <- 15 | ||
+ | lb <- 80 | ||
+ | ub <- 110 | ||
+ | normal_area(mean = m.s, sd = sd.s, lb = lb, ub = ub, lwd = 2) | ||
+ | ar <- round(pnorm(ub, | ||
+ | text(m.s, .01, ar) | ||
+ | </ | ||
+ | {{: | ||
+ | < | ||
+ | m.s <- 100 | ||
+ | sd.s <- 15 | ||
+ | lb <- m.s - sd.s | ||
+ | ub <- m.s + sd.s | ||
+ | normal_area(mean = m.s, sd = sd.s, lb = lb, ub = ub, lwd = 2) | ||
+ | ar <- round(pnorm(ub, | ||
+ | text(m.s, .01, ar) | ||
+ | </ | ||
+ | </ | ||
===== Headline ===== | ===== Headline ===== | ||
<WRAP box> | <WRAP box> | ||
Line 779: | Line 924: | ||
> pnorm(-0.29) | > pnorm(-0.29) | ||
[1] 0.3859081 | [1] 0.3859081 | ||
+ | |||
+ | # the below is the same as the above | ||
+ | n <- 12 | ||
+ | p <- 1/2 | ||
+ | q <- 1-p | ||
+ | pnorm(5.5, n*p, sqrt(n*p*q)) | ||
+ | |||
</ | </ | ||
Line 812: | Line 964: | ||
===== Pool Puzzle ===== | ===== Pool Puzzle ===== | ||
- | <wrap #continuity_correction | + | <wrap #continuity_correction_egs |
<WRAP help 60%> | <WRAP help 60%> | ||
X < 3 ---- <wrap spoiler> X < 2.5 </ | X < 3 ---- <wrap spoiler> X < 2.5 </ |
b/head_first_statistics/using_the_normal_distribution.txt · Last modified: 2023/11/01 08:29 by hkimscil