我对r很新,所以如果在其他地方列出这个答案我会道歉。我凭借对搜索内容的有限知识,尽我所能进行了搜索。
我使用parfm函数运行一个脆弱的生存分析模拟模型,并希望在平均其中一个输出的同时多次运行它。我已经弄清楚如何在所有其他函数中引用输出中的值(使用诸如摘要(输出)$ coef [" group"," coef"]))在我想过要尝试的任何变体中似乎都不适合这个。我已经列出了下面的输出,我尝试引用的数字是下面输出中的2.076(&#34旁边的输出底线; gp2和#34;)。
>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
非常感谢任何帮助!
答案 0 :(得分:3)
首先使用str
查看frail1。它不是一个列表,而是一个矩阵
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