forked from ledayamilee/Statistical-Inference-Coursera
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAssigment1-PartB.Rmd
81 lines (53 loc) · 2.37 KB
/
Assigment1-PartB.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
title: "Statistical Inference Assigment, Part B"
author: "Shahabedin Hassani"
date: "September 20, 2014"
output: pdf_document
---
Now in the second portion of the class, we're going to analyze the ToothGrowth data in the R datasets package.
Load the ToothGrowth data and perform some basic exploratory data analyses
Provide a basic summary of the data.
Use confidence intervals and hypothesis tests to compare tooth growth by supp and dose. (Use the techniques from class even if there's other approaches worth considering)
State your conclusions and the assumptions needed for your conclusions.
##################### Questions 1
Load the ToothGrowth data and perform some basic exploratory data analyses
```{r}
library(ggplot2)
library(datasets)
data(ToothGrowth)
str(ToothGrowth)
head(ToothGrowth)
```
```{r}
plot <- ggplot(ToothGrowth,
aes(x=factor(dose),y=len,fill=factor(dose)))
plot + geom_boxplot(notch=F) + facet_grid(.~supp) +
scale_x_discrete("Dosage (Milligram)") +
scale_y_continuous("Length of Teeth") +
ggtitle("Exploratory Data Analyses")
```
##################### Questions 2
Provide a basic summary of the data.
```{r}
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
summary(ToothGrowth)
```
```{r}
table(ToothGrowth$supp, ToothGrowth$dose)
```
########## Question 3
Use confidence intervals and hypothesis tests to compare tooth growth by supp and dose. (Use the techniques from class even if there’s other approaches worth considering)
```{r}
supp.t1 <- t.test(len~supp, paired=F, var.equal=T, data=ToothGrowth)
supp.t2 <- t.test(len~supp, paired=F, var.equal=F, data=ToothGrowth)
supp.result <- data.frame("p-value"=c(supp.t1$p.value, supp.t2$p.value),
"Conf-Low"=c(supp.t1$conf[1],supp.t2$conf[1]),
"Conf-High"=c(supp.t1$conf[2],supp.t2$conf[2]),
row.names=c("Equal Var","Unequal Var"))
supp.result
```
################## Question 4
State your conclusions and the assumptions needed for your conclusions.
Based on the analysis above, we can conclude that
1- The 2mg dose has larger impact on tooth growth than 1mg and 0.5mg, while 1mg dose has more impact than 0.5mg dose. So there is a different in the growth of the tooth while the doses are larger.
2- There is no doubt that orange juice and vitamin C have obvious different impact on tooth growth.