You are on page 1of 4

HW1 in Stat 798L.

2/13/08

Extra Problem on Table 1.2, Sec. 4

Saved data in "Dialys.dat" together with 1 line of


column headers

> Dialys = read.table("Dialysis.dat", header=T)


> names(Dialys)
[1] "Time" "Status" "Placemt"
> dim(Dialys)
[1] 119 3
> table(Dialys$Status,Dialys$Placemt)
1 2
0 28 65
1 15 11

### Assignment was to "create a life table, with rows


corresponding to ordered increasing infection times
within each of the two ("Surgically Placed Catheter"
and "Percutaneous Placed Catheter") groups, showing
the number of "failures" (=infections) occurring at
that time, and the number at risk (ie individuals
within the group who are neither infected nor
censored before that time.

> Surg.Tbl = data.matrix(Dialys[Placemt==1,1:2])


Perc.Tbl = data.matrix(Dialys[Placemt==2,1:2])
Surg.Tbl = Surg.Tbl[order(Surg.Tbl[,"Time"]),]
Perc.Tbl = Perc.Tbl[order(Perc.Tbl[,"Time"]),]
Surg.Tbl = cbind(Surg.Tbl[,1:2], Risk=rep(1,nrow(Surg.Tbl)))
Perc.Tbl = cbind(Perc.Tbl[,1:2], Risk=rep(1,nrow(Perc.Tbl)))
### Get numbers of occurrences of each Time in each Table
Surg.Tbl = aggregate(Surg.Tbl[,2:3],list(time=Surg.Tbl[,1]),sum)
Perc.Tbl = aggregate(Perc.Tbl[,2:3],list(time=Perc.Tbl[,1]),sum)
Surg.Tbl[,3] = rev(cumsum(rev(Surg.Tbl[,3])))
Perc.Tbl[,3] = rev(cumsum(rev(Perc.Tbl[,3])))

> library(survival)
Loading required package: splines
> tmp1 = survfit(Surv(Time,Status), data=Dialys[Placemt==1,])
tmp2 = survfit(Surv(Time,Status), data=Dialys[Placemt==2,])

> Surg.Tbl

### agrees with: cbind(tmp1$time,tmp1$n.ev,tmp1$n.risk)

time Status Risk


1 1.5

1 43

2 2.5

0 42

3 3.5

1 40

4 4.5

2 36

5 5.5

1 33

6 6.5

0 31

7 7.5

0 29

8 8.5

2 25

9 9.5

1 22

10 10.5

1 20

11 11.5

1 18

12 12.5

0 16

13 13.5

0 14

14 14.5

0 13

15 15.5

1 11

16 16.5

1 10

17 18.5

1 9

18 21.5

0 8

19 22.5

0 6

20 23.5

1 4

21 25.5

0 3

22 26.5

1 2

23 27.5

0 1

> Perc.Tbl

### agrees with: cbind(tmp2$time,tmp2$n.ev,tmp2$n.risk)

time Status Risk


1 0.5

6 76

2 1.5

0 60

3 2.5

2 56

4 3.5

1 49

5 4.5

0 43

6 5.5

0 40

7 6.5

1 35

8 7.5

0 33

9 8.5

0 30

10 9.5

0 27

11 10.5

0 25

12 11.5

0 22

13 12.5

0 20

14 14.5

0 16

15 15.5

1 14

16 16.5

0 13

17 18.5

0 11

18 19.5

0 10

19 20.5

0 7

20 22.5

0 6

21 24.5

0 5

22 25.5

0 4

23 26.5

0 3

24 28.5

0 1

You might also like