[R] maximum-likelihood-estimation with mle()
Ronald Kölpin
ronald.koelpin at gmail.com
Fri Sep 11 14:20:12 CEST 2015
Hi everyone,
I have a problem with maximum-likelihood-estimation in the following
situation:
Assume a functional relation y = f(x) (the specific form of f should be
irrelevant). For my observations I assume (for simplicity) white noise,
such that hat(y_i) = f(x_i) + epsilon_i, with the epsilon_i iid N(0,
sigma^2). Y_i should then be N(f(x_i), sigma^2)-distributed and due to
the iid assumption the density of Y = (Y_1, ..., Y_n) is simply the
product of the individual densities, taking the log gives the the sum of
the log of individual densities.
I tried coding this in R with a simple example: f(x) = a*x + b (simple
linear regression). This way I wanted to compare the results from my
ml-estimation (specifying the log-likelihood manually and estimating
with mle()) with the results from using lm(y~x). In my example however
it doesn't work:
x <- 1:10
y <- 3*x - 1 + rnorm(length(x), mean=0, sd=0.5)
library("stats4")
nLL <- function(a, b, sigma)
{
-sum(dnorm(y, mean=a*x+b, sd=sigma, log=TRUE))
}
fit <- mle(nLL1, start=list(a=0, b=0, sigma=1), nobs=length(y))
summary(lm(y~x))
summary(fit)
These should be the same but the aren't. I must have made some mistake
specifying the (negative) log-likehood (but I just don't see it). I also
actually don't care much (at the moment) for estimating sigma but I
don't know of a way to specify (and estimate) the (negative)
log-likelihood without estimating sigma.
Thanks a lot
and kind regards
Ronald Koelpin
More information about the R-help
mailing list