-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathassignment1_exercise3.Rmd
More file actions
92 lines (69 loc) · 2.01 KB
/
assignment1_exercise3.Rmd
File metadata and controls
92 lines (69 loc) · 2.01 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
title: "Assignment template"
author: "James Bond, group 007"
date: "1 February 2033"
output: pdf_document
fontsize: 11pt
highlight: tango
---
## Imports
```{r}
library("ggpubr")
```
## 3a
```{r, fig.height=3.5}
data=read.table(file="dogs.txt",header=TRUE)
data
shapiro.test(data$isofluorane)
ggqqplot(data$isofluorane)
```
p-value < 0.05 so cannot assume data was taken from normal populations.
## 3b
```{r, fig.height=3.5}
res <- cor.test(data$isofluorane, data$halothane,
method = "pearson")
res
```
p-value > 0.05 so the colleration is not significant.
Permutation test is applicable because it doesn't assume normality and the sample size is small.
Isofluorane & halothane permutation test:
```{r, fig.height=3.5}
mystat=function(x,y) {mean(x-y)}
B=1000; tstar=numeric(B)
for (i in 1:B) {
datastar=t(apply(cbind(data[,1],data[,2]),1,sample))
tstar[i]=mystat(datastar[,1],datastar[,2]) }
myt=mystat(data[,1],data[,2])
myt
hist(tstar)
pl=sum(tstar<myt)/B
pr=sum(tstar>myt)/B
p=2*min(pl,pr)
p
```
p-value > 0.05 so no significant difference
## 3c
```{r, fig.height=3.5}
dataframe=data.frame(concentration=as.vector(as.matrix(data)),
variety=factor(rep(1:3,each=10)))
aov=lm(concentration~variety,data=dataframe)
anova(aov)
```
p-value < 0.05 so factor variety is significant. So yes, the type of drug has an effect on the concentration of plasma epinephrine.
```{r, fig.height=3.5}
summary(aov)
```
The estimated concentrations are 0.43 for isofluorane, 0.04 for halothane, and 0.42 for cyclopropane.
check normality again
```{r, fig.height=3.5}
par(mfrow=c(1,2)); qqnorm(residuals(aov))
plot(fitted(aov),residuals(aov))
```
## 3d
```{r, fig.height=3.5}
attach(dataframe); kruskal.test(concentration,variety)
```
p-value > 0.05 so factor variety is significant.
So no, the two tests don't arrive at the same conclusion. Probably because the population isn't normal and one-way ANOVA assumes normality while the Kruskal-Wallis test does not rely on the normality.
```{r, fig.height=3.5}
```