% Todd McDevitt's Lab: Circularity Data
%
% In order to elucidate the differences between ``static'' and ``rotary" culture, 
% embrionic bodies (EBs) were formed under both conditions with equal starting 
% cell densities. After 2, 4 and 7 days of culture, images of EBs were acquired 
% using phase-contrast microscopy. Image analysis software was used to 
% determine the circularity (defined as 4 pi [Area/Perimeter^2]) of each 
% EB imaged.  n=325 EBs were analyzed from three separate plates for both 
% static and rotary cultures at the three time points studied. The area and
% circularity data was used to examine differences in the size and shape of
% EBs formed under the two conditions as well as differences in the variability
% of both size and shape
%
%PREAMBLE
close all
clear all
 disp('Univariate Data: Circularity of Cells from the Lab of Todd McDevitt')
 lw = 3; 
 set(0, 'DefaultAxesFontSize', 16);
 fs = 15;
 msize = 10;
load('C:\BESTAT\Descriptive\Descriptivedat\circ.mat')
circc = 1 - circ; %deviation from circularity
%
size(circc)
%
r2 = circc(:,1); %rotation treatment, 2 days
s2 = circc(:,4); %static treatment, 2 days
%
% measures of location
%
meanr2 = mean(r2)
means2 = mean(s2)
gmeanr2 = geomean(r2)
gmeans2 = geomean(s2)
hmeanr2 = harmmean(r2)
med = median(r2)
%  trimmean(r2, 100) gives an error, but
tmean1 = trimmean(r2, 99.99) % gives the median
tmean2 = trimmean(r2, 0) %gives the ordinary mean -- no trimming
mean(r2) %check
[mo fre] = mode(r2)
%
% measures of variability/spread
%------------------
stdr2 = std(r2)          %by default flag=0, i.e., std(r2,0)
srd1r2 = std(r2, 1)   %flag 1 stands for division by n
format long
std(r2)
std(r2, 1)
format short
varr2 = var(r2, 1)
ranr2 = range(r2)
mad0 = mad(r2)
mad1 = mad(r2,1)
realmad = 1/0.6745 * mad(r2,1) % compare to std(r2)
%
% missing values NaN
r2nan=r2;
r2nan([2 32 200 321])= NaN;
m1 = mean(r2nan)
m2 = nanmean(r2nan)
nmax = nanmax(r2nan)
nsum = nansum(r2nan)
%
% quantiles/percentiles
qts = quantile(r2,[0.1 0.25 0.5 0.75 0.9])
prts = prctile(r2,[10 25 50 75 90])
%
% FIGURES 
%BOX PLOT
figure(1)
% boxplot of r2 and s2
boxplot([r2 s2],'notch','on','labels',{'rotation 2 days','static 2 days'})
%print -depsc 'C:\Brani\Courses\bmestatu\Fall2007\ccirc1.eps'

%BACK TO BACK HISTOGRAM
figure(2)
% back to back histogram with 30 bins
bihist(r2, s2, 30)
%print -depsc 'C:\Brani\Courses\bmestatu\Fall2007\ccirc2.eps'

% KERNEL-SMOOTHED DENSITY ESTIMATOR
% (SMOOTHED HISTIGRAM)
figure(3)
[f,x,u] = ksdensity(r2);
plot(x,f)
title('Density estimate for r2')
hold on
[f,x] = ksdensity(r2,'width',u/4);
plot(x,f,'r');
[f,x] = ksdensity(r2,'width',u*4);
plot(x,f,'g');
legend('default width','default/4','4 * default')
plot(r2, zeros(size(r2)), 'b+');
hold off
%print -depsc 'C:\Brani\Courses\bmestatu\Fall2007\ccirc3.eps'



