User Tools

Site Tools


b:head_first_statistics:using_the_normal_distribution

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
b:head_first_statistics:using_the_normal_distribution [2022/10/27 21:39] – [Exercise] hkimscilb:head_first_statistics:using_the_normal_distribution [2023/11/01 08:28] – [When to approximate the binomial distribution with the normal] 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 303: Line 308:
 <WRAP box> <WRAP box>
 rnorm rnorm
 +<code>
 +> set.seed(101)
 +> rnorm(5) 
 +[1] -0.3260365  0.5524619 -0.6749438  0.2143595  0.3107692
 +> rnorm(5, mean=0, sd=1)
 +[1]  1.1739663  0.6187899 -0.1127343  0.9170283 -0.2232594
 +
 +</code>
 +<code>
 +> set.seed(101)
 +> rnorm(5, mean=100, sd=10)
 +[1]  96.73964 105.52462  93.25056 102.14359 103.10769
 +>
 +</code>
 +<code>
 +> set.seed(101)
 +> s1 <- rnorm(100, mean=100, sd=10)
 +> s1
 +  [1]  96.73964 105.52462  93.25056 102.14359 103.10769 111.73966 106.18790
 +  [8]  98.87266 109.17028  97.76741 105.26448  92.05156 114.27756  85.33180
 + [15]  97.63317  98.06662  91.50245 100.58465  91.82330  79.49692  98.36244
 + [22] 107.08522  97.32019  85.36078 107.44436  85.89610 104.67068  98.80680
 + [29] 104.67239 104.98136 108.94937 102.79152 110.07866  79.26894 111.89853
 + [36]  92.75626 101.67984 109.20335  83.28395 104.48469 104.82459 107.58214
 + [43]  76.80673  95.40495  88.94616 104.02928 105.68935  92.93917  97.09909
 + [50]  85.16122  88.49745  97.25529 105.77901  86.03097 107.49058  89.48813
 + [57] 101.65381 111.29809 111.73722  95.72137  97.40198  85.88827  93.58642
 + [64] 101.12458 104.22604 103.86835  93.12202 101.48902  99.42350  99.25177
 + [71] 115.09897 116.19937 111.53158  99.22396  81.81065  89.62555 103.02492
 + [78]  87.22054 101.38339  99.49016 118.52148 111.11675  94.88625  94.56119
 + [85]  82.71073 104.70750 100.05387 113.48046 107.24097 115.52549 113.25470
 + [92]  99.65735  96.38987  92.79835 102.82015  92.09474  95.55095 113.64993
 + [99] 104.97454  91.85604
 +>
 +> mean(s1)
 +[1] 99.62809
 +> sd(s1)
 +[1] 9.34071
 +
 +</code>
 pnorm pnorm
 qnorm qnorm
 +dnorm
 +<code>
 +> 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
 +
 +</code>
 +pnorm
 +
 +<code>
 +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 = "l", lwd = 2, col = "blue", ylab = "", xlab = "Weight")
 +abline(v = Mean) # Vertical line on the mean
 +</code>
 +
 +{{:b:head_first_statistics:pasted:20221027-222851.png?400}}
 +
 +<code>
 +# 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 = "lightgray", ...) {
 +    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 = "n", ylab = "")
 +   
 +    y <- dnorm(x2, mean, sd)
 +    polygon(c(lb, x2, ub), c(0, y, 0), col = acolor)
 +    lines(x, dnorm(x, mean, sd), type = "l", ...)
 +}
 +</code>
 +
 +<code>
 +normal_area(mean = 0, sd = 1, lb = -1, ub = 2, lwd = 2)
 +</code>
 +{{:b:head_first_statistics:pasted:20221027-224243.png?500}}
 +<code>
 +pnorm(2)
 +pnorm(-1)
 +pnorm(2)-pnorm(-1)
 +ar <- round(pnorm(2)-pnorm(-1),3)
 +</code>
 +<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)
 +
 +</code>
 +<code>
 +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)
 +</code>
 +{{:b:head_first_statistics:pasted:20221027-225952.png?500}}
 +<code>
 +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)
 +</code>
 </WRAP> </WRAP>
 ===== Headline ===== ===== Headline =====
Line 746: Line 886:
 </code> </code>
  
 +위는 아래와 같음을 이해해야 한다
 +<code>
 +> sum(dbinom(c(1:5),12,1/2))
 +[1] 0.3869629
 +
 +</code>
 </WRAP> </WRAP>
  
Line 784: Line 930:
 > 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
 +
 </code> </code>
  
b/head_first_statistics/using_the_normal_distribution.txt · Last modified: 2023/11/01 08:29 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki