我有一个数据集,该数据集具有在Beta分布上分布的因果右检变量。请不要提供 flexsurv 软件包。有必要描述我的Beta分布的功能,以用于AFT回归生存模型 survreg 。来自the book M. Zhu的一个示例,我替换了我已知的函数,但无法描述Beta分布的密度函数的一阶和二阶导数之比:
# Beta Distribution - User-defined code for 'survreg'
a = 1.2; b = 0.2
myb <- list (name = "beta",
init = function (x, weights, ...)
{
mean <- sum (x * weights) / sum (weights)
var <- sum (weights * (x - mean) ^ 2) / sum (weights)
c (mean, var)
},
density = function (x, parms)
{
cbind (
pb (x, shape1 = a, shape2 = b, ncp = 0), # F - Cumulative Distribution Function
1 - pb (x, shape1 = a, shape2 = b, ncp = 0), # S = 1 - F - Survival Function
db (x, shape1 = a, shape2 = b, ncp = 0), # f - Density Function
?, # f'/ f - the first derivative of the Density function
? # f''/ f - the second derivative of the Density function
)
},
quantile = function (p, parms)
qb(x, shape1 = a, shape2 = b, ncp = 0),
deviance = function (...)
stop("deviance residuals not defined")
)
我认为这是由于基本包 r <中的beta
函数,gamma
函数,digamma
和trigamma
函数的派生所致/ strong>,但我的数学级别不允许应用它们。