-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontinuous_probability.R
52 lines (40 loc) · 995 Bytes
/
continuous_probability.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
51
52
library(tidyverse)
library(dslabs)
data("heights")
x <- seq(-4, 4, length = 100)
data.frame(x, f = dnorm(x)) %>%
ggplot(aes(x, f)) +
geom_line()
# Monte Carlo simulation of tallest person over 7 feet
x <- heights %>% filter(sex == "Male") %>% pull(height)
n <- length(x)
avg <- mean(x)
s <- sd(x)
B <- 10000
tallest <- replicate(B, {
simulated_data <- rnorm(800, avg, s)
max(simulated_data)
})
mean(tallest>7*12)
# ACT scores
set.seed(16, sample.kind = "Rounding")
act_scores <- rnorm(10000, 20.9, 5.7)
mean(act_scores)
sd(act_scores)
sum(act_scores>=36)
mean(act_scores >= 30)
mean(act_scores <= 10)
x <- 1:36
f_x <- dnorm(x, 20.9, 5.7)
plot(x, f_x, type = "l")
z_scores <- (act_scores - 20.9) / 5.7
mean(z_scores >= 2)
mean(z_scores == 2)
F <- function(a){
mean(act_scores <= a)
}
scores_prop <- sapply(x, F)
p <- seq(0.01, 0.99, 0.01)
sample_quantile <- quantile(act_scores, p)
theoretical_quantile <- qnorm(p, 20.9, 5.7)
qqplot(theoretical_quantile, sample_quantile)