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

Person-period 数据只是开始和结束时间相同的拼写数据的一个特例。您可以通过复制Timestamp变量并重命名第一个start.time和第二个来获得拼写数据stop.time

可能,您可以使用list=c(Machine_id, event, TDV1, TDV2, TDV3, TDV4)asby参数来聚合您的记录。继续进行两次,一次是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 回答