Using ToothGrowth Data in R (data found using R program by library(datasets) -> data("ToothGrowth") ),
Assume that if “len” is above 20, it is classified as “HIGH”; and ”LOW”, otherwise. Ignore ‘dose’, and determine whether there is a significant difference in the proportions of the two groups classified as “HIGH” using a suitable test and a 95% confidence interval
Load library.
Then load dataset.
Apply condition using ifelse condition.
Entire R code is
library(datasets)
data("ToothGrowth")
print(ToothGrowth)
ToothGrowth$len <- ifelse( ToothGrowth$len > 20, c("HIGH"),
c("LOW"))
library(dplyr)
ToothGrowth <- select(ToothGrowth, -dose)
print(ToothGrowth)
table(ToothGrowth$len,ToothGrowth$supp)
prop.test( table(ToothGrowth$len,ToothGrowth$supp) ,
correct=FALSE)
Output:
2-sample test for equality of proportions without continuity correction
data: table(ToothGrowth$len, ToothGrowth$supp)
X-squared = 4.2857, df = 1, p-value = 0.03843
alternative hypothesis: two.sided
95 percent confidence interval:
0.02365533 0.51205896
sample estimates:
prop 1 prop 2
0.6428571 0.3750000
Here p=0.03843
p<0.05 Reject Null hypothesis.
Accept alternative hypothesis that there exists a differrence in proportions.
there is a significant difference in the proportions of the two groups classified as “HIGH” and LOW.
95% confidence interval for difference in proportons lies in between 0.0237 and 0.5121
Get Answers For Free
Most questions answered within 1 hours.