1

CoxPH 生存分析

次のような PPER (人期間) 形式のデータセットがあります。

Machine_id,Timestamp,Event,TDV1,TDV2,TDV3,TDV4 TDV1/2 は要因 (ブランド、場所) TDV3/4 は連続 (温度、湿度)

次のような SPELL 形式に変換する必要があります: Machine_id,start.time,stop.time,event,TDV1,TDV2,TDV3,TDV4

TraMineRextras で seqdef() & toPersonPeriod() を使用して SPELL から PPER に変換できました

逆を行うには助けが必要でした。また、PPER から SPELL 形式に移行する際に連続変数を処理する方法は?

4

1 に答える 1

0

人物期間データは、開始時刻と終了時刻が同じである呪文データの特殊なケースです。Timestamp変数を複製し、最初start.timeと 2 番目の名前を変更することで、スペル データを取得しますstop.time

おそらく、引数list=c(Machine_id, event, TDV1, TDV2, TDV3, TDV4)として使用してレコードを集約できます。byで 1 回、 で 1 回、2 回処理を進めるFUN="min"と、 と の共変量FUN="max"の値が変更されていない呪文の開始時刻と終了時刻を見つけることができるはずですevent

I illustrate here with an example

## creating example data
p.df <- data.frame(scan(what=list(Id=0, timestamp=0, event="", work="", income=0)))
1 2000 S working 100
1 2001 S working 100
1 2002 M working 100
1 2003 M working 100
1 2004 M jobless 80
1 2005 M jobless 70
2 2000 S jobless 10
2 2001 S working 100
2 2002 S working 100

## leave previous line blank to end scan

p.df$start <- p.df$timestamp
p.df$end <- p.df$timestamp
p.df <- p.df[,-2]  ## deleting timestamp variable

bylist <- list(id = p.df$Id, event=p.df$event,
      work=p.df$work, income=p.df$income)
spell1 <- aggregate(p.df[,c("start","end")], by=bylist, FUN="min")
spell2 <- aggregate(p.df[,c("start","end")], by=bylist, FUN="max")

## reordering columns
spell <- spell1[,c(1,5,6,2,3,4)]
spell[,3] <- spell2[,6] ## taking end value from spell2
spell <- spell[order(spell$id,spell$start),] ## sorting rows
spell

##   id start  end event    work income
## 5  1  2000 2001     S working    100
## 4  1  2002 2003     M working    100
## 3  1  2004 2004     M jobless     80
## 2  1  2005 2005     M jobless     70
## 1  2  2000 2000     S jobless     10
## 6  2  2001 2002     S working    100

お役に立てれば。

于 2015-05-05T21:06:07.800 に答える