Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Part 2: Basic Inferential Data Analysis

Mohamed Fouad Fakhruldeen

4/19/2020

Synopsis

in this second portion of the project, we’re going to analyze the ToothGrowth data in the R datasets package.

1. Load the ToothGrowth data and perform some basic exploratory data analyses
2. Provide a basic summary of the data.
3. Use confidence intervals and/or hypothesis tests to compare tooth growth by supp and dose.
4. conclusions

1. ToothGrowth data

data("ToothGrowth")
working <- ToothGrowth
dim(working)

## [1] 60 3

2. Provide a basic summary of the data.

Testing the relationship between supplements and the growth of tooth Each study subject received one of
three dose levels of supplement (0.5, 1, and 2 mg/day) by one of two delivery methods, OG or VC.

str(working)

## 'data.frame': 60 obs. of 3 variables:


## $ len : num 4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
## $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
## $ dose: num 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...

summary(working)

## len supp dose


## Min. : 4.20 OJ:30 Min. :0.500
## 1st Qu.:13.07 VC:30 1st Qu.:0.500
## Median :19.25 Median :1.000
## Mean :18.81 Mean :1.167
## 3rd Qu.:25.27 3rd Qu.:2.000
## Max. :33.90 Max. :2.000

1
working$dose <- as.factor(working$dose)
table(working$supp, working$dose)

##
## 0.5 1 2
## OJ 10 10 10
## VC 10 10 10

sd(working$len)

## [1] 7.649315

Growth <- working %>% group_by(supp, dose) %>% summarise(len = mean(len))


Growth

## # A tibble: 6 x 3
## # Groups: supp [2]
## supp dose len
## <fct> <fct> <dbl>
## 1 OJ 0.5 13.2
## 2 OJ 1 22.7
## 3 OJ 2 26.1
## 4 VC 0.5 7.98
## 5 VC 1 16.8
## 6 VC 2 26.1

plot <- ggplot(working, aes(x=factor(dose),y=len,fill=factor(dose)))


plot + geom_boxplot(notch=F) + facet_grid(.~supp) +
scale_x_discrete("Dosage") +
scale_y_continuous("Teeth Growth") +
ggtitle("Dosage and Supplement")

2
Dosage and Supplement
OJ VC

30

factor(dose)
Teeth Growth

20 0.5
1
2

10

0.5 1 2 0.5 1 2
Dosage

3. Use confidence intervals and/or hypothesis tests to compare tooth growth by


supp and dose.

testing relation between the supplement and the length of the tooth

t.test(len ~ supp, data = working)

##
## Welch Two Sample t-test
##
## data: len by supp
## t = 1.9153, df = 55.309, p-value = 0.06063
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.1710156 7.5710156
## sample estimates:
## mean in group OJ mean in group VC
## 20.66333 16.96333

null hypotheses rejected as there’s a relationship between the supplement and the length of the teeth of p
value = 3%

3
testing the relation between the dose and the length of the tooth

t.test(working$len[working$dose == 0.5], working$len[working$dose == 1])

##
## Welch Two Sample t-test
##
## data: working$len[working$dose == 0.5] and working$len[working$dose == 1]
## t = -6.4766, df = 37.986, p-value = 1.268e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -11.983781 -6.276219
## sample estimates:
## mean of x mean of y
## 10.605 19.735

t.test(working$len[working$dose == 1], working$len[working$dose == 2])

##
## Welch Two Sample t-test
##
## data: working$len[working$dose == 1] and working$len[working$dose == 2]
## t = -4.9005, df = 37.101, p-value = 1.906e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -8.996481 -3.733519
## sample estimates:
## mean of x mean of y
## 19.735 26.100

t.test(working$len[working$dose == 0.5], working$len[working$dose == 2])

##
## Welch Two Sample t-test
##
## data: working$len[working$dose == 0.5] and working$len[working$dose == 2]
## t = -11.799, df = 36.883, p-value = 4.398e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -18.15617 -12.83383
## sample estimates:
## mean of x mean of y
## 10.605 26.100

4. conclusions

the tooth growth for the OJ supplements at the lowest dose is statistically significant than the VC. as the
higher dosage contains zero in the confidence intervals giving OJ at 0.5 and 1.0 dosages is siginifcant than
VC

You might also like