简体   繁体   English

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

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

I got a sample data and i'm trying to obtain the parameters for two-parameter exponential function calculed based on maximum likelihood.我得到了一个样本数据,我试图获得基于最大似然计算的两参数指数 function 的参数。

My sample:我的样本:

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)

My main goal is to use the cdf or quantile of exponential for maximum likelihood, just like that:我的主要目标是使用cdf或指数的quantile来获得最大似然性,就像这样:

Example with GEV: 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

The two-parameter exponential function is an exponential function with a lower endpoint at xi .两参数指数 function 是指数 function ,下端点位于xi Finding MLEs of distributions with such sharp boundary points is a bit of a special case: the MLE for the boundary is equal to the minimum value observed in the data set (see eg this CrossValidated question ).找到具有如此尖锐边界点的分布的 MLE 是一种特殊情况:边界的 MLE等于在数据集中观察到的最小值(参见例如这个 CrossValidated 问题)。 That makes the MLE of the two-parameter exponential equivalent to the MLE of the exponential distribution for x-xmin .这使得二参数指数的 MLE 等效于x-xmin的指数分布的 MLE。

So the MLE of xi is所以xi的 MLE 是

print(xi <- min(sample))
  1. With MASS::fitdistr :使用MASS::fitdistr
(m0 <- MASS::fitdistr(sample-xi, "exponential"))
      rate    
  0.018382353 
 (0.003249572)
  1. with bbmle :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. Analytical solution:解析解:
1/mean(sample-xi)
## [1] 0.01838235

If you want a simple function that provides the shift and scale parameters (as apparently provided by your alternative software):如果您想要一个简单的 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 

Plotting:绘图:

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))

glm with family=Gamma doesn't work because it doesn't allow zero values (within the general family of Gamma distributions, x==0 only has a positive, finite density for the exponential distribution)带有family=Gammaglm不起作用,因为它不允许零值(在 Gamma 分布的一般族中, x==0仅具有正的、有限的指数分布密度)

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

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