Home > wafo > kdetools > kdedemo1.m

kdedemo1

PURPOSE ^

Demonstrate the smoothing parameter impact on KDE

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 KDEDEMO1 Demonstrate the smoothing parameter impact on KDE 
  
  KDEDEMO1 shows the true density (dotted) compared to KDE based on 7 
  observations (solid) and their individual kernels (dashed) for 3 
  different values of the smoothing parameter, hs.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 %KDEDEMO1 Demonstrate the smoothing parameter impact on KDE 
002 % 
003 % KDEDEMO1 shows the true density (dotted) compared to KDE based on 7 
004 % observations (solid) and their individual kernels (dashed) for 3 
005 % different values of the smoothing parameter, hs. 
006  
007 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Matlab -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%% 
008 %% kdedemo1.m ---  
009 %% Author          : Per Andreas Brodtkorb 
010 %% Created On      : Sat Mar 06 10:54:08 2004 
011 %% Last Modified By: Per Andreas Brodtkorb 
012 %% Last Modified On: Sat Feb 05 10:53:14 2005 
013 %% Update Count    : 66 
014 %% Status          : Unknown, Use with caution! 
015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
016  
017  
018  
019   
020  
021  x      = linspace(-4,4); 
022  x0     = x/2; 
023  data   = wnormrnd(0,1,7,1); 
024  kernel = 'gaus'; 
025  hs     = hns(data); 
026  %hs     = hldpi(data,kernel); 
027  hVec   = [hs/2, hs, 2*hs] 
028     
029  kopt = kdeoptset('kernel','gaus'); 
030  for ix=1:3  
031    figure(ix) 
032    h = hVec(ix); 
033    kopt.hs = h; 
034    f2 = kde(data,kopt,x); 
035    pdfplot(f2,'k-') 
036    title(sprintf('h_s = %s', num2str(h,2))) 
037    ylabel('Density') 
038     
039    hold on 
040    plot(x,wnormpdf(x,0,1),'k:') 
041    n = length(data); 
042    plot(data,zeros(size(data)),'bx','Markersize',10) 
043    y = mkernel(x0,kernel)/(n*h);  
044    for i=1:n 
045      plot(data(i)+x0*h,y,'b--'); 
046      plot([data(i) data(i)], [0 max(y)],'b') 
047    end 
048    set(gca,'ytick',0:.1:0.5) 
049    axis([min(x),max(x), 0 0.5]) 
050    axis fill 
051    axis([min(x),max(x), 0 0.5]) 
052    hold off 
053    if (ix==3) 
054      xlabel('x') 
055    end 
056    %exportfig(gcf,sprintf('kdedemo1f%d.eps',ix),'height',2.5,'width',5); 
057  end 
058

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003