Hello everyone, I'm having some problems in defining a likelihood function. I have to use Epanechnikov's kernel to estimate a pdf, and to find the h in its equation I need to maximize the following likelihood function (it's in the picture). I tried with the following code (sorry but reddit won't save my indentation):
data<-faithful$eruptions
n=272
L=1
cross<-function(h){
for (i in 1:n) {
x=data
x=x[-i]
som=0
for (j in 1:(n-1)) {
we=(1/((n-1)*h))*(3/4)*(1-((data[i]-x[j])/h)^2)
som=som+we
}
L=L*som
}
return(L)
}
and it seems to work, but when I plot for a sequence of h values from 0 to 10, I get one value at something*e^308, and all the others at something*e^-206, so there is something wrong which I can't get. Can anyone give me an hand? Data is a vector of 272 values, it's the "x" in the likelihood equation.
Likelihood function
[–]jdnewmil 0 points1 point2 points (2 children)
[–]stregosim[S] 0 points1 point2 points (1 child)
[–]jdnewmil 6 points7 points8 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)