You are on page 1of 2

AST231_L5_MLE

Mohaimen Mansur

Estimation (MLE estimators)

# MLE estimators of parameters of Normal Distribution

set.seed(1001)
n <- 100
x <- rnorm(n, mean = 3, sd = 2)
hist(x)

Histogram of x
30
25
20
Frequency

15
10
5
0

−4 −2 0 2 4 6 8 10

mean(x)

## [1] 2.998305

sd(x)

## [1] 2.288979

1
sqrt((n-1)/n)*sd(x) # MLE of sigma

## [1] 2.277506

LL <- function(mu, sigma) {


R = dnorm(x, mu, sigma)
-sum(log(R))
}

mle(minuslogl=LL, start = list(mu = 1, sigma=1), options(warn = -1))

##
## Call:
## mle(minuslogl = LL, start = list(mu = 1, sigma = 1), optim = options(warn = -1))
##
## Coefficients:
## mu sigma
## 2.998305 2.277506

# MLE estimators of parameters of Bernoulli Distribution


set.seed(1001)
N <- 50
x <- rbinom(N,1,0.3)
mean(x) # sample proportion of success

## [1] 0.36

LL3 <- function(p) {


R = dbinom(x, 1, p)
-sum(log(R))
}

mle(LL3, start = list(p=0.1))

##
## Call:
## mle(minuslogl = LL3, start = list(p = 0.1))
##
## Coefficients:
## p
## 0.3600002

# Exercise: Find the MLE of parameters for Poisson, Exponential and Gamma distributions.

You might also like