calculating Kernel density for each column

1 回表示 (過去 30 日間)
Tino
Tino 2019 年 4 月 24 日
コメント済み: Rik 2019 年 4 月 24 日
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 件のコメント
Rik
Rik 2019 年 4 月 24 日
Instead of using numbered variables, why don't you process the columns in a loop?
Tino
Tino 2019 年 4 月 24 日
Yes but how do I do that ?

サインインしてコメントする。

採用された回答

Rik
Rik 2019 年 4 月 24 日
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 件のコメント
Tino
Tino 2019 年 4 月 24 日
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 2019 年 4 月 24 日
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?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeExploration and Visualization についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by