简体   繁体   English

R中Gamma密度的最大似然估计

[英]Maximum Likelihood Estimator for a Gamma density in R

I just simulated 100 randoms observations from a gamma density with alpha(shape parameter)=5 and lambda(rate parameter)=5 : 我只是使用alpha(形状参数)= 5和lambda(速率参数)= 5来模拟伽马密度的100个randoms观测值:

x=rgamma(100,shape=5,rate=5)

Now, I want to fin the maximum likelihood estimations of alpha and lambda with a function that would return both of parameters and that use these observations. 现在,我想用一个函数返回alpha和lambda的最大似然估计,该函数将返回两个参数并使用这些观察。

Any hints would be appreciate. 任何提示都会很感激。 Thank you. 谢谢。

You can use fitdistr(...) for this in the MASS package. 您可以在MASS包中使用fitdistr(...)

set.seed(1)   # for reproducible example
x <- rgamma(100,shape=5,rate=5)

library(MASS)
fitdistr(x, "gamma", start=list(shape=1, rate=1))$estimate
#    shape     rate 
# 6.603328 6.697338 

Notice that with a small sample like this you don't get great estimates. 请注意,对于这样的小样本,您无法获得很好的估计。

x <- rgamma(10000,shape=5,rate=5)
library(MASS)    # may be loaded by default
fitdistr(x, "gamma", start=list(shape=1, rate=1))$estimate
#    shape     rate 
# 4.984220 4.971021 

fitdistr(...) also returns the standard error of the estimates and the log-likelihood. fitdistr(...)也返回估计的标准误差和对数似然。

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

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