% DENPLOT.M: procedure to compute univariate kernel density estimator % of a vector of data and then plot results % calls kdensity.m to compute kernel density estimate at points % to be plotted % % John Rust, University of Maryland, November, 2011 % % % inputs: % % vname: string variable, name of variable (in memory) which % comprises that data to be used to sstimate a density % pmin: lower end point of an interval to plot estimated density % pmax: upper end point of an interval to plot estimated density % n: number of points (equally spaced) between pmin and pmax % at which estimated density is plotted % % implicit global inputs % % kerneltyp: type of kernel density to use in the density estimation % % epanechnikov % gaussian function denplot(vname,pmin,pmax,n); data=evalin('base',vname); x=(pmin:(pmax-pmin)/n:pmax)'; kde=kdensity(x,data); plot(x,kde); title(sprintf('Kernel density plot of %s',vname)); axis([pmin pmax 0 max(kde)]); ylabel('Density'); xlabel(vname); locfac=.05; text(pmin+locfac*(pmax-pmin),max(kde)*.9,['Mean ' num2str(mean(data))]); text(pmin+locfac*(pmax-pmin),max(kde)*.85,['Median ' num2str(median(data))]); text(pmin+locfac*(pmax-pmin),max(kde)*.8,['Minimum ' num2str(min(data))]); text(pmin+locfac*(pmax-pmin),max(kde)*.75,['Maximum ' num2str(max(data))]); text(pmin+locfac*(pmax-pmin),max(kde)*.7,['Std dev ' num2str(std(data))]); text(pmin+locfac*(pmax-pmin),max(kde)*.65,['N ' num2str(size(data,1))]);