Вы находитесь на странице: 1из 46

ISEE

 561/661  –  Week  9  
 

Prof.  Silvestrini  

Week  9  -­‐  Fall  2015   1  


Week  9  Plans  
Topic   Slides   Reading  
10/19/15  [M]     WLS,  GLS,  Robust  Reg.   1  –  27  
10/21/15  [W]*   Video  Lab  Lectures     28  
10/23/15  [F]  (Hw  #4  Due)   Principle  Components    29  –  46  

*I  will  be  aYending  the  Conference  on  Applied  Sta\s\cs  in  Defense  (last  conference  I  
will  aYend  this  Fall),  so  our  lectures  on  Wednesday  will  be  replaced  by  the  Video  Lab  
lectures.  You  will  answer  par\cipa\on  ques\ons  regarding  these  lab  components  
and  they  will  help  you  complete  your  homework  that  is  due  at  the  end  of  the  week.    

Week  9  -­‐  Fall  2015   2  


Week  9  Objec\ves  and  Outcomes  
•  Objec\ves:  This  week  prepares  you  to  address  viola\on  of  the  model  
assump\ons.  You  will  learn  to  modify  the  linear  model,  use  an  alterna\ve  
to  least  squares  regression,  and  use  principle  components  in  order  to  fix  
viola\ons.    
•  Outcomes  
–  Iden\fy  and  describe  the  model  assump\ons  for  the  linear  regression  model  
–  Describe  how  weighted  least  squares  works  and  when  it  would  be  used    
–  Describe  robust  regression  and  what  it  is  used  for    
–  Transform  the  response  variables  and  evaluate  the  fit  of  the  model  with  the  
transformed  response  
–  Transform  regression  variables  and  discuss  how  the  model  matrix  is  changed  
–  Add  more  complex  terms  to  the  regression  model  and  discuss  how  the  
addi\on  of  those  terms  change  the  model  matrix    
–  Describe  principle  components  and  what  it  is  used  for    
–  Use  principle  components  to  make  transforma\ons  in  your  variables  and  then  
use  those  variables  in  the  fiYed  model    

Week  9  -­‐  Fall  2015   3  


Regression  Model  Building  Process  

Week  9  -­‐  Fall  2015   4  


Major  Assump\ons  
1.  The  error  term  ε  has  mean  =  zero      
2.  The  error  term  ε  has  constant  variance  (σ2)  
3.  The  errors  are  normally  distributed    
4.  The  errors  are  uncorrelated    
5.  The  rela\onship  between  the  response  y  and  
the  regression  variables  is  correct    
6.  The  regression  variables  are  independent    

Week  9  -­‐  Fall  2015   5  


Dealing  With  Viola\ons  of  the  Major  
Assump\ons  (Assump\on#.  Solu\on)  
1.  Fix  y  =  Xβ  
2.  Transform  y  or  use  WLS    
3.  Robust  regression    
4.  GLS  or  WLS      
5.  Add/remove  X,  add  more  complex  X,  
transform  X      
6.  Variable  selec\on,  change  variables,  PCA    

Week  9  -­‐  Fall  2015   6  


Week  8  –  Changes  to  the  Model  
•  Transforma\ons  to  y    
–  Goal:  Stabilize  the  variance    
–  What  transform:  Use  table  or  Box  –  Cox    
•  Changes  to  x    
–  Linear  changes  don’t  change  the  fundamental  
analysis    
–  Adding  interac\on    
•  Help  explain  the  response    
•  Interpreta\on  if  interac\on  is  significant    
Week  9  -­‐  Fall  2015   7  
Week  9  Handout  Ques\on  1  
•  2  Factor  interac\ons  are  included  in  the  
model  by  mul\plying  two  x  variables  together    
•  If  interac\on  is  present,  we  say  that  the  
rela\onship  between  the  response  variable  y  
and  xi  is  changed  in  the  presence    of  xj    
•  3  cases  –  Interac\on  between:    
–  Con\nuous  and  con\nuous    
–  Con\nuous  and  categorical    
–  Categorical  and  categorical    

Week  9  -­‐  Fall  2015   8  


Con\nuous  x  Con\nuous    

Week  9  -­‐  Fall  2015   9  


Con\nuous  x  Categorical  

Week  9  -­‐  Fall  2015   10  


Categorical  x  Categorical  

Week  9  -­‐  Fall  2015   11  


Dealing  With  Viola\ons  

•  The  solu\ons  essen\ally  fall  into  one  of  three  


main  categories:    
–  Fix  the  rela\onship  y  =  Xβ  (Week  8)    
–  Use  something  other  than  OLS  (Week  9)    
–  Variable  selec\on  techniques  (Week  10)    

Week  9  -­‐  Fall  2015   12  


Alterna\ves  to  OLS  
•  Generalized  least  squares  (GLS)    
•  Weighted  least  squares  (WLS)    
•  Robust  Regression    

Week  9  -­‐  Fall  2015   13  


Two  Alternate  Least  Squares  
Approaches    
•  When  the  residuals  are  not  independent,  don’t  
have  constant  variance,  or  both,  we  can  apply  an  
alterna\ve  fipng  mechanism  that  takes  these  
correla\ons  and/or  changing  variance  structures  
into  account    
•  The  math:    
var ε =σ 2
Σ
•  The  two  approaches  are    
–  Generalized  least  squares  
–  Weighted  least  squares  (Σ  is  diagonal)  
           

Week  9  -­‐  Fall  2015   14  


Weighted  Regression  

Week  9  -­‐  Fall  2015   15  


WLS  in  R    
•  Add  an  argument  into  the  lm  func\on  
•  The  argument  is:  weight  =  ?    
•  You  must  determine  what  the  weight  should  
be  based  on  the  data    

Week  9  -­‐  Fall  2015   16  


Determining  the  Weights  

Week  9  -­‐  Fall  2015   17  


GLS    
•  We  can  es\mate  the  regression  and  weigh\ng  
parameters  using  a  likelihood-­‐based  method  
that  allows  us  to  model  the  variance  prior  to  
es\ma\on    
•  This  can  be  implemented  in  R  using  the  gls()  
func\on    

Week  9  -­‐  Fall  2015   18  


Robust  Regression  
•  When  the  errors  are  normal,  least  squares  
regression  is  best,  but  when  errors  are  non-­‐
normal,  other  methods  may  be  considered  
•  Remember:  least  squares  is  rela\vely  robust  
with  respect  to  small  departures  from  
normality    
•  Most  concerning:  long  tailed  distribu\ons    
•  Fix:  Using  robust  regression  

Week  9  -­‐  Fall  2015   19  


Robust  Regression  Con\nued  
•  Maximum  likelihood  es\ma\on    
•  Class  of  robust  es\mators  that  minimize  a  
func\on  p  of  the  residuals:    
n
min ∑ ρ(e )
  i =1
i

•  Huber’s  method  is  a  compromise  between  


least  squares  and  least  absolute  devia\on,  
where     ⎧⎪ x /2 2
if | x |≤ c
ρ(x) = ⎨
⎪⎩ c | x | −c / 2
2
otherwise

Week  9  -­‐  Fall  2015   20  


Robust  Regression  in  R    
•  Install  and  load  the  MASS  package    
•  Use  the  func\on  rlm()  with  the  same  
arguments  you  would  use  in  the  lm()  func\on  
•  For  the  summary  output,  you  will  not  get  R2  or  
F  sta\s\cs,  nor  will  you  get  p-­‐values  for  the  
regression  coefficients    
•  The  general  significance  of  the  variables  
remains  the  same  and  the  conclusions  are  not  
altered  much    
Week  9  -­‐  Fall  2015   21  
Pairs  Plot  of  Delivery  Data  
10 20 30 40 50 60 70 80 5 10 15 20 25 30 0 200 600 1000 1400

80

80
70

70
60

60
50

50
40 y

40
30

30
20

20
10

10
30
25
20
x1

15
10
5
1400
1000
x2

600
200
0
0 200 600 1000 1400

Week  9  -­‐  Fall  2015   22  


Week  9  Handout    
•  You  will  answer  ques\on  3  using  slides  24  and  
26    
•  You  will  answer  ques\on  4  using  slides  25  and  
27    

Week  9  -­‐  Fall  2015   23  


LS  Regression  on  Delivery  Data  

Week  9  -­‐  Fall  2015   24  


Residual  Plots  for  Delivery.lm  

Residuals vs Fitted Normal Q-Q

9 9

3
5

Standardized residuals

2
Residuals

1
0

0
-1
-5

1
20 1
20
-2

10 20 30 40 50 60 70 -2 -1 0 1 2

Fitted values Theoretical Quantiles

Week  9  -­‐  Fall  2015   25  


Robust  Reg  on  the  Delivery  Data  

Week  9  -­‐  Fall  2015   26  


Residual  Plots  for  Delivery.Robust  

Residuals vs Fitted Normal Q-Q

8
9 9
10

6
Standardized residuals
5

4
Residuals

2
0

0
-2
24
-5

1
24
1

10 20 30 40 50 60 70 -2 -1 0 1 2

Fitted values Theoretical Quantiles

Week  9  -­‐  Fall  2015   27  


Wednesdays  Class    
•  Watch  the  3  week  9  videos  and  answer  
ques\ons  5  –  7  on  the  Week  9  handout.    
•  Note:  I  recorded  these  last  fall  and  they  are  
called  ‘Lab  4’  but  I  refer  to  them  in  our  
lectures,  handouts,  and  mycourses  as  ‘Week  9  
Labs’    

Week  9  -­‐  Fall  2015   28  


Major  Assump\ons  
1.  The  error  term  ε  has  mean  =  zero      
2.  The  error  term  ε  has  constant  variance  (σ2)  
3.  The  errors  are  normally  distributed     Predictor  
4.  The  errors  are  uncorrelated     Assump\ons    

5.  The  rela\onship  between  the  response  y  and  


the  regression  variables  is  correct    
6.  The  regression  variables  are  independent    

Week  9  -­‐  Fall  2015   29  


Mul\collinearity  
•  The  presence  of  mul\collinearity  (near-­‐linear  
dependence  among  the  regression  variables)  
has  several  effects  on  the  ordinary  least-­‐
squares  regression  procedure    
–  A  singular  X’X  matrix,  meaning  that  the  ability  to  
es\mate  regression  coefficients  will  be  impacted,  
thus  the  predic\on  equa\ons  will  be  poor  
–  Large  variance  and  covariances  for  the  least-­‐
squares  es\mators  of  the  regression  coefficients        

Week  9  -­‐  Fall  2015   30  


What  to  Do  about  Mul\collinearity  
•  Do  nothing  
•  Collect  more  data  (and  in  the  right  places)    
•  Based  on  your  knowledge  of  regressors,  
remove  regressors  or  combine  regressors    
•  Use  principle  components  to  let  the  data  help  
you  decide  which  linear  combina\ons  of  
regressors  to  use    
•  Use  variable  selec\on  strategies  perform  
variable  selec\on  
Week  9  -­‐  Fall  2015   31  
Collect  More  Data  
•  It  is  important  to  realize  this  is  a  great  op\on  
for  unconfusing  regression  variables    
•  We  are  owen  limited  on  the  amount  of  data  
we  can  collect  and  some\mes  this  isn’t  an  
op\on    
•  Keep  in  mind  that  even  if  you  do  collect  more  
data,  you  might  s\ll  have  problems  with  
collinearity  

Week  9  -­‐  Fall  2015   32  


Remove  or  Combine  Regressors  
 Defense  Language  Ins\tute  study  concerning  program  graduate  
effec\veness  
                 x1,  x2,  …,x6  are  a    sequence  of  quarterly  exam  scores  
 

                   Replace  the  6  exam  scores  with  


 

                                         z1  =  average  of  the  6  exam  scores  


                                         z2  =    

Week  9  -­‐  Fall  2015   33  


Week  9  -­‐  Fall  2015   34  
Week  9  -­‐  Fall  2015   35  
Week  9  -­‐  Fall  2015   36  
Week  9  -­‐  Fall  2015   37  
Week  9  -­‐  Fall  2015   38  
Week  9  -­‐  Fall  2015   39  
Week  9  -­‐  Fall  2015   40  
Property  Valua\on  Data  

Week  9  -­‐  Fall  2015   41  


Property  Value  PC’s    

Week  9  -­‐  Fall  2015   42  


Using  the  PC  Scores  
•  We  can  use  the  results  of  the  principle  
components  analysis  to  combine  regression  
variables  in  the  model  

Week  9  -­‐  Fall  2015   43  


Week  9  Handout  Ques\on  9  

Week  9  -­‐  Fall  2015   44  


Notes  on  PC  
•  PC  is  a  good  tool  to  explore  the  dimensionality  of  a  space  separate  from  
regression.  
•  Performing  PC  on  the  centered  and  scaled  variables  is  equivalent  to  finding  
the  eigen  values  and  vectors  of  the  correla\on  matrix  of  the  x’s.  
•  Replacing  m  regressors  with  m’  <  m  linear  combina\ons  of  the  m  regressors  
will  reduce  the  number  of  regressors.  The  trade-­‐offs  are:  
–  Unless  you  are  lucky    or  very  crea\ve,  the  principle  components  aren’t  as  easily  interpreted  
as  the  original  variables  
–  You  will  introduce  some  bias.  

•  There  are  other  rota\ons  which  are  close  to  orthogonal,  but  try  to  force  
loadings  to  0,  to  make  PC’s  more  interpretable.  You  might  use  the  PC  as  a  
guide  to  how  you  want  to  combine  regressors.  
•  And,  just  because  you  went  to  the  trouble  to  find  PC’s  doesn’t  mean  that  
they  will  be  important  in  the  regression.  

Week  9  -­‐  Fall  2015   45  


R  Code  
>  Property<-­‐  read.csv(file.choose())  
>  Property  
>  pairs(Property)  
>  Property.lm  <-­‐  lm(y~.,  data  =  Property)  
>  summary(Property.lm)  
>  anova(Property.lm)  
>    drop1(Property.lm,  test  =  "F")  
>  cor(model.matrix(Property.lm)[,-­‐1])  
>  summary(Property.lm,  correla\on  =  T)  
>  Property.pc  <-­‐  prcomp(Property[,c(2:10)])  
>  Property.pc  

Week  9  -­‐  Fall  2015   46  

Вам также может понравиться