-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlecture-04.R
43 lines (34 loc) · 1001 Bytes
/
lecture-04.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
# Bayes Rule
# P(A|B) = P(B|A)P(A) / (P(B|A)P(A) + P(B|A^c)P(A^c))
# Looking for: P(C^c|T^c)
# = P(T^c|C^c)P(C^c) / (P(T^c|C^c)P(C^c) + P(T^c|C)P(C))
# P(T^c|C^c) = 0.996
# P(C^c) = 0.9
# P(T^c|C) = 100% - 96.8% = 0.032 = 1 - P(T|C)
# P(C) = 0.1
(0.996*0.9) / (0.996*0.9 + 0.032*0.1)
prices <- c(799, 999, 1099, 699)
probs <- c(0.35, 0.29, 0.28, 0.08)
# Expected value
expected.value <- sum(prices * probs)
# Variance
variance <- sum((prices - expected.value)^2 * probs)
# Standard deviation
sqrt(variance)
newprices <- c(799, 999, 1099, 699)
newprobs <- c(0.43, 0.29, 0.28, 0)
sum(newprices * newprobs)
ut2000 <- read.csv("http://jgscott.github.io/teaching/data/ut2000.csv")
hist(ut2000$SAT.C)
mean(ut2000$SAT.C)
sd(ut2000$SAT.C)
# P(SAT < 1000)
pnorm(1000, mean(ut2000$SAT.C), sd(ut2000$SAT.C))
# P(SAT > 1500)
1 - pnorm(1500, mean(ut2000$SAT.C), sd(ut2000$SAT.C))
install.packages("moments")
library(moments)
skewness(ut2000$SAT.C)
hist(ut2000$GPA)
skewness(ut2000$GPA)
qqnorm(ut2000$GPA)