# Matlab Statistics Examples

HELP ON SELECTED TOPICS

---------------------------------------------

DESCRIPTIVE sTATISTICS:

MEAN Average or mean value.

For vectors, MEAN(X) is the mean value of the elements in X. For

matrices, MEAN(X) is a row vector containing the mean value of

each column. For N-D arrays, MEAN(X) is the mean value of the

elements along the first non-singleton dimension of X.

MEAN(X,DIM) takes the mean along the dimension DIM of X.

Example: If X = [0 1 2

3 4 5]

then mean(X,1) is [1.5 2.5 3.5] and mean(X,2) is [1

4]

VAR Variance.

For vectors, VAR(X) returns the variance of X.

For matrices, VAR(X)is a row vector containing the

variance of each column of X.

VAR(X) normalizes by N-1 where N is the sequence length. This

makes VAR(X) the best unbiased estimate of the variance if X

is a sample from a normal distribution.

VAR(X,1) normalizes by N and produces the second moment of the

VAR(X,W) computes the variance using the weight vector, W.

The number of elements in W must equal the number of rows

in X unless W = 1 which is treated as a short-cut for a

vector of ones.

The elements of W must be positive. VAR normalizes W by

dividing each element in W by the sum of all its elements.

The variance is the square of the standard deviation

---------------------------------------------

PLOTTING TOOLS:

T Linear plot.

PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,

then the vector is plotted versus the rows or columns of the matrix,

whichever line up.

PLOT(Y) plots the columns of Y versus their index.

If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)).

In all other uses of PLOT, the imaginary part is ignored.

Various line types, plot symbols and colors may be obtained with

PLOT(X,Y,S) where S is a character string made from one element

from any or all the following 3 colunms:

y yellow . point - solid

m magenta o circle : dotted

c cyan x x-mark -. dashdot

r red + plus -- dashed

g green * star

b blue s square

w white d diamond

k black v triangle (down)

^ triangle (up)

< triangle (left)

> triangle (right)

p pentagram

h hexagram

For example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus

at each data point; PLOT(X,Y,'bd') plots blue diamond at each data

point but does not draw any line.

PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by

the (X,Y,S) triples, where the X's and Y's are vectors or matrices

and the S's are strings.

For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a

solid yellow line interpolating green circles at the data points.

The PLOT command, if no color is specified, makes automatic use of

the colors specified by the axes ColorOrder property. The default

ColorOrder is listed in the table above for color systems where the

default is yellow for one line, and for multiple lines, to cycle

through the first six colors in the table. For monochrome systems,

PLOT cycles over the axes LineStyleOrder property.

PLOT returns a column vector of handles to LINE objects, one

handle per line.

The X,Y pairs, or X,Y,S triples, can be followed by

parameter/value pairs to specify additional properties

of the lines.

XLABEL, YLABEL, AXIS, AXES, HOLD, COLORDEF, and SUBPLOT.

---------------------------------------------

SPC Plots:

XBARRPLOT X-bar chart for monitoring the mean.

XBARPLOT(DATA,CONF,SPECS) produces an xbar chart of

the grouped responses in DATA. The rows of DATA contain

replicate observations taken a a given time. The rows

should be in time order.

CONF (optional) is the confidence level of the upper and

lower plotted confidence limits. CONF is 0.99 by default.

This means that 99% of the plotted points should fall

between the control limits.

SPECS (optional) is a two element vector for the lower and

upper specification limits of the response.

OUTLIERS = XBARPLOT(DATA,CONF,SPECS) returns a vector of

indices to the rows where the mean of DATA is out of control.

[OUTLIERS, H] = XBARPLOT(DATA,CONF,SPECS) also returns a vector

of handles, H, to the plotted lines.

EWMAPLOT Exponentially weighted moving average chart.

H = EWMAPLOT(DATA,LAMBDA,ALPHA,SPECS) produces an EWMA chart

of the grouped responses in DATA. The rows of DATA contain

replicate observations taken at a given time. The rows

should be in time order.

LAMBDA (optional) is the parameter that controls how much

the current prediction is influenced by past observations.

Higher values of LAMBDA give more weight to past observations.

By default, LAMBDA = 0.4, and LAMBDA must be between 0 and 1.

ALPHA (optional) is the significance level of the upper and

lower plotted confidence limits. ALPHA is 0.01 by default.

This means that 99% of the plotted points should fall

between the control limits.

SPECS (optional) is a two element vector for the lower and

upper specification limits of the response.

H is a vector of handles to the plotted lines.

-----------------------------------------------------------------

REGRESSION:

POLYFIT Fit polynomial to data.

POLYFIT(X,Y,N) finds the coefficients of a polynomial P(X) of

degree N that fits the data, P(X(I))~=Y(I), in a least-squares sense.

[P,S] = POLYFIT(X,Y,N) returns the polynomial coefficients P and a

structure S for use with POLYVAL to obtain error estimates on

predictions. If the errors in the data, Y, are independent normal

with constant variance, POLYVAL will produce error bounds which

contain at least 50% of the predictions.

The structure S contains the Cholesky factor of the Vandermonde

matrix (R), the degrees of freedom (df), and the norm of the

residuals (normr) as fields.

LEVERAGE Regression diagnostic.

LEVERAGE(DATA,MODEL) finds the leverage on a regression of each

row (point) in the matrix, DATA. The argument, MODEL, controls the

order of the regression model. By default, LEVERAGE assumes a linear

additive model with a constant term. MODEL can be following strings:

interaction - includes constant, linear, and cross product terms.

quadratic - interactions plus squared terms.

purequadratic - includes constant, linear and squared terms.

-----------------------------------------------------------------

ANOVA:

ANOVA1 One-way analysis of variance (ANOVA).

ANOVA1 performs a one-way ANOVA for comparing the means of two or more

groups of data. It returns the p-value for the null hypothesis that the

means of the groups are equal.

P = ANOVA1(X) for matrix, X, treats each column as a separate group,

and determines whether the population means of the columns are equal.

This one-input form of ANOVA1 is appropriate when each group has the

same number of elements (balanced ANOVA).

P = ANOVA1(X,GROUP) has vector inputs X and GROUP. The vector, GROUP,

identifies the group of the corresponding element of X. This two-input

form of ANOVA1 has no restrictions on the number of elements in each

group.

ANOVA1 prints the standard one-way ANOVA table in Figure 1 and displays

a boxplot in Figure2.

ANOVA2 Two-way analysis of variance.

ANOVA2(X,REPS) performs a balanced two-way ANOVA for comparing the

means of two or more columns and two or more rows of the sample in X.

The data in different columns represent changes in one factor. The data

in different rows represent changes in the other factor. If there is

more than one observation per row-column pair, then the argument, REPS,

indicates the number of observations per "cell". A cell contains REPS

number of rows.

For example, if REPS = 3, then each cell contains 3 rows and the total

number of rows must be a multiple of 3. If X has 12 rows, and REPS = 3,

then the "row" factor has 4 levels (3*4 = 12). The second level of the

row factor goes from rows 4 to 6.

-----------------------------------------------------------------

DOE:

FF2N Two-level full-factorial design.

X = FF2N(N) creates a two-level full-factorial design, X.

N is the number of columns of X. The number of rows is 2^N.

FULLFACT Mixed-level full-factorial designs.

FULLFACT(LEVELS) outputs the factor settings for a full factorial

design. The vector LEVELS specifies the number of unique setting

in each column of the design.

Example: If LEVELS = [2 4 3], FULLFACT will generate a 24 run design

with 2 levels in the first column, 4 in the second column, and 3 in

the third column.

For more help on directory/topic, type "help topic".