Dateianhang 'skript3.r'
Herunterladen 1 require(Hmisc)
2
3 x <- spss.get("session3/ZA5240_v2-0-0.sav")
4 ## y <- stata.get("data/ZA5240_v2-0-0.dta")
5
6 ## the column V417 contains the net income,
7 ## calculate the mean using the mean() function!
8 ## What is the problem?
9
10
11 nrow(x)
12 ncol(x)
13
14 mean(x$V417,na.rm = T)
15
16 mean(x$V417,trim=0.05,na.rm = T)
17
18
19 ## summarize the net income using summary(), quantiles() and fivenum()!
20
21 summary(x$V417)
22 summary(x$V81)
23
24 quantile(x$V417,na.rm = T,probs = c(0,0.1,0.2,0.3,1))
25
26 quantile(x$V417,na.rm = T,probs = seq(0,1,by=0.05))
27
28 fivenum(x$V417)
29
30
31 ## make a boxplot by using the following syntax!
32 require(ggplot2)
33 ggplot(x, aes(x=V86, y=V417)) +
34 geom_boxplot()
35
36
37 ggplot(x, aes(x=V86, y=V417, fill=V81)) +
38 geom_boxplot()
39
40
41 ######################################################################
42 ####################### T-Test #######################################
43 ######################################################################
44
45
46 ## one sample
47 set.seed(1)
48 x <- rnorm(12)
49
50 t.test(x,mu=0)
51
52 t.test(x,mu=1)
53
54
55 ## two sample Welch or Satterthwaite test
56 set.seed(1)
57 x <- rnorm(12)
58 y <- rnorm(12)
59 g <- sample(c("A","B"),12,replace = T)
60
61 t.test(x, y)
62 t.test(x ~ g)
63
64 t.test(x, y, var.equal = T)
65
66
67 ######################################################################
68 ####################### Exercises ###################################
69 ######################################################################
70
71 ## do a t-test of income (V417): male against female (V81)!
72
73 t.test(x$V417 ~ x$V81)
74
75 ## and compare the bmi (V279) in smokers and non-smokers (V272)
76 ## and between the people with high and normal blood pressure (V242)
77
78 t.test(x$V279 ~ x$V272)
79 t.test(x$V279 ~ x$V242)
80
81
82 summary(x$V242)
83
84
85 ## bmi by smokers/ non smokers
86 ggplot(x, aes(x=V272, y=V279, fill=V81)) +
87 geom_boxplot() +
88 facet_wrap( ~ V86)
89
90
91
92
93 summary(x$V272)
94
95 ## bmi by high/normal blood pressure
96
97
98
99
100
101 ## Alter
102 summary(x$V84)
103
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!