Introduction To Matlab Lecture Advanced Data Analysis Jan2012
Introduction To Matlab Lecture Advanced Data Analysis Jan2012
Lecture 11:
Graphics reveal
Data
4 sets of
{x,y} data
points
mean and
variance of {x}
and {y} is
equal
correlation
coefficient too
regression line,
and error of fit
using the line
are equal too
a2 = subplot(2,1,2)
Live demonstration
5
[x,y] = ginput(N)
Example - interpolation
x = 0:.6:pi;
y = sin(x);
xi = 0:.1:pi;
1
0.9
0.8
0.7
figure
0.6
yi =
interp1(x,y,xi,'cubic');0.5
0.4
yj =
interp1(x,y,xi,'linear');0.3
plot(x,y,'ko')
0.2
hold on
0.1
plot(xi,yi,'r:')
0
0
plot(xi,yj,'g.:')
data
cubic interpolation
linear interpolation
0.5
1.5
2.5
3.5
p w( j ) | y (:, j ) f ( x( j )) |2 (1 p ) (t ) | D 2 f (t ) |2 dt
j 1
150
Using diff() on
unsmoothed location data
100
csaps(x,y,p)
Experiment till you
find the right p to use
(the function can give
you an initial guess if Using diff() on
smoothed location data
you dont know where
to begin)
50
-50
-100
-150
1.468
1.47
1.472
1.474
1.476
1.478
10
Hypothesis testing
Random number
generators
12
Example
Implementing coin-flips in Matlab
p = rand(1);
If (p>0.5)
Do something
Else
Do something else
end
13
Histograms 1D
10 bins
0.4
0.3
0.2
Probability function
X=
randn(1,1000);
[C, N] = hist(X,
50);
bar(N,C/sum(C))
(N = location of
bins,
C = counts in
each location)
0.1
0
-4
-3
-2
-1
50 bins
0.08
0.06
0.04
[C, N] = hist(X,
10);
bar(N,C/sum(C))
0.02
0
-4
-3
-2
-1
Values
14
Histograms 2D
x = randn(1000,1);
y = exp(.5*randn(1000,1));
scatterhist(x,y)
15
Basic Characteristics of
your data:
mean
std
median
max
min
How to find the 25% percentile of your
data?
Y = prctile(X,25)
16
0.997
0.99
0.98
0.95
0.95
0.90
0.90
Probability
Probability
y = exprnd(10,100,1);
normplot(y)
0.75
0.50
0.25
0.75
0.50
0.25
0.10
0.10
0.05
0.05
0.02
0.01
0.02
0.01
10
Data
11
12
13
0.003
10
20
Data
30
40
17
18
Analysis of Variance
What is ANOVA?
In its simplest form ANOVA provides a statistical test of whether or not the means of several groups are all equal, and therefore generalizes t-test to more than two groups.
(Doing multiple two-sample t-tests would result in an increased chance of committing a type I error.)
20
14
7
12
17
14
16
11
9
7
13
12
18
7 19;
7 24;
4 19;
7 15;
12 10;
18 20]
P-value
Using
ANOV
A
Sums of squares
box plot()
Degrees of freedom
Confidence interval
mean squares (SS/df)
F statistic
25-75 percentiles
median
Data range
22
Using ANOVA
Many times it
comes handy to
perform multiple
comparisons on the
different data sets multcompare(stat
s)
Allows interactively
using the ANOVA
result
5
5
10
15
20
25
30
23
View Spectograms
Graphics Handles
Hierarchy
27
28
Reminder
set(gca,'Color','b')
get(h)
29
30
31
B
C
Subplot B)
define axes size and location inside the
figure
Load data, decide on plot type
and add supplementary items
(text, arrows etc.)
32
figure
set(gcf,'DefaultAxesFontSize',8);
set(gcf,'DefaultAxesFontName','helvetica');
set(gcf,'PaperUnits','centimeters','PaperPosi
tion',[0.2 0.2 8.3 12]); %[left, bottom,
width, height]
Many more options to control your general figure size
33
Plot
plotyy
Semilogx /
semilogy
Loglog
Area
Fill
Pie
bar/ barh
Stem
Errorbar
Polar / rose
Fplot / ezplot
Scatter
Image / imagesc
/pcolor/imshow
3D graphs:
Plot3
Pie3
Mesh / meshc /
meshz
Surf / waterfall /
surfc
Contour
Quiver
Fill3
Stem3
Slice
Scatter3
34
35
2D Plots
36
3D Plots
Positioning Axes
37
Subplot A)
define axes size and
location inside the
figure
Load data, decide on plot type and add
supplementary items (text, arrows
etc.)
line
arrow
doublearrow (two-headed arrow)
textarrow (arrow with attached text box), textbox
ellipse
Rectangle
Line attributes
Colors can
be picked
out from all
palette by
using [R G
B] notation
plot(x,y,'--rs','LineWidth',2, 'MarkerEdgeColor','k',...
'MarkerFaceColor','g', 'MarkerSize',10)
40
text( xlimits(1)-diff(xlimits)/2.8,
ylimits(1)+diff(ylimits)/2.0, {'\Delta Information',
'(bits/spike)'}, fontname', 'helvetica', 'fontsize', 7,
'rotation', 90, 'HorizontalAlignment', 'center' );
% Instead of using ylabel use a relative
placement technique
41
Greek Characters:
Math Symbols
\circ , \pm
Font
set(gcf,'CurrentAxes',h)
43
Example
% Prepare three plots on one figure x = -2*pi:pi/12:2*pi;
subplot(2,2,1:2)
plot(x,x.^2)
h1=subplot(2,2,3);
plot(x,x.^4)
h2=subplot(2,2,4);
plot(x, x.^5)
% Calculate the location of the bottom two -
p1 = get(h1,'Position');
t1 = get(h1,'TightInset');
p2 = get(h2,'Position');
t2 = get(h2,'TightInset');
x1 = p1(1)-t1(1); y1 = p1(2)-t1(2);
x2 = p2(1)-t2(1); y2 = p2(2)-t2(2);
w = x2-x1+t1(1)+p2(3)+t2(3); h = p2(4)+t2(2)+t2(4);
% Place a rectangle on the bottom two, a line on the top one
annotation('rectangle',[x1,y1,w,h],...
'FaceAlpha',.2,'FaceColor','red','EdgeColor','red');
line( [-8 8], [5 5], 'color', 'k', 'linewidth', 0.5 );
Margin
added to
Position to
include
labels and
title
44
Fig.1
Fig.2
46
47
Example making a
raster
plot
A = full(data_extracellular_A1_neuron__SparseMatrix); % convert from
sparse to full
% Plot a line on each spike location
[M, N] = size(A);
[X,Y] = meshgrid(1:N,0:M-1);
Locations_X(1,:) = X(:);
Locations_X(2,:) = X(:);
Locations_Y(1,:) = [Y(:)*4+1].*A(:);
Locations_Y(2,:) = [Y(:)*4+3].*A(:);
indxs = find(Locations_Y(1,:) ~= 0);
Locations_X = Locations_X(:,indxs);
Locations_Y = Locations_Y(:,indxs);
figure
line(Locations_X,Locations_Y,'LineWidth',4,'Color','k')
48
100
150
200
250
300
350
100
200
300
400
500
600
700
49
100
200
300
Time bin
400
500
600
700
50