Code covered by the BSD License

# BioMedical EDU Webinar - Statistics and Curve Fitting

### Peter Perkins (view profile)

09 Oct 2003 (Updated )

Code and data used during the BioMedical EDU Webinar given on 10/8/03.

allCode.m
```% Copyright 2009 The MathWorks, Inc.

% This is the sequence of commands that were run during the BioMedical EDU
% Statistics and Curve Fittiing Webinar on 10/8/03.  It was run under
% R13sp1.

format short g

% === distribution plotting and fitting ===

% interactive tools
disttool
randtool

% load and plot the data
clear all
hist(medflies, .25:.5:6.25);
set(get(gca,'Children'),'FaceColor',[.9 .9 .9]);

% fit the data and plot the fit
[paramEsts,confInts] = gamfit(medflies)
[fitMean,fitVar] = gamstat(paramEsts(1), paramEsts(2))
yfit = gampdf(0:.01:7, paramEsts(1), paramEsts(2));
hold on, plot(0:.01:7, yfit*100*.5, '-'); hold off

% simulate new data
r = gamrnd(paramEsts(1), paramEsts(2), 1, 100)

% fit a kernel smooth and plot it
ysmooth = ksdensity(medflies, 0:.01:7);
hold on, plot(0:.01:7, ysmooth*100*.5, 'r'), hold off
legend('Parametric fit', 'Kernel smooth');

% bootstrap the parametric fit
b = bootstrp(500, 'gamfit', medflies);
b(1:10,:)
std(b)
qqplot(b(:,2));

% === testing ===

% load and plot the data
clear all
boxplot(flicker, color);

% one-way ANOVA and multiple comparison
[p,table,stats] = anova1(flicker, color);
[comparison,means] = multcompare(stats);

% === multivariate ===

% load and plot the data
clear all
gscatter(meas(:,1), meas(:,2), species)
xlabel('Sepal length'), ylabel('Sepal width')
gplotmatrix(meas, [], species, [], [], [], 'off')

% hierarchical cluster analysis
dist = pdist(meas, 'euclidean');
[h,nodeNum] = dendrogram(tree, 20);
species(nodeNum==8)'
species(ismember(nodeNum, [1 2 15 4]))'

% k-means clustering
[clustIdx,clustCtrs] = kmeans(meas,3,'dist','cos','rep',5);
clustCtrs

% parallel coordinates plot
edit plotClusts
plotClusts

% classification tree
t = treefit(meas, species);
treedisp(t,'names',{'SL' 'SW' 'PL' 'PW'});

% === curve fitting ===

clear all