calculating Kernel density for each column
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi
Please how do I need a short code that will calculate the KDE of each column in the R.length data below
the KDE is given as = I/n*h sum ( K * (( v - i )/h) which is computed for each column
where h = 1.06 * variance * (n^(-0.2)) for each colum
n is the number of each column
i = first, second, third, fourth, fifth, sixth number of each column
v =pv is given as 3, 4, 5, 6 for each column
Thanks in advance
jonathan
R = [ 0.6164 3.4161 0.9950 3.4117;
3.1654 0.4123 4.2391 1.0198;
0.5745 3.0364 1.3191 3.1129;
2.9883 0.7348 3.8730 0.4123;
0.9381 3.3749 2.0421 3.5014;
2.1817 1.0630 3.0643 0.9487];
5 comentarios
Rik
el 24 de Abr. de 2019
Instead of using numbered variables, why don't you process the columns in a loop?
Respuesta aceptada
Rik
el 24 de Abr. de 2019
I am assuming the v values are the same as the column index, and that you made a mistake with the code for the second column.
Z = [ 0.6164 3.4161 0.9950 3.4117;
3.1654 0.4123 4.2391 1.0198;
0.5745 3.0364 1.3191 3.1129;
2.9883 0.7348 3.8730 0.4123;
0.9381 3.3749 2.0421 3.5014;
2.1817 1.0630 3.0643 0.9487];
n = 6;
K = 3;
z=zeros(1,size(Z,2));e=zeros(size(z));
for col=1:size(Z,2)
v=col;%is this what you mean?
h = 1.06 * var(Z(:,col)) * (n ^ 0.2);
z(col) = 1/ (n * h);
E = K * (v - Z(:,col))/h;
if col~=1
%did you mean for this to be different?
E(1)= K * (v - Z(1,col)/h);
end
e(col) = sum(E) ;
end
% the kernal density estimation
KDE = e .* z;
2 comentarios
Rik
el 24 de Abr. de 2019
Well, you know the inputs, you have working code, you should be able to integrate the calculation in my code. What issues are you having with that integration?
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!