File: smi.R

package info (click to toggle)
r-cran-mitools 2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 500 kB
  • sloc: makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download | duplicates (2)
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
### R code from vignette source 'smi.Rnw'

###################################################
### code chunk number 1: smi.Rnw:9-10
###################################################
options(width=70)


###################################################
### code chunk number 2: smi.Rnw:19-30
###################################################
library(mitools)
data.dir<-system.file("dta",package="mitools")

## read in data
library(foreign)
women<-imputationList(lapply(list.files(data.dir,
				pattern="f.\\.dta",full=TRUE),
                           read.dta, warn.missing.labels=FALSE))
men<-imputationList(lapply(list.files(data.dir,
				pattern="m.\\.dta",full=TRUE),
                           read.dta, warn.missing.labels=FALSE))


###################################################
### code chunk number 3: smi.Rnw:34-41
###################################################
## add sex variable
women<-update(women,sex=0)
men<-update(men, sex=1)
## combine two sets of imputations
all<-rbind(women,men)
all
colnames(all)


###################################################
### code chunk number 4: smi.Rnw:45-46
###################################################
with(all, table(sex, drkfre))


###################################################
### code chunk number 5: smi.Rnw:49-52
###################################################
all<-update(all, drkreg=as.numeric(drkfre)>2)
## tables
with(all, table(sex, drkreg))


###################################################
### code chunk number 6: smi.Rnw:56-60
###################################################
## logistic regression model
model1<-with(all, glm(drkreg~wave*sex, family=binomial()))
MIcombine(model1)
summary(MIcombine(model1))


###################################################
### code chunk number 7: smi.Rnw:65-68
###################################################
beta<-MIextract(model1, fun=coef)
vars<-MIextract(model1, fun=vcov)
summary(MIcombine(beta,vars))