First matlab codes for statistics
This commit is contained in:
parent
6cf7d01663
commit
92ed818419
25
statistics/code/quartiles.m
Normal file
25
statistics/code/quartiles.m
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
% generate data:
|
||||||
|
x = randn( 1, 100000 );
|
||||||
|
|
||||||
|
% histogram:
|
||||||
|
[h,b] = hist( x, 100 );
|
||||||
|
% normalize:
|
||||||
|
bs = b(2)-b(1);
|
||||||
|
h = h/sum(h)/bs;
|
||||||
|
|
||||||
|
% plot:
|
||||||
|
bar( b, h );
|
||||||
|
xlabel( 'x' );
|
||||||
|
|
||||||
|
% median, quartile:
|
||||||
|
xs = sort( x )
|
||||||
|
q = [ xs(length(xs)/4), xs(length(xs)/2), xs(3*length(xs)/4) ];
|
||||||
|
%q = quantile( x, [0.25, 0.5, 0.75 ] );
|
||||||
|
|
||||||
|
% plot:
|
||||||
|
bar( b(b<q(1)), h(b<q(1)), 'FaceColor', [0.5 0 0.5] );
|
||||||
|
hold on;
|
||||||
|
bar( b((b>=q(1)) & (b<q(2))), h((b>=q(1)) & (b<q(2))), 'FaceColor', [0.9 0 0] );
|
||||||
|
bar( b((b>=q(2)) & (b<q(3))), h((b>=q(2)) & (b<q(3))), 'FaceColor', [0 0 0.9] );
|
||||||
|
bar( b(b>=q(3)), h(b>=q(3)), 'FaceColor', [0.5 0 0.5] );
|
||||||
|
hold off;
|
6
statistics/code/randomwalk.m
Normal file
6
statistics/code/randomwalk.m
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
function x = randomwalk(n,p)
|
||||||
|
r = rand(n,1);
|
||||||
|
r(r<p) = -1.0;
|
||||||
|
r(r>=p) = +1.0;
|
||||||
|
x = cumsum(r);
|
||||||
|
end
|
25
statistics/code/randomwalkstatistics.m
Normal file
25
statistics/code/randomwalkstatistics.m
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
p = 0.5;
|
||||||
|
nsteps = 100;
|
||||||
|
nwalks = 1000;
|
||||||
|
|
||||||
|
y = zeros( nwalks, nsteps/10 );
|
||||||
|
for k = 1:length( y )
|
||||||
|
x = randomwalk( nsteps, p );
|
||||||
|
for j = 1:nsteps/10
|
||||||
|
y(k,j) = x((j-1)*10+1);
|
||||||
|
end
|
||||||
|
%plot( x )
|
||||||
|
%pause( 1 )
|
||||||
|
if rem(k,100) == 0
|
||||||
|
%[h1,b1] = hist( y(1:k,1), [-50:2:50] );
|
||||||
|
%[h2,b2] = hist( y(1:k,2), [-50:2:50] );
|
||||||
|
%bar( b1, h1, 1.0, 'b' );
|
||||||
|
%hold on;
|
||||||
|
%bar( b2, h2, 'FaceColor', 'r' );
|
||||||
|
%hold off;
|
||||||
|
sdev = var( y(1:k,:), 1 );
|
||||||
|
plot( sdev )
|
||||||
|
pause( 1.0 );
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -89,108 +89,190 @@
|
|||||||
\tableofcontents
|
\tableofcontents
|
||||||
\end{frame}
|
\end{frame}
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
\section{Descriptive statistics}
|
\section{Descriptive statistics}
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
\subsection{types of data}
|
\subsection{Statistics of ratio data}
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
||||||
|
|
||||||
|
%-------------------------------------------------------------
|
||||||
\begin{frame}
|
\begin{frame}
|
||||||
\frametitle{data scales}
|
\frametitle{Statistics of ratio data}
|
||||||
\framesubtitle{What data types are distinguished in statistics?}
|
|
||||||
\Large
|
|
||||||
{\bf Why are data types important?}
|
|
||||||
\pause
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item selection of statistics
|
\item Location, central tendency
|
||||||
\item selection of plots
|
\begin{itemize}
|
||||||
\item selection of correct tests
|
\item arithmetic mean
|
||||||
|
\item median
|
||||||
|
\item mode
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
\item Spread, dispersion
|
||||||
|
\begin{itemize}
|
||||||
|
\item variance
|
||||||
|
\item standard deviation
|
||||||
|
\item interquartile range
|
||||||
|
\item coefficient of variation
|
||||||
|
\item minimum, maximum
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
\item Shape
|
||||||
|
\begin{itemize}
|
||||||
|
\item skewnees
|
||||||
|
\item kurtosis
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
\item Dependence
|
||||||
|
\begin{itemize}
|
||||||
|
\item Pearson correlation coefficient
|
||||||
|
\item Spearman's rank correlation coefficient
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
%-------------------------------------------------------------
|
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
\subsection{Data types}
|
||||||
|
|
||||||
|
%-------------------------------------------------------------
|
||||||
\begin{frame}
|
\begin{frame}
|
||||||
\frametitle{data scales}
|
\frametitle{Data types: nominal scale}
|
||||||
\framesubtitle{nominal/categorial scale}
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item properties like cell type, experimental group (i.e. treatment
|
\item Binary
|
||||||
1, treatment 2, control)
|
\begin{itemize}
|
||||||
\item each observation/sample is put into one category
|
\item ``yes/no'',
|
||||||
\item there is no reasonable order among the categories
|
\item ``true/false'',
|
||||||
\item example: [rods, cones] vs. [cones, rods]
|
\item ``success/failure'', etc.
|
||||||
|
\end{itemize}
|
||||||
|
\item Categorial
|
||||||
|
\begin{itemize}
|
||||||
|
\item cell type (``rod/cone/horizontal cell/bipolar cell/ganglion cell''),
|
||||||
|
\item blood type (``A/B/AB/0''),
|
||||||
|
\item parts of speech (``noun/veerb/preposition/article/...''),
|
||||||
|
\item taxonomic groups (``Coleoptera/Lepidoptera/Diptera/Hymenoptera''), etc.
|
||||||
|
\end{itemize}
|
||||||
|
\item Each observation/measurement/sample is put into one category
|
||||||
|
\item There is no reasonable order among the categories.\\
|
||||||
|
example: [rods, cones] vs. [cones, rods]
|
||||||
|
\pause
|
||||||
|
\item Statistics: mode, i.e. the most common item
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
%-------------------------------------------------------------
|
|
||||||
|
|
||||||
|
%-------------------------------------------------------------
|
||||||
\begin{frame}
|
\begin{frame}
|
||||||
\frametitle{data scales}
|
\frametitle{Data types: ordinal scale}
|
||||||
\framesubtitle{ordinal scale}
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item like nominal scale, but there is an order
|
\item Like nominal scale, but with an order
|
||||||
\item {\bf but:} there is no reasonable measure of {\em distance}
|
\item Examples: ranks, ratings
|
||||||
|
\begin{itemize}
|
||||||
|
\item ``bad/ok/good'',
|
||||||
|
\item ``cold/warm/hot'',
|
||||||
|
\item ``young/old'', etc.
|
||||||
|
\end{itemize}
|
||||||
|
\item {\bf But:} there is no reasonable measure of {\em distance}
|
||||||
between the classes
|
between the classes
|
||||||
\item examples: ranks, ratings
|
\pause
|
||||||
|
\item Statistics: mode, median
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
%-------------------------------------------------------------
|
|
||||||
|
|
||||||
|
%-------------------------------------------------------------
|
||||||
\begin{frame}
|
\begin{frame}
|
||||||
\frametitle{data scales}
|
\frametitle{Data types: interval scale}
|
||||||
\framesubtitle{interval scale}
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item quantitative/metric values
|
\item Quantitative/metric values
|
||||||
\item reasonable measure of distance between values but no absolute zero
|
\item Reasonable measure of distance between values, but no absolute zero
|
||||||
\item examples: temperature in $^\circ$C
|
\item Examples:
|
||||||
|
\begin{itemize}
|
||||||
|
\item Temperature in $^\circ$C ($20^\circ$C is not twice as hot as $10^\circ$C)
|
||||||
|
\item Direction measured in degrees from magnetic or true north
|
||||||
|
\end{itemize}
|
||||||
|
\pause
|
||||||
|
\item Statistics:
|
||||||
|
\begin{itemize}
|
||||||
|
\item Central tendency: mode, median, arithmetic mean
|
||||||
|
\item Dispersion: range, standard deviation
|
||||||
|
\end{itemize}
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
%-------------------------------------------------------------
|
|
||||||
|
|
||||||
|
%-------------------------------------------------------------
|
||||||
\begin{frame}
|
\begin{frame}
|
||||||
\frametitle{data scales}
|
\frametitle{Data types: absolute/ratio scale}
|
||||||
\framesubtitle{absolut/ratio scale}
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item like interval scale but with absolute zero
|
\item Like interval scale, but with absolute origin/zero
|
||||||
\item example: temperature in $^\circ$K
|
\item Examples:
|
||||||
\end{itemize}
|
\begin{itemize}
|
||||||
|
\item Temperature in $^\circ$K
|
||||||
|
\item Length, mass, duration, electric charge, ...
|
||||||
|
\item Plane angle, etc.
|
||||||
|
\item Count (e.g. number of spikes in response to a stimulus)
|
||||||
|
\end{itemize}
|
||||||
\pause
|
\pause
|
||||||
%\begin{emphasize}{relationsships between scales}
|
\item Statistics:
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item scales exhibit increasing information content from nominal
|
\item Central tendency: mode, median, arithmetic, geometric, harmonic mean
|
||||||
to absolute
|
\item Dispersion: range, standard deviation
|
||||||
\item conversion ,,downwards'' always possible
|
\item Coefficient of variation (ratio standard deviation/mean)
|
||||||
|
\item All other statistical measures
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
%\end{emphasize}
|
\end{itemize}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
|
|
||||||
%-------------------------------------------------------------
|
%-------------------------------------------------------------
|
||||||
\begin{frame}
|
\begin{frame}
|
||||||
\frametitle{examples from neuroscience and psychology}
|
\frametitle{Data types}
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item {\bf nominal:}\pause
|
\item Data type selects
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item treatment group
|
\item statistics
|
||||||
\item stimulus class
|
\item type of plots (bar graph versus x-y plot)
|
||||||
\item cell type
|
\item correct tests
|
||||||
|
\end{itemize}
|
||||||
|
\item Scales exhibit increasing information content from nominal
|
||||||
|
to absolute.\\
|
||||||
|
Conversion ,,downwards'' is always possible
|
||||||
|
\item For example: size measured in meter (ratio scale) $\rightarrow$
|
||||||
|
categories ``small/medium/large'' (ordinal scale)
|
||||||
|
\end{itemize}
|
||||||
|
\end{frame}
|
||||||
|
|
||||||
|
%-------------------------------------------------------------
|
||||||
|
\begin{frame}
|
||||||
|
\frametitle{Examples from neuroscience}
|
||||||
|
\begin{itemize}
|
||||||
|
|
||||||
|
\item {\bf absolute:}\pause
|
||||||
|
\begin{itemize}
|
||||||
|
\item size of neuron/brain
|
||||||
|
\item length of axon
|
||||||
|
\item ion concentration
|
||||||
|
\item membrane potential
|
||||||
|
\item firing rate
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
\item {\bf interval:}\pause
|
||||||
|
\begin{itemize}
|
||||||
|
\item edge orientation
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
\item {\bf ordinal:} \pause
|
\item {\bf ordinal:} \pause
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
|
\item stages of a disease
|
||||||
\item ratings
|
\item ratings
|
||||||
\item clinical stages of a disease
|
|
||||||
\item states of an ion channel
|
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\item {\bf Absolut-/Ratioskala:}\pause
|
|
||||||
|
\item {\bf nominal:}\pause
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item firing rate
|
\item cell type
|
||||||
\item membrane potential
|
\item odor
|
||||||
\item ion concentration
|
\item states of an ion channel
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
\end{document}
|
||||||
\subsection{Real-valued data}
|
|
Reference in New Issue
Block a user