简体   繁体   English

生成/绘制对数正态生存函数

[英]Generating/plotting a log-normal survival function

I have an accelerated failure time model in SAS LIFEREG that I'd like to plot. 我在SAS LIFEREG中有一个加速故障时间模型,我想绘制。 Because SAS is to profoundly bad at graphing, I'd like to actually re-generate the data for the curves in R and plot them there. 因为SAS在绘图时非常糟糕,所以我想实际重新生成R中曲线的数据并将其绘制在那里。 SAS puts out a scale (in the case of the exponential distribution fixed to 1), an intercept, and a regression coefficient for being in the exposed or unexposed population. SAS推出了一个量表(在指数分布固定为1的情况下),截距和回归系数,用于暴露或未暴露的人口。

There's two curves, one for the exposed and one for the unexposed population. 有两条曲线,一条用于暴露,一条用于未暴露的人口。 One of the models is an exponential distribution, and I've produced the data and graph like so: 其中一个模型是指数分布,我已经生成了数据和图形,如下所示:

intercept <- 5.00
effect<- -0.500
data<- data.frame(time=seq(0:180)-1)
data$s_unexposed <- apply(data,1,function(row) exp(-(exp(-intercept))*row[1]))
data$s_exposed <- apply(data,1,function(row) exp(-(exp(-(intercept+effect))*row[1])))

plot(data$time,data$s_unexposed, type="l", ylim=c(0,1) ,xaxt='n',
     xlab="Days since Infection", ylab="Percent Surviving", lwd=2)
axis(1, at=c(0, 20, 40, 60, 80, 100, 120, 140, 160, 180))
lines(data$time,data$s_exposed, col="red",lwd=2)
legend("topright", c("ICU Patients", "Non-ICU Patients"), lwd=2, col=c("red","black") )

Which gives me this: 这给了我这个:

在此输入图像描述

Not the prettiest graph ever, but I don't really know my way around ggplot2 enough to spruce it up. 不是最漂亮的图表,但我真的不知道我的方式围绕ggplot2足以修饰它。 But more importantly, I have a second set of data that comes from a Log Normal distribution, rather than an exponential, and my attempts to generate the data for that have failed utterly - the incorporation of the cdf for the normal distribution and the like puts it beyond my R skills. 但更重要的是,我有一个来自Log Normal分布的第二组数据,而不是指数,我为此生成数据的尝试完全失败了 - 将cdf用于正态分布等等put它超越了我的R技能。

Anyone able to point me in the right direction, using the same numbers, and a scale parameter of 1? 任何人都可以指向正确的方向,使用相同的数字,并且比例参数为1?

The survival function at time t for a log-normal model can be represented in R with 1 - plnorm() , where plnorm() is the log-normal cumulative distribution function. 对数正态模型在时间t的生存函数可以用R表示,其中1 - plnorm() ,其中plnorm()是对数正态累积分布函数。 To illustrate, we'll first put your plot into a function for convenience: 为了说明,我们首先将您的绘图放入函数中以方便:

## Function to plot aft data
plot.aft <- function(x, legend = c("ICU Patients", "Non-ICU Patients"),
    xlab = "Days since Infection", ylab="Percent Surviving", lwd = 2,
    col = c("red", "black"), at = c(0, 20, 40, 60, 80, 100, 120, 140, 160, 180),
        ...)
{
    plot(x[, 1], x[, 2], type = "l", ylim = c(0, 1), xaxt = "n", 
            xlab = xlab, ylab = ylab, col = col[2], lwd = 2, ...)
    axis(1, at = at)
    lines(x[, 1], x[, 3], col = col[1], lwd=2)
    legend("topright", legend = legend, lwd = lwd, col = col)
}

Next, we'll specify the coefficients, variables, and models, and then generate the survival probabilities for the exponential and log-normal models: 接下来,我们将指定系数,变量和模型,然后生成指数和对数正态模型的生存概率:

## Specify coefficients, variables, and linear models
beta0 <- 5.00
beta1 <- -0.500
icu <- c(0, 1)
t <- seq(0, 180)
linmod <- beta0 + (beta1 * icu)
names(linmod) <- c("unexposed", "exposed")

## Generate s(t) from exponential AFT model
s0.exp <- dexp(exp(-linmod["unexposed"]) * t)
s1.exp <- dexp(exp(-linmod["exposed"]) * t)

## Generate s(t) from lognormal AFT model
s0.lnorm <- 1 - plnorm(t, meanlog = linmod["unexposed"])
s1.lnorm <- 1 - plnorm(t, meanlog = linmod["exposed"])

Finally, we can plot the survival probabilities: 最后,我们可以绘制生存概率:

## Plot survival
plot.aft(data.frame(t, s0.exp, s1.exp), main = "Exponential model")
plot.aft(data.frame(t, s0.lnorm, s1.lnorm), main = "Log-normal model")

And the resulting figures: 由此产生的数字:

指数模型

对数正态模型

Note that 注意

plnorm(t, meanlog = linmod["exposed"])

is the same as 是相同的

pnorm((log(t) - linmod["exposed"]) / 1) 

which is the Φ in the canonical equation for the log-normal survival function: S(t) = 1 − Φ((ln(t) − µ) / σ) 这是对数正态生存函数的正则方程中的Φ:S(t)= 1 - Φ((ln(t) - μ)/σ)

As I'm sure you know, there are a number of R packages that can handle accelerated failure time models with left, right, or interval censoring, as listed in the survival task view , in case you happen to develop a preference for R over SAS. 我相信你知道,有很多R软件包可以处理带有左,右或区间审查的加速故障时间模型,如生存任务视图中所列,以防你碰巧开发出R的偏好SAS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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