Math 4510/5510 Spring 2014 A tutorial to the Matlab Statistics Toolbox Math 4510/5510 Lab notes 1. 1. Introduction The user’s guide can be downloaded here, http://www.mathworks.com/help/releases/R13sp2/pdf_doc/stats/stats.pdf The documentation of the Matlab statistics toolbox can be found here, http://www.mathworks.com/help/stats/index.html;jsessionid=0bf4f3df6d60e53cb7a4efa0eba6 Figure 1. The Statistics Toolbox documentation We will introduce the most basic functions: Exploratory data Analsyis Probability Distributions Math 4510/5510 Spring 2014 Hypothesis Tests Regression and ANOVA (optional) Introduction to Matlab Statistics Toolbox 1. 1. Functions list (Button on the left in Fig 1. ) Descriptive Statistics Statistical Visualization 1.2. Classes (Button at the middle lower corner in Fig 1. ) Probability distractions Regression and ANOVA – linear regression 2. Examples Example 1. (descriptive statistics) Data set simulated stock returns stockreturns.mat > load stockreturns %load the data > who Your variables are: stocks > size(stocks) % find the size of the data > stocks(:, 2) % call the second column of the matrix % Descriptive statistics , find statistics for the given data > mean(stocks(:,2); %find the mean of the column 2 > mean_stocks= zeros(10,1); % define a 10X1 matrix, clear memory > i=1:10; mean_stocks(i, 1)=mean(:,i); % calculate mean for ith column > mean_stocks HW Q1. Find standard deviation, minimum, maximum, range, 25, 50, and 75 percentile Example 2 (visualize data) > hist(stocks(:,1); > %Multiple plots on the same panel > subplot(2,2,1) > plot Math 4510/5510 Spring 2014 Lab Notes 2 This lab will introduce Data input and out put in Matlab Basics of descriptive statistics Please read Chapter 2 in Text book #2 % recall what last lab % data set stockreturns.mat % New data set: gas.mat % for review, plot hist for gas.mat % data input and output % csvwrite(‘yourfile.csv’, variable) and a=csvread(‘yourfile.csv’) % Exercise 1. Load/Read/write for data set: gas.mat % matrix format in matlab > stocks(:,2), % call column 2 > stocks(1,:), % call first row % Distributions in toolbox > randtool %generate random variables Example Normal distribution. Generate a random sample of size 1000. % Descriptive statistics % 5 number summary, min, 25 percentile, median, 75 percentile, max, range % function prctile > prctile(stock(:,1), 25) …. > % construct 5 number summary > … Math 4510/5510 Spring 2014 Exercise 1. Generate a random sample from exponential distribution, with parameter lamda =2; 2. Find 5 number summary for data in 1; 3. generate histogram, boxplot, and normplot for data in 1: 4. write your data in 1 to a file, expSample.csv 5. read expSample.csv to variable a