In this problem, we are testing to see whether the probability of making a shot on the first attempt is different than the probability of making a shot on the second attempt.
\(H_0\): P(Made First) = P(Made Second) \(H_A\): P(Made Second) \(\neq\) P(Made Second)
With a p-value of 0.06646 > \(\alpha = 0.05\), we fail to reject our null hypothesis.
That is, there is no significant difference between making a shot on the first attempt and making a shot on the second attempt.
mat<-matrix(c(4,5,14,7),ncol=2)
rownames(mat)<-c("Made First","Missed First")
colnames(mat)<-c("Made Second","Missed Second")
mat
## Made Second Missed Second
## Made First 4 14
## Missed First 5 7
mcnemar.test(mat)
##
## McNemar's Chi-squared test with continuity correction
##
## data: mat
## McNemar's chi-squared = 3.3684, df = 1, p-value = 0.06646
With a p-value of 0.4181 > \(\alpha\) = 0.05, we fail to reject our \(H_0\).
Both the mcnemar and fisher’s exact test provide the same conclusion, though the mcnemar test is the better test to use in this situation as mcnemar’s test is used for paired comparison studies when the responses are dichotomous.
I feel like there would be an association between the first and second free throws so this doesn’t make the most sense to me.
#The special case of the permutation test for a 2 by 2 contingency table is called the Fisher’s exact test.
fisher.test(mat)
##
## Fisher's Exact Test for Count Data
##
## data: mat
## p-value = 0.4181
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 0.05986525 2.61005193
## sample estimates:
## odds ratio
## 0.4131166
eos <- c(55,140,91,122,111,185,203,101,
76,145,95,101,196,45,299,226,
65,70,196,72,121,171,151,113,
112,67,276,125,100,81,122,71,
158,78,162,128,96,79,67,119)
n<-length(eos)
#Sample Mean
thetaHat <-mean(eos)
nsim<-1000
thetaBoots<-rep(NA,nsim)
#replace = TRUE is key!
set.seed(1234)
for (i in 1:nsim){
bootsSample<-eos[sample(1:n,n,replace=TRUE)]
thetaBoots[i]<-mean(bootsSample)
}
#MSE
mean((thetaBoots-thetaHat)^2)
## [1] 84.1727
#SD
sd(thetaBoots)
## [1] 9.154394
#Standard Dev
set.seed(1234)
nsim<-1000
thetaHat <- sd(eos)
thetaBoots<-rep(NA,nsim)
#replace = TRUE is key!
for (i in 1:nsim){
bootsSample<-eos[sample(1:n,n,replace=TRUE)]
thetaBoots[i]<-sd(bootsSample)
}
#MSE
mean((thetaBoots-thetaHat)^2)
## [1] 70.37959
#SD
sd(thetaBoots)
## [1] 8.313093
#95 Percentile
set.seed(1234)
nsim = 1000
thetaHat = quantile(eos, probs = .95)
perc_boots = rep(NA,nsim)
for (i in 1:nsim){
bootsSample = eos[sample(1:n, n, replace = T)]
perc_boots[i] = quantile(bootsSample, probs = .95)
}
#MSE
mean((perc_boots-thetaHat)^2)
## [1] 1393.55
#SD
sd(perc_boots)
## [1] 36.85756
\(\bar{X}\) = 2.976 True value of \(var(\bar{X})\) = 2.4 The \(var(\bar{X})\) = 1.844354
set.seed(1234)
n = 15
xbar = rnorm(n, 5, 6)
mean(xbar)
## [1] 2.976218
36/n
## [1] 2.4
#Bootstrap Simulation
set.seed(1234)
nsim = 1000
thetaBoot = rep(NA, nsim)
for (i in 1:nsim){
sampleBoots = xbar[sample(1:n, n , replace = T)]
thetaBoot[i] = mean(sampleBoots)
}
var(thetaBoot)
## [1] 1.844354
From my simulation, \(\bar{X}\) = 18.65 True \(Var(\bar{X})\) = 0.25 \(Var(\bar{X})\) from bootstrap = 0.4460611
set.seed(1234)
b <- rbinom(100,1,0.75)
x <- rep(NA,100)
for(i in 1:100){
if (b[i] == 1) {
x[i] = rnorm(1,20,5)
}
else {
x[i] = rnorm(1,10,10)
}
}
#X bar from sample
thetaHat <-mean(x)
thetaHat
## [1] 18.65216
#True value of variance of X bar from STAT 405 Total Variance Formula
var_x <- ((0.75 * (5 + 400)) + (0.25*(10 + 100))) - (((0.75*20)+(0.25*10))^2)
var_tru <- var_x/100
var_tru
## [1] 0.25
set.seed(1234)
nsim <- 1000
thetaBoots <- rep(NA,nsim)
for (i in 1:nsim){
bootSample <- x[sample(1:100, 100, replace=TRUE)]
thetaBoots[i] <- mean(bootSample)
}
var(thetaBoots)
## [1] 0.4417037