I'm fairly new to r, so I apologize if this answer is listed elsewhere. I've searched as best I could with my limited knowledge of what to search for.
I'm running a survival analysis simulation model with frailty using the parfm function and wish to run it multiple times while averaging one of the outputs. I've figured out how to reference values in outputs in all my other functions (using something like summary(output)$coef["group","coef"])) which doesn't seem to work for this one in any variation I've thought to try. I've listed the output below, the number I'm trying to reference is the 2.076 in the output below (bottom line of output next to "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
I've tried
> 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
with obviously no luck. I've listed the attributes below as this is what I've used in the past to find how to reference something. I've also listed a simplified version of the code I'm using below that. The output above is the result.
> 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"
Simulation Code
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
Any help is much appreciated!
First look at frail1 with str. Rather than being a list it is actually a matrix
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
So you just reference it with [:
> frail1[4,1]
#[1] 2.076003
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With