Download S-Plus 4.5 Supplement
Transcript
CHAPTER 12 ROBUST LINEAR REGRESSION COMPARING LEAST SQUARES AND ROBUST FITS Creating a Comparison Object for LS and Robust Fits In the section Visualizing the Fit with the plot Function, we compared the residuals vs. fitted values plot for both the LS and robust fits. You might have noted that the two plots do not have the same vertical scale. It would be nice to have the capability of plotting different fits on the same scale for easy visual comparison and also making tabular displays of LS and robust fits which are conveniently aligned for ease of comparing inference results. To this end S-PLUS provides a function compare.fits, for creating a models comparison object, along with appropriate print, plot and summary methods for this class of object. For example, to compare the results from the two fits oil.ls and oil.robust, first create the comparison object oil.cmpr with the following command: > oil.cmpr <- compare.fits(oil.ls,oil.robust) The object returned by compare.fits is of class “compare.fits”. Now you can print a short summary of the comparison: > oil.cmpr Calls: oil.ls lm(formula = Oil ~ Market, data = oil.df) oil.robust lmRobMM(formula = Oil ~ Market, data = oil.df) Coefficients: oil.ls oil.robust (Intercept) 0.1474 -0.08396 Market 2.8567 0.82888 Residual Scale Estimates: oil.ls : 0.4867 on 127 degrees of freedom oil.robust : 0.1446 on 127 degrees of freedom Visualizing LS vs. Robust Fits You can easily plot a compare.fits object to obtain a visual comparison of the LS and robust fits: > plot(oil.cmpr) 166