-
Notifications
You must be signed in to change notification settings - Fork 0
/
KvantBio Skillnad mellan två grupper 1-2.R
165 lines (139 loc) · 2.36 KB
/
KvantBio Skillnad mellan två grupper 1-2.R
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Skillnad mellan två grupper
# Del 1
## Load data
zink <- read.table(
file = "zntill.csv",
sep = ";",
dec = ",",
header = T
)
## Check normal distribution
hist(zink$ktrl_p)
qqnorm(
zink$ktrl_p,
col = "red",
pch = 16
)
qqline(zink$ktrl_p)
hist(zink$tih_p)
qqnorm(
zink$tih_p,
col = "orange",
pch = 16
)
qqline(zink$tih_p)
## t-test
test.plasma <- t.test(
zink$ktrl_p,
zink$tih_p
)
test.plasma
## CI plot
medel_ktrl <- mean(zink$ktrl_p)
medel_tih <- mean(zink$tih_p)
medel <- c(medel_ktrl, medel_tih)
test.ktrl <- t.test(zink$ktrl_p)
test.tih <- t.test(zink$tih_p)
conf.lower <- c(test.ktrl$conf.int[1], test.tih$conf.int[1])
conf.upper <- c(test.ktrl$conf.int[2], test.tih$conf.int[2])
plotrix::plotCI(
x = c(1, 2),
y = medel,
ui = conf.upper,
li = conf.lower,
xlim = c(0.5, 2.5),
ylim = c(0, 1.2),
pch = 16,
col = "blue",
xlab = "Grupp",
ylab = "Zn-koncentration",
xaxt = "n"
)
axis(1,
at = c(1, 2),
labels = c("Kontroll", "Behandling")
)
# Del 2.1
## Load data
LD <- read.table(
file = "LD.csv",
sep = ";",
dec = ",",
header = T
)
## Get diff
LD$diff <- LD$after - LD$before
## Normality of diff
hist(LD$diff)
qqnorm(
LD$diff,
col = "red",
pch = 16
)
qqline(LD$diff)
## t-test
test.diff <- t.test(
LD$before,
LD$after,
paired = T
)
test.diff
# Del 2.2
## Load data
hgexp <- read.table(
file = "hgexp.csv",
sep = ";",
dec = ",",
header = T
)
## Get diff
# hgexp$diff <- hgexp$after - hgexp$before # finns redan
## Normality of diff
hist(hgexp$diff)
qqnorm(
hgexp$diff,
col = "red",
pch = 16
)
qqline(hgexp$diff)
## Wilcox test
wilcox.diff <- wilcox.test(
hgexp$before,
hgexp$after,
paired = T
)
wilcox.diff
## Boxplot
boxplot(
hgexp$before,
hgexp$after
)
# Del 2.3
## Load data
flowers <- read.table(
file = "flowers.csv",
sep = ";",
dec = ",",
header = T
)
## Normal distribution
hist(flowers$flowers[flowers$grazing == "high"])
qqnorm(
flowers$flowers[flowers$grazing == "high"],
col = "red",
pch = 16
)
qqline(flowers$flowers[flowers$grazing == "high"])
hist(flowers$flowers[flowers$grazing == "low"])
qqnorm(
flowers$flowers[flowers$grazing == "low"],
col = "red",
pch = 16
)
qqline(flowers$flowers[flowers$grazing == "low"])
## analysis
test.flowers <- t.test(
flowers$flowers[flowers$grazing == "high"],
flowers$flowers[flowers$grazing == "low"]
)
test.flowers