简体   繁体   English

R 中带有插补数据集的精细和灰色模型

[英]Fine and Gray model in R with imputed datasets

I have a long (vertically stacked) dataset containing 10 imputations (variable "imputation" identifies imputation number).我有一个包含 10 个插补(变量“插补”标识插补数)的长(垂直堆叠)数据集。 The imputation was done in SAS but I would like to calculate some c-statistics using R.插补是在 SAS 中完成的,但我想使用 R 计算一些 c 统计量。

I know how to calculate c-stats using cindex function and FGR function for one imputed dataset.我知道如何使用 cindex 函数和 FGR 函数为一个估算数据集计算 c-stats。 I am not sure how I will repeat this in the vertically stacked dataset.我不确定我将如何在垂直堆叠的数据集中重复这一点。 I tried to use "with" function but no luck.我尝试使用“with”功能,但没有运气。

Here are my codes:这是我的代码:

fgr.model <- FGR(Hist(time, outcome) ~ x1 + x2 + x3, data=mydata1, cause=1)

cscore <- cindex(list(fgr.model), forumula=Hist(time, outcome)~1,
          cens.model="marginal", data=mydata1, eval.time=c(1826), cause=1)

How to calculate c-stats using cindex function and FGR function in the vertically stacked dataset?如何在垂直堆叠的数据集中使用 cindex 函数和 FGR 函数计算 c-stats?

Based on details in the comments: I understood that you need to calculate stats on a partition of the original dataframe mydata1 --ie, you need to select only the rows that correspond to one "imputation" (this is the name you use, are you referring with a wrong word to an.. 'input session'? just curious)根据评论中的详细信息:我知道您需要计算原始数据mydata1 mydata1 的分区上的统计信息——即,您只需要选择与一个“插补”相对应的行(这是您使用的名称,是你用错误的词指代..“输入会话”?只是好奇)

First you have to create a new dataframe containing only the data for one "imputation", in the following examples we consider the operation for the imputation number 4. There are different ways to make the job done.首先,您必须创建一个仅包含一个“插补”数据的新数据框,在下面的示例中,我们考虑插补数 4 的操作。有不同的方法可以完成这项工作。

First way that works if columns names are right:如果列名正确,则第一种工作方式:

mydata1portion = mydata1[mydata1$ImputationNo==4,]

Second that works if position/order of columns are right:如果列的位置/顺序正确,则第二个工作:

mydata1portion = mydata1[mydata1$V1==4,]

Third way in the case the dataframe imputations/rows are ordered.在数据帧插补/行被排序的情况下的第三种方式。

mydata1portion = mydata1[(100*(4-1)+1):(100*4),]

The first two you use the value for the column ImputationNo in order to filter the dataframe, in the last one you cut the dataframe based on the position of the rows.前两个您使用列ImputationNo的值来过滤数据框,在最后一个您根据行的位置剪切数据框。

Finally you can calculate the stats on the obtained mydata1portion and NOT on the full mydata1 .最后,您可以计算获得的mydata1portion的统计数据,而不是完整的mydata1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM