R language Access Menu

Title Text Both  

Robust regression

Simple linear regression is sensitive to outliers while robust regression is not. However, robust regression is not used as a routine since in absence of outliers, simple linear regression has greater power. The functions rlm of MASS package can be used for this: 

Code:

> library(MASS)
> bwdf = mybwdf(F)
> str(bwdf)
'data.frame':   189 obs. of  9 variables:
 $ age  : int  19 33 20 21 18 21 22 17 29 26 ...
 $ lwt  : int  182 155 105 108 107 124 118 103 123 113 ...
 $ race : Factor w/ 3 levels "1","2","3": 2 3 1 1 1 3 1 3 1 1 ...
 $ smoke: Factor w/ 2 levels "0","1": 1 1 2 2 2 1 1 1 2 2 ...
 $ ptl  : int  0 0 0 0 0 0 0 0 0 0 ...
 $ ht   : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
 $ ui   : Factor w/ 2 levels "0","1": 2 1 1 2 2 1 1 1 1 1 ...
 $ ftv  : int  0 3 1 2 0 0 1 1 1 0 ...
 $ bwt  : int  2523 2551 2557 2594 2600 2622 2637 2637 2663 2665 ...

> mod = rlm(bwt~., bwdf)
> summary(mod)

Call: rlm(formula = bwt ~ ., data = bwdf)
Residuals:
     Min       1Q   Median       3Q      Max 
-1840.66  -453.84    44.83   472.35  1741.56 

Coefficients:
            Value     Std. Error t value  
(Intercept) 2927.1465  323.2615     9.0550
age           -5.5991    9.9387    -0.5634
lwt            4.7445    1.7930     2.6460
race2       -489.9354  154.9491    -3.1619
race3       -335.2751  118.5517    -2.8281
smoke1      -352.7716  110.0008    -3.2070
ptl          -68.9633  105.3469    -0.6546
ht1         -612.8685  209.0180    -2.9321
ui1         -499.2599  143.4825    -3.4796
ftv          -10.3178   48.0061    -0.2149

Residual standard error: 690.3 on 179 degrees of freedom


References:
mass package: Venables, W. N. & Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth Edition. Springer, New York. ISBN 0-387-95457-0 
https://cran.r-project.org/web/packages/MASS/index.html
 


    Comments & Feedback