-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomework.R
More file actions
86 lines (54 loc) · 1.42 KB
/
homework.R
File metadata and controls
86 lines (54 loc) · 1.42 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
f <- cbind ( fac11[fac11$Name %in% fac13$Name & fac11$dept %in%fac13$dept, ])
samp50 <- rep(NA,5000)
for (i in 1:5000)
{
samp <- sample(Gr.Liv.Area, 50)
samp50 [i] <- mean(samp)
}
hist(samp50)
sample_means10 <- rep(NA, 5000)
sample_means100 <- rep(NA, 5000)
for (i in 1:5000) {
samp <- sample(Gr.Liv.Area, 10)
sample_means10[i] <- mean(samp)
samp <- sample(Gr.Liv.Area, 100)
sample_means100[i] <- mean(samp)
}
samp60 <- rep(NA, 5000)
for (i in 1:5000)
{
samp <- sample(SalePrice, 60)
samp60[i] <- mean(samp)
}
smean <- rep(NA, 50)
ssd <- rep(NA, 50)
n <- 60
for (i in 1:50)
{
samp <- sample(Gr.Liv.Area, n)
smean[i] <- mean (samp)
ssd[i] <- sd(samp)
}
lower <- smean - 1.96 * (ssd/sqrt(n))
upper <- smean + 1.96 * (ssd/sqrt(n))
c(lower, upper)
plot.ci(lower, upper, mean(Gr.Liv.Area))
//------home work week 5 BOOTSTRAPPING
bootmeans <- rep(NA, 100)
for (i in 1:100)
{
s <- sample(gained_clean, length(gained_clean), replace=T)
bootmeans[i] = mean(s)
}
// The bootstrap is calculated by resampling from the sample
// 90% CI using BOOTSTRAPPING (PERCENTILE METHOD)
sortedb <- sort(bootmeans)
b <- sortedb[6:length(sortedb)-5]
ci = c(min(b), max(b))
// 90% CI using BOOTSTRAPPING (STANDARD ERROR METHOD)
m = mean (bootmeans)
se = sd(bootmeans)
// note: sample size in denominator is not used when using bootstrapping
// for 90% CI alpha = .05
z = qnorm(.05)
ci = c(m+z*se, m-z*se)