Question

I want to compute maximum likelihood estimator of mean,mu, of normal distribution with variance=36.

But the following procedure showing error:

set.seed(36)

x <- rnorm(50,mean=20,sd=6)

loglikelikelihood<- function(mu,x){
 L = (-50)*log(sqrt(2*pi)*6)-((1/72)*(sum(x^2)-2*mu*sum(x)+50*mu^2))
 }

optimize(f=loglik,X=x,interval=c(0,100),maximum=T)
Was it helpful?

Solution

you misspelled two arguments. Try writing loglikelihood instead of loglik and x instead of X, it'll work.

> optimize(f=loglikelihood,x=x,interval=c(0,100),maximum=T)
$maximum
[1] 20.86679

$objective
[1] -157.6814
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top