我的概率分布函数是
f(x;r)=(1+r)/Γ(1/(1+r))exp(-x^(1+r)) , 0<x<Inf, r>-1
我正在使用以下代码:
library(stats4)
x3=c(0.927869895,0.000559193,0.059761785,0.361542986,0.274291999,0.563373589,
0.565878385,0.126281994,0.46623362,0.796111638,0.809460469,0.28011156,
0.263443012,0.704551045,0.978333171,0.139962088,0.599336759,0.108009066,
0.202133384,0.05401611)
nLL <- function(r)-sum(log(1+r)-log(gamma(1/(1+r)))-x3^(1+r))
fit0 <- mle(nLL, start = list(r = 0.1), nobs = NROW(x3))
fit1 <- mle(nLL, start = list(r = 0.1), nobs = NROW(x3),
method = "Brent", lower = -1, upper = 150)
stopifnot(nobs(fit0) == length(x3))
现在我想提取存储在fit1
. 我使用了以下命令
fitv = fit1$Coefficients
但是我无法获得该值,因为它给出了以下错误
fit1$Coefficients 中的错误:未为此 S4 类定义 $ 运算符
现在我得到了答案
nLL <- function(r)-sum(log(1+r)-log(gamma(1/(1+r)))-x1^(1+r))
fit0 <- mle(nLL, start = list(r = 0.1), nobs = NROW(x1))
fit1 <- mle(nLL, start = list(r = 0.1), nobs = NROW(x1),
method = "Brent", lower = -1, upper = 200)
stopifnot(nobs(fit0) == length(x1))
class(fit1)
str(fit1)
fiteg[k] = fit1@coef