Download presentation
Presentation is loading. Please wait.
1
Stat Final Lab
2
Q1a: Write down the log likelihood function.
Find the density f of xi first by taking the 1st derivative of the cdf F. Take the natural log of f
3
Density f of xi: Natural log f of xi: Log likelihood of all observed data:
4
rweibull(n, shape=a, scale=b)
Q1b: For n=200, write R code to generate data from the Weibull distribution with α=2.3. Then comput the MLE of α by using ‘optim’ in R. In R, use rweibull(n, shape=a, scale=b) to generate data from the Weibull distribution. Check the definition of the Weibull distribution in R by ?rweibull because the density of the Weibull defined in R may be different from the Weibull density in our assignment.
5
f(x) = (a/b) (x/b)^(a-1) exp(- (x/b)^a)
In R, the Weibull distribution with shape parameter a and scale parameter b has density given by f(x) = (a/b) (x/b)^(a-1) exp(- (x/b)^a) for x >= 0. The cdf is F(x) = 1 - exp(- (x/b)^a) on x >= 0, E(X) = b Gamma(1 + 1/a) Var(X) = b^2 * (Gamma(1 + 2/a) - (Gamma(1 + 1/a))^2). Compare with the definition of the cdf of the Weibull distribution in our assignment. where x > 0. α=a=shape, 1/5=b=scale
6
α=a=shape, 1/5=b=scale Use ‘optim’ to find the MLE of α. n = 200
alpha=2.3 beta=1/5 x = rweibull(n, shape=alpha, scale=beta) Log likelihood of all observed data: Use ‘optim’ to find the MLE of α. f=function(y) { h=n*log(y)+(y-1)*sum(log(5*x))-5^y*sum(x^y) } Then use optim(par, f), where par is an initial value for the parameters to be optimized over.
7
a1 = optim(2, f, method = "BFGS")$par
f=function(y) { h=n*log(y)+(y-1)*sum(log(5*x))-5^y*sum(x^y) } -h optim(par, fn, …) par: Initial values for the parameters to be optimized over. fn: A function to be minimized. a1 = optim(2, f, method = "BFGS")$par Get the MLE from “optim”:
8
Problems!! The approximate 95% C.I. for α is where
Q1c and d: Find an approximate 95% C.I. for α. where Problems!! The approximate 95% C.I. for α is
9
Natural log f of X:
10
Shit!! ? Natural log f of X: The 1st derivative of the log f:
The Fisher information at the MLE: The Observed Fisher information at the MLE: Shit!! has no closed form. How to find ? Even we know the closed form, then how to find ? The 2nd derivative of the log f:
11
where z0.975 is the 97.5th quantile of the standard normal density and
12
# MLE of alpha a1 = optim(2, f, method = "BFGS")$par # Observed Fisher Information I1= (a1)^(-2)+ 5^(a1)*mean(x^(a1)*(log(5*x))^2) # 1.96 is (approximately) the 97.5th quantile of standard normal sd1 =1.96*sqrt(1/(n*I1)) # The approximate 95% C.I. for alpha CIa =c(a1-sd1, a1+sd1 ) CIa
13
lambda1=optim(6, f2, method="BFGS")$par # Ques 2d:
# Ques 2a: n =200 x =rweibull(n,2.3,1/5) f2 =function(lambda) { h=n*log(2.3)+n*2.3*log(lambda)+(1.3)*sum(log(x))-lambda^(2.3)*sum(x^(2.3)) -h } # MLE of lambda lambda1=optim(6, f2, method="BFGS")$par # Ques 2d: # Observed Fisher Information I2 = 2.3/(lambda1)^2+2.3*(2.3-1)*(lambda1)^(2.3-2)*mean(x^2.3) sd2=1.96*((n*I2)^(-1/2)) # The approximate 95% C.I. for alpha CIlambda = c(lambda1-sd2, lambda1+sd2) CIlambda
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.