LINEAR TRANSFORMATIONS AND MATRICES [REVIEW]                   SPH 5421 notes.013

     This is an extremely brief review of some of the linear algebra that
you need to know to do regression.  It would be good to refer to a statistics
textbook that deals with linear models and regression for a more complete
discussion.  The books on linear models by Searle, Scheffe, Rao, and Seber are OK
for this purpose.  There is a definitive text on linear algebra by Paul Halmos,
but it goes well beyond what you need for this course.

     A linear transformation F is a linear function which acts upon values
in  Rn (n-dimensional Euclidean space) and takes values in Rm
(m-dimensional Euclidean space):


               Rn  --- F ---> Rm.

              domain          range


     Rn is called the domain space and Rm is the range space.

     Here is an example in which both Rn and Rm are two-dimensional
(n = m = 2):


             F(x, y) = (2x + 3y, 3x + 2y).

     The easiest way to think of linear functions in R2 is to see what
they do to the 'unit square'.  The unit square is the square in R2 which
has vertices (0,0), (0,1), (1,1), and (1,0).

     The linear transformation  F  above transforms the unit square into a
parallelogram with the following vertices:

         (0,0), (3, 2), (5,5), (2, 3).

     The resulting parallelogram is called the 'image' of the unit square.

     The general form of a linear transformation from R2 to R2 is

         F(x, y) = (a*x + b*y, c*x + d*y).

     It is thus determined by 4 coefficients, a, b, c, and d.  This linear
transformation produces the following image of the unit square:

                (0, 0)      (1, 0)       (1, 1)     (0, 1)

                   |           |            |          |
                   |           |            |          |
                   V           V            V          V

                (0, 0)      (a, c)     (a+b, c+d)   (b, d)

     The following SAS program may be useful for exploring linear
transformations from R^2 to R^2:

=======================================================================
FILENAME GRAPH 'gsas.grf' ;

OPTIONS  LINESIZE = 80  MPRINT ;

GOPTIONS
         RESET = GLOBAL
         ROTATE = PORTRAIT
         FTEXT = SWISSB
         DEVICE = PSCOLOR
         GACCESS = SASGASTD
         GSFNAME = GRAPH
         GSFMODE = REPLACE
         GUNIT = PCT BORDER
         CBACK = WHITE
         HTITLE = 2 HTEXT = 1 ;

*===================================================================== ;        

footnote "program: /home/walleye/john-c/5421/linear1.sas &sysdate &systime";

data square ;
     length ptname $3 fptname $3 ;
     length ord1 $24 ord2 $24 ;
     seed = -1 ;
     a = 1.5 * ranuni(seed); b = 1.5 * ranuni(seed) ;
     c = 1.5 * ranuni(seed); d = 1.5 * ranuni(seed) ;

*                                                                              ;
*    Note - you can set a, b, c, d to various values here, if desired.         ;
*                                                                              ;

     a = .8; b = .8; c = -.8; d = .8 ;

     va = left(put(a, 4.2)) ;
     vb = left(put(b, 4.2)) ;
     vc = left(put(c, 4.2)) ;
     vd = left(put(d, 4.2)) ;

     vmin = 0 ;
     vmax = 1 ;

     u = 0 ; v = 0 ;

     fu = a * u + b * v ;
     fv = c * u + d * v ;

     if fu lt vmin then vmin = fu ;
     if fu gt vmax then vmax = fu ;
     if fv lt vmin then vmin = fv ;
     if fv gt vmax then vmax = fv ;

     ptname = 'C' ; fptname = 'fC' ;
     output ;

     u = 1 ; v = 0 ;

     fu = a * u + b * v ;
     fv = c * u + d * v ;

     if fu lt vmin then vmin = fu ;
     if fu gt vmax then vmax = fu ;
     if fv lt vmin then vmin = fv ;
     if fv gt vmax then vmax = fv ;

     ptname = 'D' ; fptname = 'fD' ;
     output ;

     u = 1 ; v = 1 ;

     fu = a * u + b * v ;
     fv = c * u + d * v ;

     if fu lt vmin then vmin = fu ;
     if fu gt vmax then vmax = fu ;
     if fv lt vmin then vmin = fv ;
     if fv gt vmax then vmax = fv ;

     ptname = 'B' ; fptname = 'fB' ;
     output ;

     u = 0 ; v = 1 ;

     fu = a * u + b * v ;
     fv = c * u + d * v ;

     if fu lt vmin then vmin = fu ;
     if fu gt vmax then vmax = fu ;
     if fv lt vmin then vmin = fv ;
     if fv gt vmax then vmax = fv ;

     ptname = 'A' ; fptname = 'fA' ;
     output ;

     u = 0 ; v = 0 ;

     fu = a * u + b * v ;
     fv = c * u + d * v ;

     if fu lt vmin then vmin = fu ;
     if fu gt vmax then vmax = fu ;
     if fv lt vmin then vmin = fv ;
     if fv gt vmax then vmax = fv ;

     ptname = 'C' ; fptname = 'fC' ;

     cmin = left(put(vmin - .5, 3.1)) ;
     cmax = left(put(vmax + .5, 3.1)) ;

     ord1 = trim(cmin || " to " || cmax || " by .1 ;") ;
     ord2 = trim(cmin || " to " || cmax || " by .1 ;") ;

     call symput ('dsn1', ord1) ;
     call symput ('dsn2', ord2) ;

     output ;

run ;

proc print data = square ;
     var a b c d fu fv vmin vmax ord1 ord2 ;

data anno ;
     length text $80 text1 $40 text2 $40 ;
     set square ;

     determ = a * d - b * c ;

     xsys = '2' ; ysys = '2' ; size = 2.0 ; hsys = '1' ;
     style = 'swissbu' ;
     function = 'label' ; position = '>' ;
     x = u + .02 ; y = v ;
     text = ptname ;
     output ;

     x = fu + .02; y = fv - .05 ;
     text = fptname ;
     output ;

     if u = 1 and v = 1 then do ;

        xsys = '1' ; ysys = '1' ; size = 2.0 ; hsys = '1' ;
        x = 5 ; y = 95 ;
        text1 = "f(u, v) = ( " || va || "*u + " || vb || "*v," ;
        text2 = vc || "*u + " || vd || "*v )" ;
        text = trim(text1) || trim(text2) ;
        output ;

        x = 25 ; y = 90 ;
        text1 = "Determinant = " ;
        text2 = left(put(determ, 6.2)) ;
        text = trim(text1) || trim(text2) ;
        output ;

     end ;
run ;

proc print data = anno ;

%macro vplot(dsn1, dsn2) ;

symbol1 i = j v = NONE  f = swissb  w = 3  h = 2  c = black l = 1 ;
symbol2 i = j v = NONE  f = swissb  w = 3  h = 2  c = gray  l = 2 ;

proc gplot  data = square annotate = anno ;
     plot v * u   fv * fu / overlay haxis = axis1 vaxis = axis2 ;
     axis1 order = &dsn1 ;
     axis2 order = &dsn2 ;
title1 'Illustration of What a Linear Transformation Does to the Unit Square';
run ;
%mend ;

%vplot(&dsn1, &dsn2) ;

endsas ;
=======================================================================

     Below is a variant of the same program which shows what a linear
transformation does to the unit circle (that is, the circle around the
origin with radius 1).  Note that the points labelled 1, 2, and 3 on
the circle are transformed into the correspondingly labelled points on the
ellipse.  Also note that on the circle, (1, 2, 3) are in counterclockwise
order, while on the ellipse they are in clockwise order.

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


options linesize = 80 ;
footnote "~john-c/5421/circle.sas &sysdate &systime" ;

FILENAME GRAPH 'gsas.grf' ;
LIBNAME  loc '' ;

OPTIONS  LINESIZE = 80 MPRINT ;

GOPTIONS
         RESET = GLOBAL
         ROTATE = PORTRAIT
         FTEXT = SWISSB
         DEVICE = PSCOLOR
         GACCESS = SASGASTD
         GSFNAME = GRAPH
         GSFMODE = REPLACE
         GUNIT = PCT BORDER
         CBACK = WHITE
         HTITLE = 2 HTEXT = 1 ;

*===================================================================== ;        

%let a = -.5 ;
%let b =  1  ;
%let c =  1  ;
%let d = -.5 ;

data circle ;

     n = 500 ;
     pi = 4*atan(1) ;
     r = 1 ;

     do i = 1 to n ;

        theta = 2 * pi * i / n ;
        x = r*cos(theta) ;
        y = r*sin(theta) ;

        u = &a * x + &b * y ;
        v = &c * x + &d * y ;

        xstar = . ;
        ystar = . ;
        ustar = . ;
        vstar = . ;

        if i = 166 then do ;
           xstar1 = x ;
           ystar1 = y ; output ;
           xstar1 = u ;
           ystar1 = v ; output ;
        end ;
        if i = 333 then do ;
           xstar2 = x ;
           ystar2 = y ; output ;
           xstar2 = u ;
           ystar2 = v ; output ;
        end ;
        if i = 500 then do ;
           xstar3 = x ;
           ystar3 = y ; output ;
           xstar3 = u ;
           ystar3 = v ; output ;
        end ;

        output ;

     end ;

run ;

symbol1 i = j v = none l = 1 w = 2 c = black ;
symbol2 i = j v = none l = 3 w = 2 c = red   ;
symbol3 i = j v = '1'  l = 1 w = 3 h = 2 c = black ;
symbol4 i = j v = '2'  l = 1 w = 3 h = 2 c = black ;
symbol5 i = j v = '3'  l = 1 w = 3 h = 2 c = black ;

proc gplot data = circle ;
  plot y * x  v * u ystar1 * xstar1  ystar2 * xstar2  ystar3 * xstar3 / overlay ;
title1 h = 2 'Linear Transformation of Unit Circle' ;
title2 h = 2 f = swissb "U = &a * X + &b * Y   -  solid curve" ;
title3 h = 2 f = swissb "V = &c * X + &d * Y   -  dotted curve" ;
run ;

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

/home/walleye/john-c/5421/notes.013    Last update: October 22, 2007