Tải bản đầy đủ
A.5 Estimating E(Y|X) Using a Smoother

A.5 Estimating E(Y|X) Using a Smoother

Tải bản đầy đủ



estimating e(y |x) using a smoother

Height, dm

f = .1
f = 2/3
f = .95






Diameter at 137 cm above ground

Figure A.1  Three choices of the smoothing parameter for a loess smooth. The data used in this
plot are discussed in Section 8.1.2.

5. Repeat steps 1–4 for many values of xg that form a grid of points that
cover the interval on the x-axis of interest. Join the points.
Figure A.1 shows a plot of Height versus Diameter for western cedar
trees in the Upper Flat Creek data, along with four smoothers. The first
smoother is the ols simple regression line, which does not match the
data well because the mean function for the data in this figure is probably
curved, not straight. The loess smooth with f  =  0.1 is as expected very
wiggly, matching the local variation rather than the mean. The line for
f  =  2/3 seems to match the data very well, while the loess fit for f  =  .95
is nearly the same as for f  =  2/3, but it tends toward oversmoothing and
attempts to match the ols line. We would conclude from this graph that a
straight-line mean function is likely to be inadequate because it does not
match the data very well. Loader (2004) presents a bootstrap based lack-of-fit
test based on comparing parametric and nonparametric estimates of the
mean function.
The loess smoother is an example of a nearest neighbor smoother. Local
polynomial regression smoothers and kernel smoothers are similar to loess,
except they give positive weight to all cases within a fixed distance of the point
of interest rather than a fixed number of points. There is a large literature on
nonparametric regression, for which scatterplot smoothing is a primary tool.
Recent reference on this subject include Simonoff (1996), Bowman and Azzalini (1997), and Loader (1999).



We provide only a brief introduction to matrices and vectors. More complete
references include Seber (2008), Schott (2005), or any good linear algebra
Boldface type is used to indicate matrices and vectors. We will say that X
is an r  ×  c matrix if it is an array of numbers with r rows and c columns. A
specific 4 × 3 matrix X is

 1


1  x11
5  x21
 =
4  x31
6  x41


x13 
x23 
 = ( xij )
x33 
x43 


The element xij of X is the number in the ith row and the jth column. For
example, in the preceding matrix, x32 = 3.
A vector is a matrix with just one column. A specific 4 × 1 matrix y, which
is a vector of length 4, is given by
 2  y1 
 3  y2 
y=  = 
 −2  y3 
 0  y 
The elements of a vector are generally singly subscripted; thus, y3 = −2. A row
vector is a matrix with one row. We do not use row vectors in this book. If a
vector is needed to represent a row, a transpose of a column vector will be
used, Appendix A.6.4.
A square matrix has the same number of rows and columns, so r  =  c. A
square matrix Z is symmetric if zij = zji for all i and j. A square matrix is diagonal if all elements off the main diagonal are 0, zij = 0, unless i = j. The matrices
C and D below are symmetric and diagonal, respectively:
7 3
3 4
 1 −1

1 −1

6 3
3 8

 0





The diagonal matrix with all elements on the diagonal equal to 1 is
called the identity matrix, for which the symbol I is used. The 4 × 4 identity
matrix is



a brief introduction to matrices and vectors
 0





A scalar is a 1 × 1 matrix, an ordinary number.
A.6.1  Addition and Subtraction
Two matrices can be added or subtracted only if they have the same number
of rows and columns. The sum C = A + B of r × c matrices is also r × c. Addition is done elementwise:
 a11
C = A + B =  a21

 a31

a12   b11
a22  +  b21
 
a32   b31

b12   a11 + b11
b22  =  a21 + b21
 
b32   a31 + b31

a12 + b12 
a22 + b22 

a32 + b32 

Subtraction works the same way, with the “+” signs changed to “−” signs. The
usual rules for addition of numbers apply to addition of matrices, namely commutativity, A + B = B + A, and associativity, (A + B) + C = A + (B + C).
A.6.2  Multiplication by a Scalar
If k is a number and A is an r  × c matrix with elements (aij), then kA is an
r × c matrix with elements (kaij). For example, the matrix σ2I has all diagonal
elements equal to σ2 and all off-diagonal elements equal to 0.
A.6.3  Matrix Multiplication
Multiplication of matrices follows rules that are more complicated than are
the rules for addition and subtraction. For two matrices to be multiplied
together in the order AB, the number of columns of A must equal the number
of rows of B. For example, if A is r × c, and B is c × q, then C = AB is r × q.
If the elements of A are (aij) and the elements of B are (bij), then the elements
of C = (cij) are given by the formula

cij =

∑a b

ik kj

k =1

This formula says that cij is formed by taking the ith row of A and the jth
column of B, multiplying the first element of the specified row in A by the first
element in the specified column in B, multiplying second elements, and so on,
and then adding the products together.



If A is 1 × c and B is c × 1, then the product AB is 1 × 1, an ordinary number.
For example, if A and B are
 2
 1
A = (1 3 2 − 1) B =  
 −2 
 4
then the product AB is
AB = (1 × 2) + (3 × 1) + (2 × −2) + (−1 × 4) = −3
AB is not the same as BA. For the preceding matrices, the product BA will
be a 4 × 4 matrix:
4 −2
 2
 1 3 2 −1

BA = 
 −2 −6 −4
 4 12
8 −4
The following small example illustrates what happens when all the dimensions are bigger than 1. A 3 × 2 matrix A times a 2 × 2 matrix B is given as
 a11
 a21

 a31

a12 
 b11
a22  
  b21
a32 

 a11b11 + a12 b21
b12 
=  a21b11 + a22 b21
b22  
 a31b11 + a32 b21

a11b12 + a12 b22 
a21b12 + a22 b22 

a31b12 + a32 b22 

Using numbers, an example of multiplication of two matrices is
 15 + 0 3 + 4  15 4
 3 1
5 1
 −1 0 
=  −5 + 0 −1 + 0 =  −5 −1

 
  0 4 

 10 + 0 2 + 8  10 10
 2 2
In this example, BA is not defined because the number of columns of B is not
equal to the number of rows of A. However, the associative law holds: If A is
r × c, B is c × q, and C is q × p, then A(BC) = (AB)C, and the result is an r × p
A.6.4  Transpose of a Matrix
The transpose of an r × c matrix X is a c × r matrix called X′ such that if the
elements of X are (xij), then the elements of X′ are (xji). For the matrix X given
at (A.12),



a brief introduction to matrices and vectors
 1 1 1 1
X ′ =  2 1 3 8

 1 5 4 6

The transpose of a column vector is a row vector. The transpose of a product
(AB)′ is the product of the transposes, in opposite order, so (AB)′ = B′A′.
Suppose that a is an r × 1 vector with elements a1, . . . , ar. Then the product
a′a will be a 1 × 1 matrix or scalar, given by

a ′a = a12 + a22 +

+ ar2 =




i =1

Thus, a′a provides a compact notation for the sum of the squares of the elements of a vector a. The square root of this quantity (a′a)1/2 is called the norm
or length of the vector a. Similarly, if a and b are both r × 1 vectors, then we

a ′b = a1b1 + a2 b2 +

+ an bn =

i =1


ai bi =

∑ b a = b′a
i i

i =1

The fact that a′b = b′a is often quite useful in manipulating the vectors used
in regression calculations.
Another useful formula in regression calculations is obtained by applying
the distributive law

(a − b)′ (a − b) = a ′a + b′ b − 2a ′b


A.6.5  Inverse of a Matrix
For any real number c ≠ 0, there is another number called the inverse of c, say
d, such that the product cd = 1. For example, if c = 3, then d = 1/c = 1/3, and
the inverse of 3 is 1/3. Similarly, the inverse of 1/3 is 3. The number 0 does not
have an inverse because there is no other number d such that 0 × d = 1.
Square matrices can also have an inverse. We will say that the inverse of a
matrix C is another matrix D, such that CD = I, and we write D = C−1. Not all
square matrices have an inverse. The collection of matrices that have an
inverse are called full rank, invertible, or nonsingular. A square matrix that is
not invertible is of less than full rank, or singular. If a matrix has an inverse,
it has a unique inverse.
The inverse is easy to compute only in special cases, and its computation in
general can require a very tedious calculation that is best done on a computer.
High-level matrix and statistical languages such as Matlab, Maple, Mathematica and R include functions for inverting matrices, or returning an appropriate message if the inverse does not exist.



The identity matrix I is its own inverse. If C is a diagonal matrix, say
3 0
 0 −1
0 0
 0 0

0 0
0 0

4 0
0 1

then C−1 is the diagonal matrix
 1 0 0 0

 0 −1 0 0


0 0

 0 0 0 1
as can be verified by direct multiplication. For any diagonal matrix with
nonzero diagonal elements, the inverse is obtained by inverting the diagonal
elements. If any of the diagonal elements are 0, then no inverse exists.
A.6.6  Orthogonality
Two vectors a and b of the same length are orthogonal if a′b  =  0. An r  ×  c
matrix Q has orthonormal columns if its columns, viewed as a set of c ≤ r different r  ×  1 vectors, are orthogonal and in addition have length 1. This is
equivalent to requiring that Q′Q = I, the r × r identity matrix. A square matrix
A is orthogonal if A′A = AA′ = I, and so A−1 = A′. For example, the matrix




1 

2 
0 −
1 


can be shown to be orthogonal by showing that A′A = I, and therefore

A −1 = A ′ = 



1 

1 
0 −
1 




random vectors

A.6.7  Linear Dependence and Rank of a Matrix
Suppose we have a n × p matrix X with columns given by the vectors x1, . . . ,
xp; we consider only the case p  ≤  n. We will say that x1, .  .  . , xp are linearly
dependent if we can find multipliers a1, . . . , ap, not all of which are 0, such that

∑a x



= 0


i =1

If no such multipliers exist, then we say that the vectors are linearly independent, and the matrix is full rank. In general, the rank of a matrix is the
maximum number of xi that form a linearly independent set.
For example, the matrix X given at (A.12) can be shown to have linearly
independent columns because no ai not all equal to zero can be found that
satisfy (A.15). On the other hand, the matrix

 1

2 5
1 4
 = (x 1, x 2, x 3 )
3 6
8 11


has linearly dependent columns and is singular because x3 = 3x1 + x2. The matrix
has rank 2, because the linearly independent subset of the columns with the
most elements has two elements.
The matrix X′X is a p × p matrix. If X has rank p, so does X′X. Full-rank
square matrices always have an inverse. Square matrices of less than full rank
never have an inverse.

An n × 1 vector Y is a random vector if each of its elements is a random variable. The mean of an n  ×  1 random vector Y is also an n  ×  1 vector whose
elements are the means of the elements of Y. The variance of an n × 1 vector
Y is an n × n square symmetric matrix, often called a covariance matrix, written
Var(Y) with Var(yi) as its (i, i) element and Cov(yi, yj) = Cov(yj, yi) as both the
(i, j) and (j, i) element.
The rules for means and variances of random vectors are matrix equivalents
of the scalar versions in Appendix A.2. If a0 is a vector of constants, and A is
a matrix of constants,

E(a 0 + AY) = a 0 + AE(Y)


Var(a 0 + AY) = AVar(Y)A ′




The multiple linear regression model can be written as
E(Y |X = x) = b ′x Var(Y |X = x) = σ 2
The matrix version is
E(Y|X) = Xb

Var(Y|X) = σ 2 I

where Y is the n × 1 vector of response values and X is a n × p′ matrix. If the
mean function includes an intercept, then the first column of X is a vector of
ones, and p′ = p + 1. If the mean function does not include an intercept, then
the column of one is not included in X and p′ = p. The ith row of the n × p′
matrix X is x i′ , β is a p′ × 1 vector of parameters for the mean function.
The ols estimator bˆ of β is given by the arguments that minimize the
residual sum of squares function,
RSS( b ) = (Y − Xb )′ (Y − Xb )
Using (A.14)

RSS(b ) = Y ′Y + b ′(X ′X)b − 2Y ′Xb


RSS(β) depends on only three functions of the data: Y′Y, X′X, and Y′X. Any
two data sets that have the same values of these three quantities will have the
same least squares estimates. Using (A.8), the information in these quantities
is equivalent to the information contained in the sample means of the regressors plus the sample covariances of the regressors and the response.
To minimize (A.19), differentiate with respect to β and set the result equal
to 0. This leads to the matrix version of the normal equations,

X ′ Xb = X ′ Y


The ols estimates are any solution to these equations. If the inverse of (X′X)
exists, as it will if the columns of X are linearly independent, the ols estimates
are unique and are given by

bˆ = (X ′X)−1 X ′Y


If the inverse does not exist, then the matrix (X′X) is of less than full rank,
and the ols estimate is not unique. In this case, most computer programs
will use a linearly independent subset of the columns of X in fitting the model,
so that the reduced model matrix does have full rank. This is discussed in
Section 4.1.4.



least squares using matrices

A.8.1  Properties of Estimates
Using the rules for means and variances of random vectors, (A.17) and (A.18),
we find
E( bˆ |X) = E [(X ′X)−1 X ′Y|X ]

= [(X ′X)−1 X ′ ] E(Y|X)

= ( X ′ X ) −1 X ′ X b



so bˆ is unbiased for β, as long as the mean function that was fit is the true
mean function. The variance of bˆ is
Var( bˆ |X) = Var [(X ′X)−1 X ′Y|X ]

= (X ′X)−1 X ′ [ Var(Y|X)] X(X ′X)−1

= (X ′X)−1 X ′ [σ 2 I ] X(X ′X)−1
= σ ( X ′ X ) X ′ X( X ′ X )



= σ 2 (X ′X)−1


The variances and covariances are compactly determined as σ2 times a matrix
whose elements are determined only by X and not by Y.
A.8.2  The Residual Sum of Squares
ˆ = Xbˆ be the n × 1 vector of fitted values corresponding to the n cases
Let Y
in the data, and ê = Y − Ŷ is the vector of residuals. One representation of the
residual sum of squares, which is the residual sum of squares function evaluated at bˆ , is
ˆ )′ (Y − Y
ˆ ) = eˆ ′eˆ =
RSS = (Y − Y


∑ eˆ


i =1

which suggests that the residual sum of squares can be computed by squaring
the residuals and adding them up. In multiple linear regression, it can also be
computed more efficiently on the basis of summary statistics. Using (A.19) and
the summary statistics X′X, X′Y, and Y′Y, we write
RSS = RSS( bˆ ) = Y ′Y + bˆ ′X ′Xbˆ − 2 Y ′Xbˆ
We will first show that bˆ ′X ′Xbˆ = Y ′Xbˆ . Substituting for one of the bs,
we get
bˆ ′X ′X(X ′X)−1 X ′Y = bˆ ′X ′Y = Y ′Xbˆ



The last result follows because taking the transpose of a 1  ×  1 matrix does
not change its value. The residual sum of squares function can now be rewritten as
RSS = Y ′Y − bˆ ′X ′Xbˆ
ˆ ′Y
= Y ′Y − Y
ˆ = Xbˆ are the fitted values. The residual sum of squares is the differwhere Y
ence in the squares of the lengths of the two vectors Y and Ŷ. Another useful
form for the residual sum of squares is
RSS = SYY(1 − R2 )
where R2 is the square of the sample correlation between Ŷ and Y.
A.8.3  Estimate of Variance
Under the assumption of constant variance, the estimate of σ2 is

σˆ 2 =




with d df, where d is equal to the number of cases n minus the number of
regressors with estimated coefficients in the model. If the matrix X is of full
rank, then d = n − p′, where p′ = p for mean functions without an intercept,
and p′ = p + 1 for mean functions with an intercept. The number of estimated
coefficients will be less than p′ if X is not of full rank.
A.8.4  Weighted Least Squares
From Section 7.1, the wls model can be written in matrix notation as
E(Y|X) = Xb

Var(Y|X) = σ 2 W −1


To distinguish ols and wls results, we will use a subscript W on several quantities. In practice, there is no need to distinguish between ols and wls, and this
subscript is dropped elsewhere in the book.

The wls estimator bˆ W of β is given by the arguments that minimize the
residual sum of squares function,
RSSW (b ) = (Y − Xb )′ W(Y − Xb )

= Y ′WY + b ′(X ′WX)b − 2 Y ′WXb



the qr factorization
The wls estimator solves the weighted normal equations
X ′WXb = X ′WY

The wls estimate is
bˆ W = (X ′WX)−1 X ′WY


bˆ W is unbiased:
E( bˆ W |X) = E [(X ′WX)−1 X ′WY|X ]
= (X ′WX)−1 X ′WE(Y|X)

= (X ′WX)−1 X ′WXb



The variance of bˆ is
Var( bˆ W |X) = Var((X ′WX)−1 X ′WY|X)
= (X ′WX)−1 X ′W [ Var(Y|X)] WX(X ′WX)−1

= (X ′X)−1 X ′W [σ 2 W −1 ] WX(X ′X)−1
= σ 2 (X ′WX)−1


The RSSW can be computed from
RSSW = Y ′WY − bˆ ′X ′WXbˆ

The estimated variance is

σˆ 2 =




with d df, where d is equal to the number of cases n minus the number
of regressors with estimated coefficients in the model.
Confidence intervals are the same for both ols and wls as long as (A.28)
and (A.29) are used. Testing procedures in Chapter 6 are the same with
ols and wls subject to the changes described here. In particular, standard computer programs produce output that will look the same with
ols and wls and the output can be interpreted similarly.

Most of the formulas given in this book are convenient for derivations but can
be inaccurate when used on a computer because inverting a matrix such as