I was trying to obtain mles of the scale and shape parameter for the weibull distribution using the optim function.

The code is as follows:

weibull_data= rweibull(1000,shape=2,scale=3)

log_lik_weibull=function(par,obs_data){

n=length(obs_data)

a=par[1]

b=par[2]

n*(log(a)-log(b))+(a-1)*(sum(log(obs_data))-n*log(b))-(a/b)*

sum(obs_data)

}

optim(c(1,1),log_lik_weibull,obs_dat=weibull_data,control = list(fnscale=-1))$par

This gives parameter estimates of 0.86, 2.63 which is significantly different from my shape and scale parameters.

I feel the log likelihood function is correct however I am not able to obtain reliable estimates.

Any help will be appreciated.