# R : Computing maximum likelihood estimator

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)

## Answers

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