in reply to Re: Kernel Density Estimation
in thread Kernel Density Estimation

Hi. I looked at the CPAN module again and realized that the code was available for Epanechnikov:
0.75*(1-((x-m)/s)**2)/s if abs( (x-m)/s ) < 1 0 otherwise
However, I don't see what 'm' and 's' are if my only input is 'x'.

Replies are listed 'Best First'.
Re^3: Kernel Density Estimation
by cmr72 (Initiate) on Aug 30, 2012 at 13:13 UTC
    I took a stab at it thinking that 's' was the sum and 'm' was the previous value for 'x'

    I am pretty certain that this is incorrect.

    #!/usr/bin/perl -w use strict ; my %epan ; my @data ; my $sum ; while ( <STDIN> ) { my @line= split ; push (@data,$line[0]) ; } #Epanechnikov: 0.75*(1-((x-m)/s)**2)/s if abs( (x-m)/s ) < 1, otherwis +e 0 for ( my $i = 0 ; $i <= $#data ; $i++ ) { $sum+=$data[$i] ; if ($sum !=0 && abs(($data[$i]-$data[$i-1])/$sum) < 1) { $epan{$i}=0.75*(1-(($data[$i]-$data[$i-1])/$sum)**2)/$sum ; } else { $epan{$i} = 0 ; } } for ( my $i = 0 ; $i <= $#data ; $i++ ) { print "$data[$i] $epan{$i}\n" ; }