[R] Kernel density estimation - problem with matrix created in loop

Brocker84 V.Brocker at web.de
Thu Sep 30 15:52:26 CEST 2010


Hi you all!

I have a very serious problem. 
What I am going to do is a kernel density estimation (Nadaraya-Watson) but
without any helping packages. I want to do it on my own and just use R as a
calculator. 
The problem is that the matrix which I need does not seem to be calculated
correctly in my loop. 
This matrix is created by the multiplication of a vector and its
transponent. But before it becomes multiplicated with a kernel term. 

Just let me show this:

A=matrix(0,nrow=22,ncol=22)
temp=matrix(0,nrow=22,ncol=22)
for (i in 1:1473)
{
vectora=c(X_1[i],X_2[i],X_3[i],X_4[i],X_5[i],X_6[i],X_7[i],X_8[i],X_9[i],X_10[i],X_11[i],X_12[i],X_13[i],X_14[i],X_15[i],X_16[i],X_17[i],X_18[i],X_19[i],X_20[i],X_21[i],X_22[i])
vectorb=t(c(X_1[i],X_2[i],X_3[i],X_4[i],X_5[i],X_6[i],X_7[i],X_8[i],X_9[i],X_10[i],X_11[i],X_12[i],X_13[i],X_14[i],X_15[i],X_16[i],X_17[i],X_18[i],X_19[i],X_20[i],X_21[i],X_22[i]))
temp=(3/(4*h))*(1-((i/T - u)/h)^2)*vectora%*%vectorb
Anw=A+temp
}

This is the problem part, the part with the matrix. You see that it is a
22x22 matrix. Each vector has got more than 1000 elements. Thus there are
more than one thousand of those matrices. And "temp" is the command in which
each of those matrices should be multiplicated with the "i"-corresponding
calue of (3/(4*h))*(1-((i/T - u)/h)^2) [Epanechnikov kernel].
And with "Anw=A+temp" finally there should be only a sum. And it is a sum, a
22x22matrix. But I cannot continue with my work because in the formula I
have to use this I have to invert this matrix before. And this does not
work. The determinant is said as being 0. 
I am sure that I am wrong with something. Can someone help me?? 
-- 
View this message in context: http://r.789695.n4.nabble.com/Kernel-density-estimation-problem-with-matrix-created-in-loop-tp2720793p2720793.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list