-
Notifications
You must be signed in to change notification settings - Fork 0
/
norm-pdf.r
50 lines (40 loc) · 939 Bytes
/
norm-pdf.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Plot normal pdf
norm_pdf <- function(x , d.mean = 0, d.sd = 1) {
r <- (
1/(
d.sd*sqrt(2*pi)
)
)*exp(1)^(
-0.5*(
(
(x-d.mean)/d.sd
)^2
)
)
#write(r, "")
return(r)
}
men.mean <- 69.1
men.sd <- 2.9
men.sample_size <- 1000
women.mean <- 63.7
women.sd <- 2.7
women.sample_size <- 1000
men <- rnorm( men.sample_size, mean = men.mean, sd = men.sd )
women <- rnorm( women.sample_size, mean = women.mean, sd = women.sd )
write("Men", "")
mean(men)
quantile(men, c(0.978))
69.1 + 2*2.9
write("Women", "")
mean(women)
quantile(women, c(0.978))
63.7 + 2*2.7
domain_sz = 100
domain <- 0:(domain_sz-1)
from <- men.mean - 4*men.sd
to <- men.mean + 4*men.sd
delta <- (to - from)/domain_sz
domain <- delta * domain + from
fx <- lapply(domain, norm_pdf, d.mean = men.mean, d.sd = men.sd)
plot(domain, fx, type = "l")