Matlab_Tutorial_PartII_2005

# Matlab_Tutorial_PartII_2005 - MATLAB Tutorial Part II...

This preview shows pages 1–4. Sign up to view the full content.

MATLAB Tutorial: Part II. Conchi Ausín Olivera Econometrics Ph.D. Program in Business Administration and Quantitative Methods. April 4, 2005 Contents 1 Statistical analysis and simulation using MATLAB 2 1.1 Descriptive statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.1.1 Numerical description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.1.2 Descriptive statistics with the Statistics Toolbox of MATLAB . . . . . . . . . 3 1.2 Probability distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.2.1 Random variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.2.2 Probability distributions with the Statistics Toolbox of MATLAB. . . . . . . 6 1.3 Multiple linear regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.3.1 Programming functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.3.2 Multiple linear regression with the Statistics Toolbox of MATLAB . . . . . . 9 1.4 Stochastic processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.4.1 Bernoulli process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.4.2 Random walk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.4.3 Poisson process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.4.4 Autoregressive process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.4.5 Moving average process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.5 Monte Carlo simulation of known results . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.5.1 Central limit theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.5.2 Some properties of a random sample from a normal population . . . . . . . . 13 1.6 Optimization: Newton-Raphson method to obtain maximum likelihood estimators . 14 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
1 Statistical analysis and simulation using MATLAB The Statistics Toolbox for MATLAB provides a large number of function for analyzing data. How- ever, in practical situations, we are often faced with the di culty of programming. In these notes, we will consider di ff erent problems that will be solved both by programming and by using the Statistical Toolbox for MATLAB. This toolbox includes functions for Probability distributions, Parameter estimations, Descriptive Statistics, Multivariate statistics, Linear and nonlinear mod- eling, Statistical plotting, Statistical Process Control, Design of Experiments, Hypothesis Tests, Cluster Analysis. See help stats . 1.1 Descriptive statistics 1.1.1 Numerical description We can de fi ne this simple function to compute the mean value of the elements of a vector. function xbar = mean1(x) % For a vector x, mean1(x) returns the mean of x. n = length(x); xbar = x(1); for i = 2:n xbar = xbar + x(i); end xbar = xbar/n; Now, you can type the following statement to see how this function works: >> x = rand(1000,1); >> m = mean1(x) The mean of x given by m should be close to 0.5 . Alternatively, we could have make use of the sum command to avoid including a for loop: function xbar = mean2(x) % For a vector x, mean1(x) returns the mean of x.. n = length(x); xbar = sum(x); xbar = xbar/n; Observe that the function mean2 (unlike mean1 ) can also be applied to matrices where each column is a sample of data from a di ff erent variable. For matrices, mean2(x) is a row vector containing the mean value of each column. We can construct a function to compute simultaneously the sample mean, ¯ x, standard deviation, s, skewness, SK, and kurtosis, K, for each column of a matrix where, ¯ x = n P i =1 x i n , s = v u u u t n P i =1 ( x i ¯ x ) 2 n , SK = n P i =1 ( x i ¯ x ) 3 ns 3 , K = n P i =1 ( x i ¯ x ) 3 ns 4 . function [xbar,s,SK,K] = statistics(X) 2
% X is a matrix whose columns are sample % of data from a certain variable.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern