- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 10498 个
- 通用积分
- 369.2883
- 学术水平
- 160 点
- 热心指数
- 169 点
- 信用等级
- 124 点
- 经验
- 274346 点
- 帖子
- 237
- 精华
- 1
- 在线时间
- 520 小时
- 注册时间
- 2007-4-27
- 最后登录
- 2024-12-6
|
已经找到解决办法,采用多阶段模型(MSM)可以完成该任务。MSM不仅能计算不同状态之间的转换概率
详细的编码如下:
- library(msm)
- ## Simulated data
- N1 <- 9900 # number of subjects from stage A to A
- N2 <- 500 # number of subjects from stage A to B
- N3 <- 600 # number of subjects from stage B to C
- data <- data.frame(
- rbind(
- cbind((rep(1:N1,
- each=2)),rep(1),rep(c(0,5))), # subjects from stage A to A
- cbind((rep((N1+1):(N1+N2),
- each=2)),rep(c(1,2)),rep(c(0,5))), # subjects from stage A to B
- cbind((rep((N1+N2+1):(N1+N2+N3),
- each=2)),rep(c(2,3)),rep(c(0,5))) # subjects from stage B to C
- )
- )
- ## change variable names
- names(data)[1:3] <- c("ID", "status", "time" )
- ## check the frequency table between different stages
- statetable.msm(status, ID, data=data)
- ## set arbitrary initial values for transition intensities
- ini.q <- rbind(c(1, 1, 0), c(0, 1, 1), c(0, 0, 0))
- ## calculate crude initial values for transition intensities
- ini.q <- crudeinits.msm(status ~ time, ID, data=data, qmatrix=ini.q)
- ini.q
- ## develop multi-state model with initial values for transition intensities
- scr.msm <- msm(status ~ time, ID, data=data, qmatrix=ini.q, deathexact = 3)
- scr.msm
- ## show transition intensities matrix
- qmatrix.msm(scr.msm)
- ## show transition probability matrix for 1 year
- pmatrix.msm(scr.msm, t=1)
- ## show sojourn times
- sojourn.msm(scr.msm)
复制代码
其中pmatrix.msm(scr.msm, t=1)的输出结果即为问题的答案:
- State 1 State 2 State 3
- State 1 0.9902232 0.009095594 0.0006812451
- State 2 0.0000000 0.864167214 0.1358327863
- State 3 0.0000000 0.000000000 1.0000000000
复制代码也即,A向B的转化概率为 0.009095594,B向C的转换概率为0.1358327863。
注意根据该问题构建的多阶段模型中有一个非常重要的隐形Markov过程:A不能跳过B直接到C,C只能从B转换过来。具体详细原理参考msm 程序包的帮助,^_^
|
|