First we need to create lists with the values given in the chart:
brfed <- c(18,11,3,6,14,25,17)
botfed <- c(20,35,7,17,28,39,15)
H0 : Both fed babies are equal H1: Breastfed is not equal to bottle-fed babies
First we have to explore the data and look over histogram and means:
hist(brfed)
mean(brfed)
## [1] 13.42857
hist(botfed)
hist(botfed)
The data does not seem that follows a normal distribution , therefore we will ise a non-parametric test. Also, this is a very small study,I would use a WILCOXON RANK SUM TEST. As a default we always want to use two-sided to cover both tails.
wilcox.test(brfed,botfed)
## Warning in wilcox.test.default(brfed, botfed): cannot compute exact p-value with
## ties
##
## Wilcoxon rank sum test with continuity correction
##
## data: brfed and botfed
## W = 11.5, p-value = 0.1098
## alternative hypothesis: true location shift is not equal to 0
The p-value is very high , is 0.1098.
Assuming that the Type I error is 0.05 , the we would fail to reject the null hypothesis. The two babies population are statistically equal.
H0 : The proportion of males is equal to the proportion of females affected by covid. H1: The proportion of males is not equal fo the proportion of females affected by covid.
Then check your solution by comparing this p-value to that output using the function “prop.test” in R.
prop.test(c(111412,115965),c(4418620,4025100),correct=T)
##
## 2-sample test for equality of proportions with continuity correction
##
## data: c(111412, 115965) out of c(4418620, 4025100)
## X-squared = 1039.5, df = 1, p-value < 2.2e-16
## alternative hypothesis: two.sided
## 95 percent confidence interval:
## -0.003815748 -0.003376767
## sample estimates:
## prop 1 prop 2
## 0.02521421 0.02881046
The p-value is under 0.001 , which is very low, therefore, we will reject the null hypothesis.
Hypertension(HT), Diabetes (Db), Cardiac Event (CE)
HT/High Salt : (24)(17)/83 = 4.9 HT/low Salt (24)(66)/83 = 19.1 Db/High Salt : (35)(17)/83 = 7.2 Db/low Salt (35)(66)/83 = 27.8 CE/High Salt : (24)(17)/83 = 4.9 CE/low salt (24)(66)/83 = 19.1
As we can see in the contingency table, there are 2 values under than 5, which conform over 20% of values and therefore, it will not permit to analyze the problem data using chi-square.
fisher.test(matrix(c(2,5,10,22,30,14),nrow=3))
##
## Fisher's Exact Test for Count Data
##
## data: matrix(c(2, 5, 10, 22, 30, 14), nrow = 3)
## p-value = 0.01251
## alternative hypothesis: two.sided
The p-value is low ,which in this case is 0.01251
Yes definitely, if we consider the Type I error as 0.05, then, we reject the null hypothesis and we confirm that there is statistical difference between these different disease.
HT/High Salt : (55)(41)/181 = 12.46 HT/low Salt (55)(140)/181 = 42.54 Db/High Salt : (69)(41)/181 = 15.63 Db/low Salt (69)(140)/181 = 53.37 CE/High Salt : (57)(41)/181 = 12.91 CE/low salt (57)(140)/181 = 44.09
Since all of the values in the table are greated than 5, therefore we will use the chi-square test.
X^2 = (5-12.46)^2/12.46 + (11-15.63)^2/15.63 + (25-12.91)^2/12.91 + (50-42.54)^2/42.54 + (58-53.37)^2/53.37 + (32-44.09)^2/44.09 X^2= 22.19
Degrees of freedom = (3-1)(2-1) = 2
1-pchisq(22.19,2)
## [1] 1.518807e-05
# The p-value is 0.00001519
The p-value is 0.00001519
Yes, the p-value is extremely low and we reject the null hypothesis, confirming that there is staticcillay difference between all of the types of disease mentioned in this exercise.
Suppose you want to compare the proportion of successes in the behavioral therapy between the matched patients A and B.
For this proportions we would use the McNemar method, where the hypothesis are as follows:
H0: The proportion is 1/2 ( or treatment equally effective) H1: The proportion is not 1/2
As I mentioned before, we should use the McNemar’s Test , because these proportions are correlated.
mcnemar.test(matrix(c(396,139,167,162),2,2))
##
## McNemar's Chi-squared test with continuity correction
##
## data: matrix(c(396, 139, 167, 162), 2, 2)
## McNemar's chi-squared = 2.3824, df = 1, p-value = 0.1227
The p-value is 0.1227
If we assume that the Type I error is 0.05 then we fail to reject the null hypothesis and that the treatments will not be different from each other, it wont be statistically different.