如何绘制具有危险无线电,死亡概率或y轴死亡率的受限三次样条?

时间:2015-07-21 22:44:35

标签: r plot logistic-regression spline cox-regression

1)在下面的例子中,如何将y轴更改为“比值比”,“死亡概率”和“适合”的“死亡率”?

2)在下面的例子中,如何将y轴更改为“fit2”的“风险比”?

library(Hmisc)
library(survival)
library(rms)

data(pbc)
d <- pbc
rm(pbc)
d$died <- ifelse(d$status == 2, 1, 0)
d$status <- ifelse(d$status != 0, 1, 0)

ddist <- datadist(d)
options(datadist='ddist')

fit <- lrm(status ~ rcs(age, 4), data=d)
(an <- anova(fit))
plot(Predict(fit), anova=an, pval=TRUE)

fit2 <- cph(Surv(time, status) ~  rcs(age, 4), data=d)
(an2 <- anova(fit2))
plot(Predict(fit2), anova=an, pval=TRUE)

我期待着你的帮助!

更新1 在BondedDust的回答之后,我想到了以下内容:

# probability
getProbability <- function(x) {
     exp(x)/(1+exp(x))*100
}

fit <- lrm(status ~ rcs(age, 4), data=d)
(an <- anova(fit))
plot(Predict(fit, fun=getProbability), anova=an, pval=TRUE, ylab="Probability of death [%]")

# overall probability to die
table(d$status)
round(table(d$status)[[2]]/sum(table(d$status))*100, digits=1) # = 44.5%

由于死亡的总概率是44.5%,预测概率的计算和得出的情节似乎对我来说是非统计学家的,不是吗?

1 个答案:

答案 0 :(得分:2)

如果你想要赔率,那么你需要添加一个$(function() { $(document).on('click', 'button', function(e) { e.preventDefault(); var idname= $(this).attr('id'); //Here: $('button') should be $(this) alert (idname); }); }); - 参数来转换为优势比例:

fun=

我不确定我是否知道plot(Predict(fit,fun=exp), anova=an, pval=TRUE, ylab="Odds ratio") 的意思。逆logit函数是changing to the "probability of mortality", and "mortality rate" for "fit"但是为了根据系数构造事件或速率的估计,您需要合并截距项。也许您可以从拟合对象的拟合值组件中提取有用的东西,以满足您的作业问题的要求。

exp(x)/(1+exp(x))

与用于将对数概率系数转换为优势比的方法相同,用于将对数危险转换为危险比:

> names(fit)
 [1] "freq"              "sumwty"            "stats"             "fail"             
 [5] "coefficients"      "var"               "u"                 "deviance"         
 [9] "est"               "non.slopes"        "linear.predictors" "penalty.matrix"   
[13] "info.matrix"       "weights"           "call"              "Design"           
[17] "scale.pred"        "terms"             "assign"            "na.action"        
[21] "fail"              "interceptRef"      "nstrata"          
> str(fit$linear.predictors)
 Named num [1:418] -0.187 -0.235 0.41 -0.24 -0.538 ...
 - attr(*, "names")= chr [1:418] "1" "2" "3" "4" ...