calculating Kernel density for each column

조회 수: 6 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by