calculating Kernel density for each column
Afficher commentaires plus anciens
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 commentaires
David Wilson
le 24 Avr 2019
Would ksdensity work? (From stats toolbox)
Rik
le 24 Avr 2019
This is what I have done so far and the answers are below
thanks
n = 6;
K = 3;
h1 = 1.06 * var(Z(:,1)) * (n ^ 0.2);
h2 = 1.06 * var(Z(:,2)) * (n ^ 0.2);
h3 = 1.06 * var(Z(:,3)) * (n ^ 0.2);
h4 = 1.06 * var(Z(:,4)) * (n ^ 0.2);
z1 = 1/ (n * h1);
z2 = 1/ (n * h2);
z3 = 1/ (n * h3);
z4 = 1/ (n * h4);
Ec11 = (K * (v1 - Z(1,1))/h1) ;
Ec12 = (K * (v1 - Z(2,1))/h1) ;
Ec13 = (K * (v1 - Z(3,1))/h1) ;
Ec14 = (K * (v1 - Z(4,1))/h1) ;
Ec15 = (K * (v1 - Z(5,1))/h1) ;
Ec16 = (K * (v1 - Z(6,1))/h1) ;
e1 = [Ec11; Ec12; Ec13; Ec14; Ec15; Ec16];
e1 = sum (e1);
Ec21 = K * (v2 - Z(1,2)/h2);
Ec22 = (K * (v2 - Z(2,2))/h2) ;
Ec23 = (K * (v2 - Z(3,2))/h2) ;
Ec24 = (K * (v2 - Z(4,2))/h2) ;
Ec25 = (K * (v2 - Z(4,2))/h2) ;
Ec26 = (K * (v2 - Z(4,2))/h2) ;
e2 = [ Ec21; Ec22; Ec23; Ec24; Ec25; Ec26];
e2 = sum (e2);
Ec31 = K * (v3 - Z(1,3)/h3);
Ec32 = (K * (v3 - Z(2,3))/h3) ;
Ec33 = (K * (v3 - Z(3,3))/h3) ;
Ec34 = (K * (v3 - Z(4,3))/h3) ;
Ec35 = (K * (v3 - Z(5,3))/h3) ;
Ec36 = (K * (v3 - Z(6,3))/h3) ;
e3 = [Ec31; Ec32; Ec33; Ec34; Ec35; Ec36];
e3 = sum (e3);
Ec41 = K * (v4 - Z(1,4)/h4);
Ec42 = (K * (v4 - Z(2,4))/h4) ;
Ec43 = (K * (v4 - Z(3,4))/h4) ;
Ec44 = (K * (v4 - Z(4,4))/h4) ;
Ec45 = (K * (v4 - Z(5,4))/h4) ;
Ec46 = (K * (v4 - Z(6,4))/h4) ;
e4 = [Ec41; Ec42; Ec43; Ec44; Ec45; Ec46];
e4 = sum(e4);
k = e1;
l = e2;
m = e3;
b = e4;
% the kernal density estimation
KDE1 = k * z1;
KDE2 = l * z2;
KDE3 = m * z3;
KDE4 = b * z4;
answer
-0.4881
-0.1668
-0.7734
-0.3972
Rik
le 24 Avr 2019
Instead of using numbered variables, why don't you process the columns in a loop?
Tino
le 24 Avr 2019
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!