[R] How to find the likelihood, MLE and plot it?
C W
tmrsg11 at gmail.com
Wed Nov 18 23:31:07 CET 2015
Dear R list,
I am trying to find the MLE of the likelihood function. I will plot the
log-likelihood to check my answer.
Here's my R code:
xvec <- c(2,5,3,7,-3,-2,0)
fn <- function(theta){
sum(0.5 * (xvec - rep(theta, 7)) ^ 2 / 1 + 0.5 * log(1))
}
gn <- Vectorize(fn)
curve(gn, -5, 20)
optimize(gn, c(-5, 20))
$minimum
[1] 1.714286
$objective
[1] 39.71429
The MLE using optimize() is 1.71, but what curve() gives me is the absolute
minimum.
I think 1.71 is the right answer, but why does the graph showing it's the
minimum? What is going on here?
Thank so much!
[[alternative HTML version deleted]]
More information about the R-help
mailing list