Z = zscore(X) returns
the z-score for
each element of X such that columns of X are
centered to have mean 0 and scaled to have standard deviation 1. Z is
the same size as X.

If X is a vector, then Z is
a vector of z-scores.

If X is a matrix, then Z is
a matrix of the same size as X, and each column
of Z has mean 0 and standard deviation 1.

Z = zscore(X,flag) scales X using
the standard deviation indicated by flag.

If flag is 0 (default), then zscore scales X using
the sample standard deviation, with n -
1 in the denominator of the standard deviation formula. zscore(X,0) is
the same as zscore(X).

If flag is 1, then zscore scales X using
the population standard deviation,
with n in the denominator of standard deviation
formula.

Z = zscore(X,flag,dim) standardizes X along
dimension dim. For example, for a matrix X,
if dim = 1, then zscore uses
the means and standard deviations along the columns of X,
if dim = 2, then zscore uses
the means and standard deviations along the rows of X.

[Z,mu,sigma]
= zscore(___) also returns the means and standard
deviations used for centering and scaling, mu and sigma,
respectively. You can use any of the input arguments in the previous
syntaxes.

Now, you can see the relative performance of individuals with
respect to both their gpa and lsat results.
For example, the third individual's gpa and lsat results
are both one standard deviation below the sample mean. The eleventh
individual's gpa is around the sample mean
but has an lsat score almost 1.25 standard deviations
above the sample average.

Check the mean and standard deviation of the z-scores
you created.

mean([Zgpa,Zlsat])

ans =
1.0e-14 *
-0.1088 0.0357

std([Zgpa,Zlsat])

ans =
1 1

By definition, z-scores of gpa and lsat have
mean 0 and standard deviation 1.

For a sample from a population, the population standard deviation
formula with n in the denominator corresponds to
the maximum likelihood estimate of the population
standard deviation, and might be biased. The sample standard
deviation formula, on the other hand, is the unbiased estimator of
the population standard deviation for a sample.

Compute z-scores using the
mean and standard deviation computed along the columns or rows of
a data matrix.

Load the sample data.

load('flu.mat')

The dataset array flu is loaded in the workplace. flu has
52 observations on 11 variables. The first variable contains dates
(in weeks). The other variables contain the flu estimates for different
regions in the U.S.

Convert the dataset array to a data matrix.

flu2 = double(flu(:,2:end));

The new data matrix, flu2, is a 52-by-10
double data matrix. The rows correspond to the weeks and the columns
correspond to the U.S. regions in the data set array flu.

Standardize the flu estimate for each region (the columns of flu2).

Z1 = zscore(flu2,[ ],1);

You can see the z-scores in the variable
editor by double-clicking on the matrix Z1 created
in the workspace.

Standardize the flu estimate for each week (the rows of flu2).

Dimension along which to calculate the z-scores
of X, specified as a positive integer. For example,
for a matrix X, if dim = 1,
then zscore uses the means and standard deviations
along the columns of X, if dim =
2, then zscore uses the means and standard deviations
along the rows of X.

Z — z-scoresvector | matrix | multidimensional array

z-scores, returned as a vector, matrix, or
multidimensional array. A vector of z-scores has
mean 0 and variance 1.

If X is a vector, then Z is
a vector of z-scores.

If X is an array, then zscore is
an array, with each column or row standardized to have mean 0 and
variance 1 (depending on dim). If dim is
not specified, zscore standardizes along the first nonsingleton dimension of X.

Mean of X used to compute the z-scores,
returned as a scalar or vector.

If X is a vector, then mu is
a scalar.

If X is a matrix, then mu is
a row vector if zscore calculates the means along
the columns of X (dim = 1),
and a column vector if zscore calculates the means
along the rows of X (dim = 2).

Standard deviation of X used to compute the z-scores,
returned as a scalar or vector.

If X is a vector, then sigma is
a scalar.

If X is a matrix, then sigma is
a row vector if zscore calculates the standard
deviations along the columns of X (dim =
1), and a column vector if zscore calculates the
standard deviations along the rows of X (dim =
2).

For a random variable X with
mean μ and standard deviation σ, the z-score
of a value x is

For sample data with mean and standard deviation S,
the z-score of a data point x is

z-scores measure the distance of a data point
from the mean in terms of the standard deviation. This is also called standardization of
data. The standardized data set has mean 0 and standard deviation
1, and retains the shape properties of the original data set (same
skewness and kurtosis).

You can use z-scores to put data on the same
scale before further analysis. This lets you to compare two or more
data sets with different units.

A first nonsingleton dimension
is the first dimension of an array whose size is not equal to 1. For
example, if X is a 1-by-2-by-3-by-4 array, then
the second dimension is the first nonsingleton dimension of X.

S is the square root of an unbiased
estimator of the variance of the population from which X is
drawn, as long as X consists of independent, identically
distributed samples.

Notice that the denominator in this variance formula is n –
1.

If the data is the entire population of values,
then you can use the population standard deviation,

If X is a random sample from
a population, then μ is estimated by the
sample mean, and σ is the biased maximum
likelihood estimator of the population standard deviation.

Notice that the denominator in this variance formula is n.

zscore returns NaNs for
any sample containing NaNs.

zscore returns 0s for
any sample that is constant (all values are the same). For example,
if X is a vector of the same numeric value, then Z is
a vector of 0s. If X is a matrix
with a column of consisting of the same value, then that column of Z consists
of 0s.