我想用广义指数(GE)分布测试我的样本数据的接近程度。为此,我在R中使用ks测试。在ks.gen.exp(reliaR包)的文档中,给出了它:## alpha& amp; lambda使用'maxLik'包。来自R package reliaR的示例代码
## Load data sets
data(bearings)
## Estimates of alpha & lambda using 'maxLik' package
## alpha.est = 5.28321139, lambda.est = 0.03229609
ks.gen.exp(bearings, 5.28321139, 0.03229609, alternative = "two.sided", plot = TRUE)
有谁能告诉我如何使用maxLik包估算alpha(形状参数)和lambda(比例参数)?
答案 0 :(得分:2)
这不是最优雅的解决方案,但遵循?maxLik
中的示例,下面的代码就是这样的解决方案。请注意,方法“BFGS”可能(不)是最好的,但它在?ks.gen.exp
中复制了示例的结果。
loglik.genExp <- function(theta){
# Just incase you don't want to give the input names
if(is.null(names(theta))){
names(theta) <- c("alpha", "lambda")
}
# generate a numeric vector of probability densities from a general
# exponential distribution
rrgs <- c(list(x = z), as.list(theta))
l <- do.call("dgen.exp", rrgs)
# return the log-likelihood
sum(log(l))
}
# Assign your sample to the variable z
z <- bearings
maxLik(logLik = loglik.genExp, start = c(5.3, 0.03), method = "BFGS")