In: Statistics and Probability
1. (a) Simulate a random sample of size 100 from the exponential distribution with the rate parameter λ = 10. Then make a histogram of the simulated data.
(b) We use the simulated data as a data set to construct the log-likelihood function as an R function. We will find the MEL of the value λ = 10. Choose the appropriate range for the parameter λ, then make a plot of the log-likelihood function.
(c) Use R function ‘optim‘ to find the MLE λˆ and its SE SE(λˆ). Then construct the 95% confidence interval of λ. Does the confidence interval include the true value λ = 10?
(a).
(b).
.
(c).
MLE of = 8.8735 and Standarad Error = 0.0113
95% confidence interval = (8.3977, 12.4922)
According to computed Interval we can say that this interval contains the true value of parameter.
R code:
##### Program to find MLE of lamda ##############
n =100
x = rexp(n, 0.1)
hist(x, main = "Histogram of generated samples", col =
"brown")
lamda = seq(1:10)
l_log = (n*log(lamda))-(lamda*sum(x))
plot(lamda, l_log, type = "l", col = "brown", main = "lamda Vs
Loglikelihood")
l_L = function(lamda){
-(n*log(lamda))+(lamda*sum(x))
}
mle = optim(1, l_L, )
mle
l = mean(x)-(1.96*(sqrt(mean(x)^2)/n));l
u = mean(x)+(1.96*(sqrt(mean(x)^2)/n));u
Output:
> ##### Program to find MLE of lamda ##############
> n =100
> x = rexp(n, 0.1)
> hist(x, main = "Histogram of generated samples", col =
"brown")
> lamda = seq(1:10)
> l_log = (n*log(lamda))-(lamda*sum(x))
> plot(lamda, l_log, type = "l", col = "brown", main = "lamda Vs
Loglikelihood")
>
> l_L = function(lamda){
+ -(n*log(lamda))+(lamda*sum(x))
+ }
> mle = optim(1, l_L )
$par
[1] 0.1126953
$value
[1] 318.2901
$counts
function gradient
36 NA
$convergence
[1] 0
$message
NULL
> l = mean(x)-(1.96*(sqrt(mean(x)^2)/n));l
[1] 8.397744
> u = mean(x)+(1.96*(sqrt(mean(x)^2)/n));u
[1] 12.49217