Dateianhang 'session4.r'
Herunterladen 1 ## load the data
2 load("data/studrecords.rdata")
3
4 ## Test the null hypothesis that the population mean math score
5 ## is 500 against a two-sided alternative. Would you accept or
6 ## reject at a 0.05 significance level?
7
8
9
10 ## Test the null hypothesis that the mean math score is equal
11 ## to the mean verbal (sat.v) score against a two sided hypothesis.
12
13
14
15 ## Test the null hypothesis that the verbal and the math score
16 ## is equal in each student.
17
18
19
20 ## Wilcoxon signed-rank test
21 pre.test <- c(17,12,20,12,20,21,23,10,15,17,18,18)
22 post.test <- c(19,25,18,18,26,19,27,14,20,22,16,18)
23
24 wilcox.test(pre.test,post.test,paired = T)
25
26 ## exercises
27 ## load the data frame normtemp from the file temperature.rdata;
28 ## it contains the body temperature of several individuals,
29 ## the gender and the heart rate
30
31
32 ## test if the temperature is different in male (coded as 1)
33 ## and female (coded as 2), use the appropriate test.
34
35
36 ## test again, compare the results of the t test and the wilcoxon.
37
38
39
40 ## plot the respective boxplots!
41
42
43
44
45
46 ## add another layer
47 ggplot(normtemp, aes(x = factor(gender), y = temperature)) +
48 geom_boxplot() +
49 geom_point()
50
51 ggsave("boxplotpoint.png")
52
53
54 ggplot(normtemp, aes(x = factor(gender), y = temperature)) +
55 geom_boxplot() +
56 geom_jitter()
57
58
59 ggsave("boxplotjitter.png")
60
61
62 ggplot(normtemp, aes(x = factor(gender), y = temperature)) +
63 geom_boxplot() +
64 geom_jitter(position=position_jitter(width=0.1))
65
66
67 ggsave("boxplotjitter2.png")
68
69 ggplot(normtemp, aes(x = factor(gender), y = temperature)) +
70 geom_boxplot() +
71 geom_point(stat = "summary", fun.y = "mean")
72
73 ggsave("boxplotmean.png")
74
75
76 ggplot(normtemp, aes(x = factor(gender), y = temperature)) +
77 geom_boxplot() +
78 geom_point(stat = "summary", fun.y = "mean",
79 size = 5, colour = "red")
80
81 ggsave("boxplotmean2.png")
82
83
84
85
86 ## Exercises
87
88 ## load the data set GaltonFamilies from the package HistData
89
90
91 ## make a boxplot of childHeight dependent on gender
92 ## add the means using geom_point()
93
94
95
96
97
98 ## do the respective t-test: what is the (trivial) null hypothesis,
99 ## what is appropriate test, what is the test result and what is
100 ## the conclusion?
101
102
103
104 ## bivariate plots
105 ggplot(GaltonFamilies, aes(x=mother,y=father)) +
106 geom_point()
107
108
109 ggsave("scatter.png")
110
111
112 ## adding a trend line
113 ggplot(GaltonFamilies, aes(x=mother,y=father)) +
114 geom_point() +
115 geom_smooth()
116
117 ggsave("scattertrend1.png")
118
119
120 ## adding a trend line
121 ggplot(GaltonFamilies, aes(x=mother,y=father)) +
122 geom_point() +
123 geom_smooth(method="lm")
124
125 ggsave("scattertrend2.png")
126
127
128 ## Exercises
129 ## use again the GaltonFamilies data set; produce a scatter plot
130 ## of childHeight vs midparentHeight
131
132
133
134
135
136 ##add a trend line by using geom_smooth() without any
137 ## arguments. Which method is used?
138
139
140
141
142
143 ## add a second trend line, this time a linear one!
144
145
146
147
148
149
150 ## now use the aesthetic colour in the first line of the plot
151 ## definition. What happens?
152
Gespeicherte Dateianhänge
Um Dateianhänge in eine Seite einzufügen sollte unbedingt eine Angabe wie attachment:dateiname benutzt werden, wie sie auch in der folgenden Liste der Dateien erscheint. Es sollte niemals die URL des Verweises ("laden") kopiert werden, da sich diese jederzeit ändern kann und damit der Verweis auf die Datei brechen würde.Sie dürfen keine Anhänge an diese Seite anhängen!