Stat Trek

Teach yourself statistics

Teach yourself statistics

# How to Compute Vector Means

This lesson explains how to use matrix methods to compute the means of vector elements and the means of matrix columns.

## Mean Scores: Vectors

In ordinary algebra, the mean of a set of observations is computed by adding all of the observations and dividing by the number of observations.

x = Σxi / n

where x is the mean of observations, Σxi is the sum of all observations, and n is the number of observations.

In matrix algebra, the mean of a set of n scores can be computed as follows:

x = 1'x ( 1'1 )-1 = 1'x ( 1/n )

where

x is the mean of a set of n scores
1 is an n x 1 column vector of ones
x is an n x 1 column vector of scores: x1, x2, . . . , xn

To show how this works, let's find the mean of elements of vector x, where x' = [ 1 2 3 ].

 x   = 1' x ( 1' 1 )-1

x   =    [ 1 1 1 ]
 1 2 3
(    [ 1 1 1 ]
 1 1 1
)-1

x   =   6/3   =   2

Thus, the mean of the elements of x is 2.

## Mean Scores: Matrices

You can think of an r x c matrix as a set of c column vectors, each having r elements. Often, with matrices, we want to compute mean scores separately within columns, consistent with the equation below.

Xc = Σ Xic / r

where

Xc is the mean of a set of r scores from column c
Σ Xic is the sum of elements from column c

In matrix algebra, a vector of mean scores from each column of matrix X can be computed as follows:

m' = 1'X ( 1'1 )-1 = 1'X ( 1/r )

where

m' is a row vector of column means, [ X1   X2 ... Xc ]
1 is an r x 1 column vector of ones
X is an r x c matrix of scores: X11, X12, . . . , Xrc

The problem below shows how everything works.

Problem 1

Consider matrix X.

X   =
 3 5 1 9 1 4

Using matrix methods, create a 1 x 3 vector m', such that the elements of m' are the mean of column elements from X. That is,

m' = [ X1    X2    X3 ]

where Xi is the mean of elements from column i of matrix X.

Solution

To solve this problem, we use the following equation: m' = 1'X ( 1'1 )-1. Each step in the computation is shown below.

m'   =    1' X ( 1' 1   )-1
m'   =    [ 1 1 ]
 3 5 1 9 1 4
(    [ 1 1 ]
 1 1
)-1
m'  =
 3+9 5+1 1+4
(    [ 1 1 ]
 1 1
)-1
m'   =
 12 6 5
*  0.5
m'   =
 6 3 2.5

Thus, vector m has the mean column scores from matrix X. The mean score for column 1 is 6, the mean score for column 2 is 3, and the mean score for column 3 is 2.5.