n1= 133 p1 = 15/133 n2 = 138 p2 = 2/138
p1 and p2 are the measures of prevelance.
We will use a Z test for proportions where H0 -> p1 = p2, HA -> p1 != p2
p1 = % of participants with abnormal trigl in Vit A group p2 = % of participants with abnormal trigl in trace group p_hat = pooled
The p-value is 0.262. With a p-value of 0.262 > 0.05, the alpha level, we fail to reject the null hypothesis. That is, the the proportions of prevelance of abnormal triglycerides are equal.
n1 <- 133
p1 <- 15/133
n2 <- 138
p2 <- 2/138
p_hat <- (n1*p1 + n2*p2)/(n1+n2)
p_hat
## [1] 0.06273063
z <-(p1 - p2)/(sqrt(p_hat*(1-p_hat)*(1/n1) + 1/n2))
z
## [1] 1.120951
2*pnorm(-abs(z))
## [1] 0.2623089
We use a z test for proportions.
The p-value is 0.855. With a p-value of 0.855 > 0.05, the alpha level, we fail to reject the null hypothesis. That is, the the proportions of cancer groups are in fact equal.
n1 <- 11036
p1 <- 1273/n1
n2 <- 11035
p2 <- 1293/n2
p_hat <- (n1*p1 + n2*p2)/(n1+n2)
p_hat
## [1] 0.1162612
z <-(p1 - p2)/(sqrt(p_hat*(1-p_hat)*(1/n1) + 1/n2))
z
## [1] -0.18235
2*pnorm(-abs(z))
## [1] 0.8553081
H0: there is no association between use of Oracon and the development of endometrial cancer (p1=p2) HA: there is an association (p1 != p2)
With a p-value of 0.09987 > 0.05, our alpha level, we fail to reject the null hypothesis. That is, there is no association between the use of Oracon and the development of endometrial cancer and the proportions are equal.
data<-matrix(c(6,8,111,387),nrow=2)
data
## [,1] [,2]
## [1,] 6 111
## [2,] 8 387
fisher.test(data, alternative="two.sided")
##
## Fisher's Exact Test for Count Data
##
## data: data
## p-value = 0.09987
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 0.7298476 8.7798550
## sample estimates:
## odds ratio
## 2.608874
We can use a Fischer’s exact test to test whether the percentage of cases among boys is significantly different from the percentage of cases among girls.
H0: The proportions are equal. HA: The proportions are unequal.
With a p-value of 0.289 > 0.05, our alpha level, we fail to reject the null hypothesis. That is, the the proportions are equal of boys and girls.
data<-matrix(c(6,2,1356,1311),nrow=2)
data
## [,1] [,2]
## [1,] 6 1356
## [2,] 2 1311
fisher.test(data, alternative="two.sided")
##
## Fisher's Exact Test for Count Data
##
## data: data
## p-value = 0.289
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 0.5172593 29.4276588
## sample estimates:
## odds ratio
## 2.899628
HO: The probability of detecting this viral infection are the same for the computer and the attending physician. HA: The probability of detecting this viral infection is not the same for the computer and the attending physician.
The Mcnemar’s test produced a p-value of 0.0001211, which is lower than the alpha level of 0.05. So, we reject the null hypothesis. There is sufficient evidence to claim that the probability of detecting this viral is not the same for the computer and the physician.
require(exact2x2)
## Loading required package: exact2x2
## Warning: package 'exact2x2' was built under R version 3.3.2
## Loading required package: exactci
## Warning: package 'exactci' was built under R version 3.3.2
## Loading required package: ssanv
## Warning: package 'ssanv' was built under R version 3.3.2
dvsc<-matrix(c(48,2,20,9932),nrow=2)
dvsc
## [,1] [,2]
## [1,] 48 20
## [2,] 2 9932
T <- mcnemar.exact(dvsc)
T
##
## Exact McNemar test (with central confidence intervals)
##
## data: dvsc
## b = 20, c = 2, p-value = 0.0001211
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 2.429205 88.241205
## sample estimates:
## odds ratio
## 10
We will use a McNemar’s Match test
HO:The proportion of adverse events between cases and controls is the same HA: The proportion of adverse events between cases and controls is different With a p-value of 4.034e-05 < 0.05, we reject the null hypothesis. That is, there is sufficient evidence to claim the proportion of adverse events between cases and controls is different.
hospepid<-matrix(c(126,104,173,121),nrow=2)
hospepid
## [,1] [,2]
## [1,] 126 173
## [2,] 104 121
T <- mcnemar.exact(hospepid)
T
##
## Exact McNemar test (with central confidence intervals)
##
## data: hospepid
## b = 173, c = 104, p-value = 4.035e-05
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 1.296891 2.142409
## sample estimates:
## odds ratio
## 1.663462
HO: The present and past diagnosis are related HA: The present and the past are not related
With a p-value of 2.2e-16 < 0.05, we reject the null hypothesis. That is, there is sufficient evidence to claim the present and past diagnosis are not related.
gonn<- matrix(c(160,50,200,105),nrow=2)
T<-mcnemar.exact(gonn)
T
##
## Exact McNemar test (with central confidence intervals)
##
## data: gonn
## b = 200, c = 50, p-value < 2.2e-16
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 2.921168 5.568566
## sample estimates:
## odds ratio
## 4
T<-chisq.test(gonn)
T
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: gonn
## X-squared = 6.168, df = 1, p-value = 0.01301
We would use a chi-squred test
HO: Total family income is related in a consistent manner to percentage of HIV-positive HA: Total family income is not related in a consistent manner to percentage of HIV-positive
The p-value is 0.6534. We fail to reject the null hypothesis as the p-value > 0.05, the alpha level. That is, there is sufficient evidence to claim the total family income is related in a consistent manner to percentage of HIV-positive.
blood <-matrix(c(13,5,2,72,26,22), nrow=3)
blood
## [,1] [,2]
## [1,] 13 72
## [2,] 5 26
## [3,] 2 22
T<-chisq.test(blood)
## Warning in chisq.test(blood): Chi-squared approximation may be incorrect
T
##
## Pearson's Chi-squared test
##
## data: blood
## X-squared = 0.85105, df = 2, p-value = 0.6534