calculating Kernel density for each column

2 views (last 30 days)
Tino
Tino on 24 Apr 2019
Commented: Rik on 24 Apr 2019
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 Comments
Rik
Rik on 24 Apr 2019
Instead of using numbered variables, why don't you process the columns in a loop?

Sign in to comment.

Accepted Answer

Rik
Rik on 24 Apr 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 Comments
Tino
Tino on 24 Apr 2019
Hi Rik
The v values are numbers obtained from a different computation below
strangeness1 = 0.25541
strangeness2 = 4.4465
strangeness3 = 0.38976
strangeness4 = 4.2112
using Si = [strangeness1,strangeness2, strangeness3, strangeness4];
% find the v-values
fnP=@(a,i)(sum(a(i)>a(1:i))+0.5*sum(a(i)==a(1:i)))/i;
Thanks in advance
Regards
Jonathan
Rik
Rik on 24 Apr 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?

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!