2014-09-05 58 views
3

我对r相当陌生,所以我很抱歉如果这个答案在其他地方列出。我尽可能地用有限的知识搜索了什么。参考输出值

我使用parfm函数运行具有脆弱性的生存分析仿真模型,并希望在平均其中一个输出的同时多次运行它。我已经想出了如何在输出中引用所有其他函数中的值(使用类似summary(输出)$ coef [“group”,“coef”]))的东西,这对任何变体都不起作用我曾想过尝试。我列出了下面的输出,我试图引用的数字是下面的输出中的2.076(输出的底行“gp2”旁边)。

>frail1 

Frailty distribution: inverse Gaussian 
Baseline hazard distribution: Weibull 
Loglikelihood: -90.577 

     ESTIMATE SE p-val  
theta 0.043 0.524   
rho 1.185 0.228   
lambda 0.162 0.046   
gp2 2.076 0.423 0 

我已经试过

> names(frail1) 
NULL 


> coef(frail1) 
Error: $ operator is invalid for atomic vectors 


> names(summary(frail1)) 
NULL 


> summary(frail1)$coefficients 
Error in summary(frail1)$coefficients : 
    $ operator is invalid for atomic vectors 

有明显没有运气。我列出了下面的属性,因为这是我以前用来找到如何引用某些东西的东西。我还列出了我在下面使用的代码的简化版本。上面的输出是结果。

> attributes(frail1) 
$dim 
[1] 4 3 

$dimnames 
$dimnames[[1]] 
[1] "theta" "rho" "lambda" "gp2" 

$dimnames[[2]] 
[1] "ESTIMATE" "SE"  "p-val" 


$class 
[1] "parfm" "matrix" 

$call 
parfm(formula = Surv(time, event) ~ gp, cluster = "id", data = d1, 
    dist = "weibull", frailty = "ingau") 

$convergence 
[1] 0 

$it 
function 
     84 

$extime 
user.self 
    13.69 

$nobs 
[1] 100 

$shared 
[1] FALSE 

$loglik 
[1] -67.13683 

$dist 
[1] "weibull" 

$dq 
[1] 56 

$frailty 
[1] "ingau" 

$clustname 
[1] "id" 

$correct 
[1] 0 

$formula 
[1] "Surv(time, event) ~ gp" 

$terms 
[1] "gp" 

模拟程序

library(cmprsk) 
library(statmod) 
library(parfm) 

set.seed(0) 

shp <- 1 #weibull shape parameter 
ns1 <- 50 #group 1 sample size 
ns2 <- ns1 #group 2 sample size 
hr11 <- 1 #group 1 hazard 
hr21 <- 2 #group 2 hazard 
frl <- 1 #frailty 
alpha1 <- 2 
nsim <- 1 #number of simulations 


frail <- matrix(1,nsim,1) 


id <- seq(1,ns1+ns2) 

if(frl==1){ 
g1et <- matrix(rweibull(ns1,shape=shp,scale=1/(hr11*rinvgauss(1,1,alpha1))),ns1,1) 
} else { 
g1et <- matrix(rweibull(ns1,shape=shp,scale=1/hr11),ns1,1) 
} 
g2et <- matrix(rweibull(ns2,shape=shp,scale=1/hr21),ns2,1) 


time <- c(g1et,g2et) 


gp <- factor(c(matrix(1,ns1,1),matrix(2,ns2,1)),1:2,c(1,2)) #create treatment groups 

event <- matrix(round(runif(ns1+ns2,0,1),0),ns1+ns2,1) #select first event type 

d1 <- data.frame(id,gp,time,event) 

frail1 <- parfm(Surv(time,event)~gp, cluster="id", data=d1, dist="weibull", frailty = "ingau") 

frail1 

任何帮助,非常感谢!

回答

3

首先看看fragil1与str。而不是一个列表它实际上是一个矩阵

str(frail1) 
parfm [1:4, 1:3] 0.043 1.185 0.162 2.076 0.524 ... 
- attr(*, "dimnames")=List of 2 
    ..$ : chr [1:4] "theta" "rho" "lambda" "gp2" 
    ..$ : chr [1:3] "ESTIMATE" "SE" "p-val" 
snipped all the rather long list of attributes 

所以你只是[引用它:

> frail1[4,1] 
    #[1] 2.076003 
+0

真棒!非常感谢。这正是我需要的。 – 2014-09-05 19:23:48

+0

此外,更多的打字,但更明确地说,你可以做'frail1 ['gp2','ESTIMATE']' – Jota 2014-09-05 19:25:31

+1

并感谢你有一个记录良好的问题和演示新的生存分析包,试图了解。 – 2014-09-05 19:26:15