Statistical basis - maximum likelihood estimation of software to solve

I. Introduction

Maximum likelihood estimation is an important parameter estimation method of mathematical statistics, but solving the maximum likelihood likelihood function is sometimes very difficult, in the article entitled to a maximum likelihood as an example. To show one yuan to solve the great problems of the likelihood function, and finally attach the code and explain.

Second, the title and deduced

Examples: a life of electronic components (unit: hour) Weibull distribution, the distribution of the probability density function is:
f ( x ; a , b ) = { a b a x a 1 e ( x b ) a , if  x  >0 0 , 其他 f(x;a,b)= \begin{cases} \frac{a}{b^a}x^{a-1}e^{-(\frac{x}{b})^a}, & \text {if $x$ >0} \\ 0, & \text{其他} \end{cases}
among them a a >0, b b > 0. Granted the a a = 2.5, which has a capacity of 101 sample size is as follows:
97.73,152.86,148.27,86.81,166.78,79.66,95.01,22.24,52.66,150.02
unknown parameters b b maximum likelihood estimation.

Answer: Write the title of the log-likelihood function
L = k = 1 10 l n ( f ( x i ; a , b ) ) = 10 a l n ( b ) k = 1 10 x i b a + C (C是与b无关的常数) \begin{aligned} L^* &\left.=\sum_{k=1}^{10}ln(f(x_i;a,b)) \right. \\ &\left.=-10aln(b) -\frac{\sum_{k=1}^{10}x_i}{b^a}+C \right.\text{(C是与b无关的常数)} \\ \end{aligned}
This problem becomes a matter of maximum points below this function.
L = 10 a l n ( b ) k = 1 10 x i b a \begin{aligned} L^* &\left.=-10aln(b) -\frac{\sum_{k=1}^{10}x_i}{b^a}\right. \\ \end{aligned} The following self with R language function to solve this problem.

Three, R language to solve

Results of operations

# 读入数据
data = c(96.73, 152.86, 148.27, 86.81, 166.78, 79.66,
95.01, 22.24, 52.66, 150.02)
# 自编函数
MLE <- function(a = 2.5, data){
  fun <- function(b){
    -10*a*log(b)-sum(data)/(b^a)
  }
  optim(50, fun, method = "CG")$par
}
# 函数调用
> MLE(a = 2.5, data = data)
[1] 86.30949

The end result is 86.309

optim function introduction

This function title is too long, just put the parameters section. Detailed usage reference optim function help documentation.

function (par, fn, gr = NULL, ..., method = c("Nelder-Mead", 
    "BFGS", "CG", "L-BFGS-B", "SANN", 
    "Brent"), lower = -Inf, upper = Inf, control = list(), 
    hessian = FALSE) 

Just say here that a parameter method, usually selected "BFGS", "CG" in two ways.

Released seven original articles · won praise 31 · views 9704

Guess you like

Origin blog.csdn.net/weixin_46111814/article/details/105307362