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 [2022/10/27 22:12] – [Exercise] hkimscil | b:head_first_statistics:using_the_normal_distribution [2023/11/01 08:24] – [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 359: | Line 364: | ||
< | < | ||
+ | Mean <- 100 | ||
+ | Sd <- 10 | ||
- | x <- seq(-4,4, length=100) | + | # X grid for non-standard normal distribution |
- | y <- dnorm(x) | + | x <- seq(-4, 4, length = 100) * Sd + Mean |
- | plot(x,y, type=" | + | |
+ | # Density function | ||
+ | f <- dnorm(x, Mean, Sd) | ||
+ | |||
+ | plot(x, f, type = " | ||
+ | abline(v = Mean) # Vertical line on the mean | ||
</ | </ | ||
- | < | ||
- | # Children' | ||
- | # mean of 100 and a standard deviation of 15. What | ||
- | # proportion of children are expected to have an IQ between | ||
- | # 80 and 120? | ||
- | mean=100; sd=15 | + | {{: |
- | lb=80; ub=120 | + | |
- | x <- seq(-4, | + | <code> |
- | hx <- dnorm(x,mean,sd) | + | # 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 | ||
- | plot(x, hx, type=" | + | normal_area <- function(mean = 0, sd = 1, lb, ub, acolor |
- | main=" | + | x <- seq(mean - 3 * sd, mean + 3 * sd, length |
+ | |||
+ | if (missing(lb)) { | ||
+ | lb <- min(x) | ||
+ | } | ||
+ | if (missing(ub)) { | ||
+ | ub <- max(x) | ||
+ | } | ||
- | i <- x >= lb & x <= ub | + | x2 <- seq(lb, ub, length = 100) |
- | lines(x, hx) | + | plot(x, dnorm(x, mean, sd), type = " |
- | polygon(c(lb, | + | |
+ | y <- dnorm(x2, mean, sd) | ||
+ | | ||
+ | lines(x, dnorm(x, mean, sd), type = "l", ...) | ||
+ | } | ||
+ | </ | ||
- | area <- pnorm(ub, mean, sd) - pnorm(lb, mean, sd) | + | <code> |
- | result | + | normal_area(mean = 0, sd = 1, lb = -1, ub = 2, lwd = 2) |
- | | + | </ |
- | mtext(result,3) | + | {{: |
- | axis(1, at=seq(40, 160, 20), pos=0) | + | < |
+ | pnorm(2) | ||
+ | pnorm(-1) | ||
+ | pnorm(2)-pnorm(-1) | ||
+ | ar <- round(pnorm(2)-pnorm(-1),3) | ||
+ | </code> | ||
+ | < | ||
+ | > pnorm(2) | ||
+ | [1] 0.9772499 | ||
+ | > pnorm(-1) | ||
+ | [1] 0.1586553 | ||
+ | > pnorm(2)-pnorm(-1) | ||
+ | [1] 0.8185946 | ||
+ | > ar <- round(pnorm(2)-pnorm(-1),3) | ||
+ | > | ||
+ | </ | ||
+ | < | ||
+ | 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, m.s, sd.s)-pnorm(lb, m.s, sd.s),3) | ||
+ | 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, m.s, sd.s)-pnorm(lb, m.s, sd.s),3) | ||
+ | text(m.s, .01, ar) | ||
</ | </ | ||
- | {{: | ||
</ | </ | ||
===== Headline ===== | ===== Headline ===== | ||
Line 870: | 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)) | ||
+ | [1] 0.386415 | ||
+ | > | ||
</ | </ | ||
b/head_first_statistics/using_the_normal_distribution.txt · Last modified: 2023/11/01 08:29 by hkimscil