简体   繁体   中英

get output of anova.rms into data.frame

I would like to get output of anova.rms into a data.frame.

library("rms")

# generate data taken from ?cph
n <- 1000
set.seed(731)
age <- 50 + 12*rnorm(n)
label(age) <- "Age"
sex <- factor(sample(c('Male','Female'), n,rep=TRUE, prob=c(.6, .4)))
cens <- 15*runif(n)
h <- .02*exp(.04*(age-50)+.8*(sex=='Female'))
dt <- -log(runif(n))/h
label(dt) <- 'Follow-up Time'
e <- ifelse(dt <= cens,1,0)
dt <- pmin(dt, cens)
units(dt) <- "Year"
dd <- datadist(age, sex)
options(datadist='dd')
S <- Surv(dt,e)

f <- cph(S ~ rcs(age,4)*sex, x=TRUE, y=TRUE)

anovaTable <- anova(f,main.effect=T,indnl=F)
# the table I want
anovaTable

data.frame(anovaTable) does not work because of the duplicate row names. I searched str(anovaTable), but it was not clear how to obtain it. Thanks.

您可以使用make.unique函数使行名称唯一。

as.data.frame(anovaTable, row.names = make.unique(rownames(anovaTable)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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