有没有一种方法可以从coxme模型中获取事件概率?

时间:2020-02-29 16:23:28

标签: r survival lsmeans

对于给定的解释变量值和给定的时间步长,我想从Coxme模型获得事件概率的预测。我的数据结构如下:

# Generate data
set.seed(123)
mydata <- data.frame(Site = as.factor(sample(c("SiteA", "SiteB", "SiteC"), 1000, replace = TRUE)), 
                     Block = as.factor(sample(c("A", "B", "C", "D", "E", "F"), 1000, replace = TRUE)),
                     Treatment = as.factor(sample(c("Treat.A", "Treat.B"), 1000, replace = TRUE)),
                     Origin = as.factor(sample(c("Origin.A", "Origin.B"), 1000, replace = TRUE)),
                     Time = sample(seq(3), 1000, replace = TRUE), 
                     Surv = sample(c(0, 1), 1000, replace = TRUE)) # Alive is 0, death is 1

# Coxme model
mymodel <- coxme(Surv(Time , Surv) ~ Treatment*Origin + 
                   (1|Site/Block), data = mydata)

对于每种处理:原始组合,我想获得时间= 3时的预测生存可能性。如果我有一个Coxph模型(,没有随机影响),则可以通过生存包中的survfit轻松完成:

# use expand.grid to get a table with all possible combinations of Site and Treatment
newdata.surv <- with(mydata, expand.grid(Site = unique(Origin), Treatment = unique(Treatment)))

# run survfit to predict the new values
fitted <- survival::survfit(mymodel, newdata = newdata.surv)

# extract the fitted values for the time slice of interest: 3
newdata.surv$fit <- fitted$surv[3,]
newdata.surv$lower <- fitted$lower[3,] # Lower confidence interval
newdata.surv$upper <- fitted$upper[3,] # Upper confidence interval

但是,survfitcoxme object不兼容。我知道predict.coxme中存在coxme package,但是当我尝试使用它时,总是出现错误:“找不到函数“ predict.coxme”。我使用的是2.2-10

版本的coxme软件包,因此应该包括predict.coxme函数(请参见https://cran.r-project.org/web/packages/coxme/news.html)。

我已经看到coxmeemmeans软件包支持lsmeans对象,但是我不确定这些软件包是否可以用于预测生存期。在此先感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

<div class="row"> <div class="col-md-12 col-sm-12 col-xs-12 col-lg-12"> <div class="table-responsive"> <table class="table table-striped table-bordered table-hover general-journal-report-table" id="gj-report"> <thead class="thead-global"> <tr> <th id="pj_sequence">Sequence No.</th> <th id="pj_date">Posting Date</th> <th id="pj_op">Transaction No.</th> <th id="4">Document Reference</th> <th id="5">Remarks</th> <th id="6">Amount Due</th> </tr> </thead> <tbody class="general-journal-report-details"> @if($defined_gj) <?php $counter = 0; ;?> <?php $total_debit = 0; ?> @foreach($defined_gj as $key => $value) <?php $counter++;?> <?php $total_debit += $value->debit ;?> <tr> <td class="pj_sequence">{{$counter}}</td> <td class="pj_date">{{$value->posting_date}}</td> <td class="pj_op">{!! $value->number !!}</td> <td>{{$value->doc_ref}}</td> <td>{{$value->remarks}}</td> @if($value->debit == '0') <td></td> @else <td align="right"> {{number_format($value->debit,2)}}</td> @endif </tr> @endforeach <tr> <td><b>Total</b></td> <td></td> <td></td> <td></td> <td></td> <td align="right"> {{number_format($total_debit)}}</td> </tr> @endif </tbody> </table> </div> {{ $general_journals->links() }} </div> 函数本身并未导出,但是您可以使用coxme.predict来调用它,然后它将调用此方法(或者您可以直接调用predict(mymodel)(带有3个冒号)) 。简要说明,请参见coxme:::predict.coxme(mymodel)。看来它当前不支持newdata参数,因此我不确定它对您的用例有多有用。