-
Notifications
You must be signed in to change notification settings - Fork 7
/
session2-exercise.R
58 lines (41 loc) · 1.8 KB
/
session2-exercise.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
#asssuming the design object created earlier in session 1
grep("age",names(nhis_data), value=TRUE)
grep("sex",names(nhis_data), value=TRUE)
summary(svyglm(sleep~age_p, design=nhis))
summary(svyglm(sleep~sex, design=nhis))
summary(svyglm(sleep~sex*age_p, design=nhis))
svyplot(sleep~age_p,design=nhis, style="trans", pch=19)
summary(nhis_data$sleep)
with(nhis_data, table(sleep[sleep>24]))
nhis<-update(nhis, sleep=ifelse(sleep>24,NA,sleep))
svyplot(sleep~age_p,design=nhis, style="trans", pch=19)
svyplot(sleep~age_p,design=nhis, style="hex") #ick
summary(nhis_data$age_p)
table(nhis_data$sex)
svyplot(sleep~age_p,design=nhis, style="trans", pch=19)
age_smth<-svysmooth(sleep~age_p, design=nhis)
lines(age_smth,col="orange",lwd=2)
f_smth<-svysmooth(sleep~age_p, design=subset(nhis,sex=="2 Female"))
m_smth<-svysmooth(sleep~age_p, design=subset(nhis,sex=="1 Male"))
svyplot(sleep~age_p,design=nhis, style="trans", pch=19)
lines(f_smth,col="orange",lwd=2)
lines(m_smth,col="purple",lwd=2)
f_smth<-svysmooth(sleep~age_p, design=subset(nhis,sex=="2 Female"), bandwidth=5)
m_smth<-svysmooth(sleep~age_p, design=subset(nhis,sex=="1 Male"),bandwidth=5)
svyplot(sleep~age_p,design=nhis, style="trans", pch=19)
lines(f_smth,col="orange",lwd=2)
lines(m_smth,col="purple",lwd=2)
nhis<-update(nhis,
agelo=pmin(30,age_p),
agemid=pmin(55,pmax(30,age_p)),
agehi=pmax(55,age_p)
)
summary(svyglm(sleep~sex*(agelo+agemid+agehi), design=nhis))
svyttest(sleep~sex, design=nhis)
svyranktest(sleep~sex, design=nhis)
svyranktest(sleep~sex, design=nhis,test="median")
svyttest(sleep~backpain, design=nhis)
svyranktest(sleep~backpain, design=nhis)
svyranktest(sleep~backpain, design=nhis,test="median")
svyboxplot(sleep~backpain, design=nhis,all.outliers=TRUE)
svyciprop(~backpain, design=nhis)