Plotting a histogram density estimator

Hello everyone,
Kindly assist me in writing a Matlab code to plot the histogram density estimator using Scott rule.
I tried the following but didnt get a result:
n=length(a); % sample size
s = std(a);
h = 3.5*s*(length(a)).^(-1/3);
% compute the skew factor (for histograms):
sf = ((2.^(1/3)).*s) / ( exp(5.*s.^2/4) .* ((s.^2 + 2).^(1/3)) .* (exp(s.^2) - 1).^(1/2) );
h = h*sf;
% get the limits, bins, bin centers etc:
x_lim_left = min(x)-1;
x_lim_rght = max(x)+1;
t0 = x_lim_left;
tm = x_lim_rght;
rng = tm-t0;
nbin = ceil(rng./h);
bins = t0:h:(nbin.*h+t0); % <- the bin edges ...
%bc = bins(1:end-1)+h./2; % <- the bin centers ...
x(x<x_lim_left)=x_lim_left;
x(x>x_lim_rght)=x_lim_rght;
vk=histc(x,bins); vk(end)=[];
% normalize:
fhat = vk/(n.*h);

1 comentario

Star Strider
Star Strider el 26 de Abr. de 2015
What do you mean by ‘didn’t get a result’?
I’m not certain where you’re your getting your expressions (I wasn’t aware of Scott’s paper until I went looking for it), but your expression for the skewness factor doesn’t resemble the expression on the top of page 6 (for the normal density).
Perhaps going into more detail will help. I’m not certain what you want to do.

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Preguntada:

el 25 de Abr. de 2015

Comentada:

el 26 de Abr. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by