Hi!
I wonder why I cant create curve from given data from normal distribution and created function. I could make mistake calculating hes and grad, but the outcome is very close to mean. I use "maxLik" package.
Thanks for help,
regards
x = c(0.5677523, 0.8236657, 0.4568736, 0.5125185, 0.3192458)
N = length(x)
sigma2 = 1
sd = sqrt(1)
options(scipen=999)
lnL = function(mu){
l = -(N/2)*log(2*pi)-N*log(sd)-sum(x-mu)^2/2*sigma2
return(l)
}
grad = function(mu){
g = 1/sigma2*sum(x)-N*mu
return(g)
}
hes = function(mu){
h = N
}
solution= maxNR(fn=lnL, grad=grad, hess=hes, start = 0)
summary(solution)
curve(lnL(x), from=0, to= 0.8)
abline(v=solution$estimate, col="red")
(mu = sum(x)/N)