繁体   English   中英

指数 function 的参数,最大似然为 R

[英]Parameters for Exponential function with maximum likelihood in R

我得到了一个样本数据,我试图获得基于最大似然计算的两参数指数 function 的参数。

我的样本:

sample = c(136.5,150,94.1,127.6,77.2,136.1,83.4,75.6,92.7,106.5,95.9,112.1,80.7,90.4,143.7,152.7,113.3,143.9,87.9,85.2,117.2,193,153.7,84.7,97.3,140.3,80,103.6,72.6,90.7,52.6,52.8)

我的主要目标是使用cdf或指数的quantile来获得最大似然性,就像这样:

GEV 示例:

library(nsRFA)

parameters <- ML_estimation(sample, dist = "GEV")
p = c(0.1,0.066667,0.05,0.04,0.033333,0.02,0.01,0.005,0.002,0.001,0.0002,0.0001)
q = invF.GEV(1-p, parameters[1], parameters[2], parameters[3]); q
> 149.4 158.8 165.2 170 173.9 184.3 197.6 210 225.4 236.2 258.9 267.7

两参数指数 function 是指数 function ,下端点位于xi 找到具有如此尖锐边界点的分布的 MLE 是一种特殊情况:边界的 MLE等于在数据集中观察到的最小值(参见例如这个 CrossValidated 问题)。 这使得二参数指数的 MLE 等效于x-xmin的指数分布的 MLE。

所以xi的 MLE 是

print(xi <- min(sample))
  1. 使用MASS::fitdistr
(m0 <- MASS::fitdistr(sample-xi, "exponential"))
      rate    
  0.018382353 
 (0.003249572)
  1. bbmle
m1 <- bbmle::mle2(y-xi~dexp(lambda), 
      data=data.frame(y=sample), start=list(lambda=1),
      method="Brent", lower=0.001, upper=100)
broom::tidy(m1, conf.int=TRUE, conf.method="profile")
  term   estimate std.error statistic      p.value conf.low conf.high
  <chr>     <dbl>     <dbl>     <dbl>        <dbl>    <dbl>     <dbl>
1 lambda   0.0184   0.00325      5.66 0.0000000154   0.0127    0.0255
  1. 解析解:
1/mean(sample-xi)
## [1] 0.01838235

如果您想要一个简单的 function 提供移位和比例参数(显然由您的替代软件提供):

est_twoexp <- function(x) {
   xi <- min(x)
   c(xi = xi, scale = mean(sample-xi))
}
est_twoexp(sample)
##    xi scale 
##  52.6  54.4 
est_twoexp <- function(x) {
   xi <- min(x)
   c(xi = xi, scale = mean(sample-xi))
}
est_twoexp(sample)
##    xi scale 
##  52.6  54.4 

绘图:

library(nsRFA)
ee <- ecdf(sample)
inv_ecdf <- approxfun(seq(0, 1, length=length(sample)),
                      sort(sample),
                      method="constant")
## homemade quantile function
q2exp <- function(p, xi, scale) {
  xi + qexp(p, rate=1/scale)
}
curve(inv_ecdf(x), from=0, to=1, type="s", ylim=c(40,250))
with(as.list(est_twoexp(sample)),
     curve( invF.exp (x, xi, scale), col=2, lwd=2, add=TRUE))
with(as.list(est_twoexp(sample)),
     curve( q2exp(x, xi, scale), col=4, lwd=2, lty= 2, add=TRUE))

带有family=Gammaglm不起作用,因为它不允许零值(在 Gamma 分布的一般族中, x==0仅具有正的、有限的指数分布密度)

暂无
暂无

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

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