ME = 1.96*sqrt((.66*.44)/1018)
ME
## [1] 0.033104
The morgin of error reported by The Marist Poll was correct.
pbar = .66
p0 = .70
n = 1018
z = (pbar-p0)/sqrt(p0*(1-p0)/n)
z
## [1] -2.784994
z = -2.784
alpha = .05
z.alpha = qnorm(1-alpha)
z.alpha
## [1] 1.644854
pval = pnorm(z, lower.tail=FALSE)
pval
## [1] 0.9973236
Since the test statistic is NOT greater than the critical value of 1.64 and the p-value IS greater than the .05 significance level, we do not reject the null, so the poll does not provide evidence that more than 70% of the population think that licensed drivers should be required to retake their road test once they turn 65.
Ho: >= 50% of American adults who decided not to go to college did so because they could not afford it
Ha: < 50% of American adults who decided not to go to college did so because they could not afford it
pbar1 = .48
p01 = .50
n = 331
z1 = (pbar-p0)/sqrt(p0*(1-p0)/n)
z1
## [1] -1.588051
The test statistic -1.58 is not less than the critical value of -1.64 so therefore we do not reject the null hypothesis, and there is not enough evidence to support the newspaper’s claim.
SE = sqrt((.48*(1-.48))/331)
SE
## [1] 0.02746049
With a standard error of .027 or 2.7% and a sample proportion of .48 or 48% we can form a 95% confidence interval. We are 95% confident that the population proportion falls within 2 SE’s of the sample proportion, in the range (42.6%-53.4%). Therefore the confidence interval, at 95%, does contain .5.
myvector=c(4,30)
mymatrix=matrix(c(4,30,24,45), nrow=2)
colnames(mymatrix) <- c("Control", "Treatment")
rownames(mymatrix) <-c("Alive", "Dead")
mymatrix
## Control Treatment
## Alive 4 24
## Dead 30 45
We cannot calculate a confidence interval because the few number of discrete variables and it is count data rather than observations. However, we can use the Chi-Square distribution.
alive = c(4,24)
dead = c(30,45)
heartData<-rbind(alive,dead)
colnames(heartData)=c("control","treatment")
chisq.test(heartData)
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: heartData
## X-squared = 4.9891, df = 1, p-value = 0.02551
Chi-Square = 4.98 and p-value = 0.025. Therefore, we can reject Ho, and we conclude that there is a differnce in survival rate between the two groups.
myvector1=c(264,38,16)
mymatrix1=matrix(c(264,38,16,299,55,15,351,77,22), nrow=3)
colnames(mymatrix1) <- c("Republican", "Democrat", "Independent")
rownames(mymatrix1) <-c("Should", "Should Not", "Don't Know/No Answer")
mymatrix1
## Republican Democrat Independent
## Should 264 299 351
## Should Not 38 55 77
## Don't Know/No Answer 16 15 22
myvector2=c(264,38,16)
mymatrix2=matrix(c(264,38,16,299,55,15), nrow=3)
colnames(mymatrix2) <- c("Republican", "Democrat")
rownames(mymatrix2) <-c("Should", "Should Not", "Don't Know/No Answer")
mymatrix2
## Republican Democrat
## Should 264 299
## Should Not 38 55
## Don't Know/No Answer 16 15
Since we are just looking at the differnce between Republican and Democrat, I removed Independent from the matrix. Now we can run the chisq.test to test our hypothesis.
Ho: No difference in proportion Republicans and Democrats who think the full-body scans should be applied in airports
Ha: There is a difference in proportion Republicans and Democrats who think the full-body scans should be applied in airports
chisq.test(mymatrix2)
##
## Pearson's Chi-squared test
##
## data: mymatrix2
## X-squared = 1.5381, df = 2, p-value = 0.4635
Chi-Square = 1.53 p-value = 0.4635 Since p > 0.05 we do not reject the null hypothesis and we can conclude that there is no evidence of an association between party and opinion.
TRUE
pchisq(10,5,lower.tail=FALSE)
## [1] 0.07523525
p-value (.075) > .05
TRUE
FALSE
The chi-squared test is basically always a one-sided test because it is squared and made positive.
TRUE
myvector3=c(670,11545)
mymatrix3=matrix(c(670,11545,373,6244,905,16392,564,11726,95,2288), nrow=2)
colnames(mymatrix3) <- c("<=1Cup/Week", "2-6Cups/Weel", "1Cup/Day", "2-3Cups/Day", ">=4Cups/Day")
rownames(mymatrix3) <-c("Yes", "No")
mymatrix3
## <=1Cup/Week 2-6Cups/Weel 1Cup/Day 2-3Cups/Day >=4Cups/Day
## Yes 670 373 905 564 95
## No 11545 6244 16392 11726 2288
Based on the data, conducting a chi-square independence test to evaluate if the variables are dependent or not is most appropriate.
Ho: Depression in women is independent of coffee consumption
Ha: Depression in women is NOT independent of coffee consumption
Proportion of women who do notsuffer from depression = 48,132/50,739 or .949 or 94.9%.
Therefore, 2,607/50,739 do not suffer from depression (5.1%).
Exp=(2607*6617)/50739
Exp
## [1] 339.9854
The expected value is 339.98. We can plug this into the chi-test statistic to find its contribution.
ChiSq = (373-339.98)^2/339.98
ChiSq
## [1] 3.207013
Chi-Sq = 3.207
ChiSq=20.93
r=2
c=5
df=(r-1)*(c-1)
round(1-pchisq(ChiSq,df),5)
## [1] 0.00033
P-value = .0003
With a p-value less than .05, we can reject the null hypothesis that depression and coffee consumption are independent.
myvector4=c(10,324)
mymatrix4=matrix(c(10,24,4,12), nrow=2)
colnames(mymatrix4) <- c("Treatment", "Control")
rownames(mymatrix4) <-c("Yawn", "NotYawn")
mymatrix4
## Treatment Control
## Yawn 10 4
## NotYawn 24 12
Ho: Yawning is independent of seeing someone else yawn (Yawning is not contagious)
Ha: Yawning is not indpendent of seeing someone else yawn (Yawning is contagious)
Control Yawning Rate = 4/16 = .25
Treatment Yawning Rate = 10/34 = .29
There is a differnce of .04 or 4% between the treatment and control groups’ yawning rates.
chisq.test(mymatrix4)
## Warning in chisq.test(mymatrix4): Chi-squared approximation may be
## incorrect
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: mymatrix4
## X-squared = 0, df = 1, p-value = 1
Yawn = c(10,4)
NotYawn = c(24,12)
YawnData<-rbind(Yawn,NotYawn)
colnames(YawnData)=c("Treatment","Control")
chisq.test(YawnData)
## Warning in chisq.test(YawnData): Chi-squared approximation may be incorrect
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: YawnData
## X-squared = 0, df = 1, p-value = 1
``` When running the Chi-Square test for independence we get a p-value of 1 > .05, so we fail to reject the null hypothesis and do not have enough evidence to say yawning is contagious.