Language Reference

LMS Call

CALL LMS (sc, coef, wgt, opt, y <, x> <, sorb> ) ;

This subroutine is supported only by the IML procedure.

The LMS subroutine performs least median of squares (LMS) robust regression (sometimes called resistant regression) by minimizing the hth-ordered squared residual. The subroutine is able to detect outliers and perform a least squares regression on the remaining observations.

The algorithm used in the LMS subroutine is based on the PROGRESS program of Rousseeuw and Hubert (1996), which is an updated version of Rousseeuw and Leroy (1987). In the special case of regression through the origin with a single regressor, Barreto and Maharry (2006) show that the PROGRESS algorithm does not, in general, find the slope that yields the least median of squares. Starting with SAS/IML 9.2, the LMS subroutine uses the algorithm of Barreto and Maharry (2006) to obtain the correct LMS slope in the case of regression through the origin with a single regressor. In this case, input arguments that are specific to the PROGRESS algorithm are ignored and output specific to the PROGRESS algorithm is suppressed.

The value of h can be specified, but in most applications the default value works well and the results seem to be quite stable toward different choices of h.

In the following discussion, N is the number of observations and n is the number of regressors. The input arguments to the LMS subroutine are as follows:

opt

specifies an options vector. The options vector can be a vector of missing values, which results in default values for all options. The components of opt are as follows:

opt[1]

specifies whether an intercept is used in the model (opt[1]=0) or not (opt[1]not-equals 0). If opt[1]=0, then a column of ones is added as the last column to the input matrix bold upper X; that is, you do not need to add this column of ones yourself. The default is opt[1]=0.

opt[2]

specifies the amount of printed output. Higher values request additional output and include the output of lower values.

0

prints no output except error messages.

1

prints all output except (1) arrays of upper O left-parenthesis upper N right-parenthesis, such as weights, residuals, and diagnostics; (2) the history of the optimization process; and (3) subsets that result in singular linear systems.

2

additionally prints arrays of upper O left-parenthesis upper N right-parenthesis, such as weights, residuals, and diagnostics; also prints the case numbers of the observations in the best subset and some basic history of the optimization process.

3

additionally prints subsets that result in singular linear systems.

The default is opt[2]=0.

opt[3]

specifies whether only LMS is computed or whether, additionally, least squares (LS) and weighted least squares (WLS) regression are computed.

0

computes only LMS.

1

computes, in addition to LMS, weighted least squares regression on the observations with small LMS residuals (where small is defined by opt[8]).

2

computes, in addition to LMS, unweighted least squares regression.

3

adds both unweighted and weighted least squares regression to LMS regression.

The default is opt[3]=0.

opt[4]

specifies the quantile h to be minimized. This is used in the objective function. The default is opt[4]equals h equals left-bracket StartFraction upper N plus n plus 1 Over 2 EndFraction right-bracket, which corresponds to the highest possible breakdown value. This is also the default of the PROGRESS program. The value of h should be in the range StartFraction upper N Over 2 EndFraction plus 1 less-than-or-equal-to h less-than-or-equal-to StartFraction 3 upper N Over 4 EndFraction plus StartFraction n plus 1 Over 4 EndFraction

opt[5]

specifies the number upper N Subscript normal upper R normal e normal p of generated subsets. Each subset consists of n observations left-parenthesis k 1 comma ellipsis comma k Subscript n Baseline right-parenthesis, where 1 less-than-or-equal-to k Subscript i Baseline less-than-or-equal-to upper N. The total number of subsets that contain n observations out of N observations is

upper N Subscript normal t normal o normal t Baseline equals StartBinomialOrMatrix upper N Choose n EndBinomialOrMatrix equals StartFraction product Underscript j equals 1 Overscript n Endscripts left-parenthesis upper N minus j plus 1 right-parenthesis Over product Underscript j equals 1 Overscript n Endscripts j EndFraction

where n is the number of parameters including the intercept.

Due to computer time restrictions, not all subset combinations of n observations out of N can be inspected for larger values of N and n. Specifying a value of upper N Subscript normal upper R normal e normal p Baseline less-than upper N Subscript normal t normal o normal t enables you to save computer time at the expense of computing a suboptimal solution.

If opt[5] is zero or missing, the default number of subsets is taken from the following table.

n 1 2 3 4 5 6 7 8 9 10
upper N Subscript normal l normal o normal w normal e normal r 500 50 22 17 15 14 0 0 0 0
upper N Subscript normal u normal p normal p normal e normal r 10 Superscript 6 1414 182 71 43 32 27 24 23 22
upper N Subscript normal upper R normal e normal p 500 1000 1500 2000 2500 3000 3000 3000 3000 3000

n 11 12 13 14 15
upper N Subscript normal l normal o normal w normal e normal r 0 0 0 0 0
upper N Subscript normal u normal p normal p normal e normal r 22 22 22 23 23
upper N Subscript normal upper R normal e normal p 3000 3000 3000 3000 3000

If the number of cases (observations) N is smaller than upper N Subscript normal l normal o normal w normal e normal r, then all possible subsets are used; otherwise, upper N Subscript normal upper R normal e normal p subsets are chosen randomly. This means that an exhaustive search is performed for opt[5]=negative 1. If N is larger than upper N Subscript normal u normal p normal p normal e normal r, a note is printed in the log file that indicates how many subsets exist.

opt[6]

is not used.

opt[7]

specifies whether the last argument sorb contains a given parameter vector bold b or a given subset for which the objective function should be evaluated.

0

sorb contains a given subset index.

1

sorb contains a given parameter vector bold b.

The default is opt[7]=0.

opt[8]

is relevant only for LS and WLS regression (opt[3] > 0). It specifies whether the covariance matrix of parameter estimates and approximate standard errors (ASEs) are computed and printed.

0

does not compute covariance matrix and ASEs.

1

computes covariance matrix and ASEs but prints neither of them.

2

computes the covariance matrix and ASEs but prints only the ASEs.

3

computes and prints both the covariance matrix and the ASEs.

The default is opt[8]=0.

y

refers to an N response vector.

x

refers to an upper N times n matrix bold upper X of regressors. If opt[1] is zero or missing, an intercept bold x Subscript n plus 1 Baseline identical-to 1 is added by default as the last column of bold upper X. If the matrix bold upper X is not specified, bold y is analyzed as a univariate data set.

sorb

refers to an n vector that contains either of the following:

  • n observation numbers of a subset for which the objective function should be evaluated; this subset can be the start for a pairwise exchange algorithm if opt[7] is specified.

  • n given parameters bold b equals left-parenthesis b 1 comma ellipsis comma b Subscript n Baseline right-parenthesis (including the intercept, if necessary) for which the objective function should be evaluated.

Missing values are not permitted in x or y. Missing values in opt cause the default value to be used.

The LMS subroutine returns the following values:

sc

is a column vector that contains the following scalar information, where rows 1–9 correspond to LMS regression and rows 11–14 correspond to either LS or WLS:

sc[1]

the quantile h used in the objective function

sc[2]

number of subsets generated

sc[3]

number of subsets with singular linear systems

sc[4]

number of nonzero weights w Subscript i

sc[5]

lowest value of the objective function upper F Subscript normal upper L normal upper M normal upper S attained

sc[6]

preliminary LMS scale estimate upper S Subscript upper P

sc[7]

final LMS scale estimate upper S Subscript upper F

sc[8]

robust R square (coefficient of determination)

sc[9]

asymptotic consistency factor

If opt[3] > 0, then the following are also set:

sc[11]

LS or WLS objective function (sum of squared residuals)

sc[12]

LS or WLS scale estimate

sc[13]

R square value for LS or WLS

sc[14]

F value for LS or WLS

For opt[3]=1 or opt[3]=3, these rows correspond to WLS estimates; for opt[3]=2, these rows correspond to LS estimates.

coef

is a matrix with n columns that contains the following results in its rows:

coef[1,]

LMS parameter estimates

coef[2,]

indices of observations in the best subset

If opt[3] > 0, then the following are also set:

coef[3,]

LS or WLS parameter estimates

coef[4,]

approximate standard errors of LS or WLS estimates

coef[5,]

t values

coef[6,]

p-values

coef[7,]

lower boundary of Wald confidence intervals

coef[8,]

upper boundary of Wald confidence intervals

For opt[3]=1 or opt[3]=3, these rows correspond to WLS estimates; for opt[3]=2, these rows correspond to LS estimates.

wgt

is a matrix with N columns that contains the following results in its rows:

wgt[1,]

weights (1 for small residuals; 0 for large residuals)

wgt[2,]

residuals r Subscript i Baseline equals y Subscript i Baseline minus bold x Subscript i Baseline bold b

wgt[3,]

resistant diagnostic u Subscript i (the resistant diagnostic cannot be computed for a perfect fit when the objective function is zero or nearly zero)

Example

Consider results for Brownlee (1965) stackloss data. The three explanatory variables correspond to measurements for a plant that oxidizes ammonia to nitric acid on 21 consecutive days.

  • x 1 air flow to the plant

  • x 2 cooling water inlet temperature

  • x 3 acid concentration

The response variable y Subscript i contains the permillage of ammonia lost (stackloss). The data are also given by Rousseeuw and Leroy (1987) and Osborne (1985). Rousseeuw and Leroy (1987) cite a large number of papers where this data set was analyzed and state that most researchers "concluded that observations 1, 3, 4, and 21 were outliers," and that some people also reported observation 2 as an outlier.

For upper N equals 21 and n equals 4 (three explanatory variables including intercept), you obtain a total of 5,985 different subsets of 4 observations out of 21. If you decide not to specify opt[5], the LMS subroutine chooses upper N Subscript normal r normal e normal p Baseline equals2,000 random sample subsets. Since there is a large number of subsets with singular linear systems, which you do not want to print, choose opt[2]=2 for reduced printed output.

   /* X1  X2  X3   Y  Stackloss data */
aa = { 1  80  27  89  42,
       1  80  27  88  37,
       1  75  25  90  37,
       1  62  24  87  28,
       1  62  22  87  18,
       1  62  23  87  18,
       1  62  24  93  19,
       1  62  24  93  20,
       1  58  23  87  15,
       1  58  18  80  14,
       1  58  18  89  14,
       1  58  17  88  13,
       1  58  18  82  11,
       1  58  19  93  12,
       1  50  18  89   8,
       1  50  18  86   7,
       1  50  19  72   8,
       1  50  19  79   8,
       1  50  20  80   9,
       1  56  20  82  15,
       1  70  20  91  15 };

a = aa[, 2:4]; b = aa[, 5];
opt = j(8, 1, .);
opt[2]= 2;    /* ipri */
opt[3]= 3;    /* ilsq */
opt[8]= 3;    /* icov */

call lms(sc, coef, wgt, opt, b, a);

The first portion of the output displays descriptive statistics, as shown in Figure 230:

Figure 230: Descriptive Statistics


LMS: The 13th ordered squared residual will be minimized.

Median and Mean
  Median Mean
VAR15860.428571429
VAR22021.095238095
VAR38786.285714286
Intercep11
Response1517.523809524

Dispersion and Standard Deviation
 Dispersion StdDev
VAR15.9304088749.1682682584
VAR22.9652044373.160771455
VAR34.44780665555.3585712381
Intercep00
Response5.93040887410.171622524


The next portion of the output shows the least squares estimates and the covariance of the estimates. Information about the residuals are also displayed, but are not shown in Figure 231.

Figure 231: Least Squares Estimates


Unweighted Least-Squares Estimation

LS Parameter Estimates
VariableEstimateApprox
Std Err
t ValuePr > |t|Lower WCIUpper WCI
VAR10.71564020.134858195.31<.00010.451323010.97995739
VAR21.295286120.368024273.520.00260.573971822.01660043
VAR3-0.15212250.15629404-0.970.3440-0.45845320.15420818
Intercep-39.91967411.8959969-3.360.0038-63.2354-16.603949


Sum of Squares = 178.8299616


Degrees of Freedom = 17


LS Scale Estimate = 3.2433639182

Cov Matrix of Parameter Estimates
 VAR1VAR2VAR3Intercep
VAR10.0181867302-0.036510675-0.0071435210.2875871057
VAR2-0.0365106750.13544185980.0000104768-0.651794369
VAR3-0.0071435210.00001047680.024427828-1.676320797
Intercep0.2875871057-0.651794369-1.676320797141.51474107


R-squared = 0.9135769045


F(3,17) Statistic = 59.9022259


Probability = 3.0163272E-9


The LMS subroutine prints results for the 2,000 random subsets. Figure 232 shows the iteration history, the best subset of observations that are used to form estimates, and the estimated parameters. The subroutine also displays residual information (not shown).

Figure 232: Least Median Squares Estimates


There are 5985 subsets of 4 cases out of 21 cases.


The algorithm will draw 2000 random subsets of 4 cases.


Random Subsampling for LMS

SubsetSingularBest
Criterion
Percent
500230.16326225
1000550.14051950
1500790.14051975
20001030.126467100


Minimum Criterion= 0.1264668282


Least Median of Squares (LMS) Method


Minimizing 13th Ordered Squared Residual.


Highest Possible Breakdown Value = 42.86 %


Random Selection of 2103 Subsets


Among 2103 subsets 103 is/are singular.

Observations of Best Subset
15111910

Estimated Coefficients
VAR1VAR2VAR3Intercep
0.750.50-39.25


Observations 1, 3, 4, and 21 have scaled residuals larger than 2.0 (table not shown) and are considered outliers. The corresponding WLS estimates are shown in Figure 233:

Figure 233: Weighted Least Squares Estimates


LMS Objective Function = 0.75


Preliminary LMS Scale = 1.0478510755


Robust R Squared = 0.96484375


Final LMS Scale = 1.2076147288

LMS Residuals
NObservedEstimatedResidualRes / S
142.00000034.2500007.7500006.417610
237.00000034.2500002.7500002.277216
337.00000029.5000007.5000006.210590
428.00000019.2500008.7500007.245688
518.00000018.250000-0.250000-0.207020
618.00000018.750000-0.750000-0.621059
719.00000019.250000-0.250000-0.207020
820.00000019.2500000.7500000.621059
915.00000015.750000-0.750000-0.621059
1014.00000013.2500000.7500000.621059
1114.00000013.2500000.7500000.621059
1213.00000012.7500000.2500000.207020
1311.00000013.250000-2.250000-1.863177
1412.00000013.750000-1.750000-1.449138
158.0000007.2500000.7500000.621059
167.0000007.250000-0.250000-0.207020
178.0000007.7500000.2500000.207020
188.0000007.7500000.2500000.207020
199.0000008.2500000.7500000.621059
2015.00000012.7500002.2500001.863177
2115.00000023.250000-8.250000-6.831649


Distribution of Residuals

MinRes 1st Qu. Median Mean 3rd Qu. MaxRes
-8.25-0.50.250.90476190480.758.75

Resistant Diagnostic
NUResistant
Diagnostic
110.4480522.278040
27.9317511.729399
310.0000002.180349
411.6666672.543741
52.7297300.595176
63.4864860.760176
74.7297301.031246
84.2432430.925175
93.6486490.795533
103.7598350.819775
114.6057671.004218
124.9251691.073859
133.8888890.847914
144.5864211.000000
155.2970301.154938
164.0099010.874299
176.6795761.456381
184.3053400.938715
194.0199760.876495
203.0000000.654105
2111.0000002.398384


Median(U)= 4.5864208797


Weighted Least-Squares Estimation

RLS Parameter Estimates Based on LMS
VariableEstimateApprox
Std Err
t ValuePr > |t|Lower WCIUpper WCI
VAR10.797685560.0674390611.83<.00010.665507420.9298637
VAR20.577340460.165968943.480.00410.252047310.9026336
VAR3-0.06706020.06160314-1.090.2961-0.18780010.05367975
Intercep-37.6524594.73205086-7.96<.0001-46.927108-28.37781


Weighted Sum of Squares = 20.400800254


Degrees of Freedom = 13


RLS Scale Estimate = 1.2527139846

Cov Matrix of Parameter Estimates
 VAR1VAR2VAR3Intercep
VAR10.0045480273-0.007921409-0.0011986890.0015681747
VAR2-0.0079214090.0275456893-0.00046339-0.065017508
VAR3-0.001198689-0.000463390.0037949466-0.246102248
Intercep0.0015681747-0.065017508-0.24610224822.392305355


Weighted R-squared = 0.9750062263


F(3,13) Statistic = 169.04317954


Probability = 1.158521E-10


There are 17 points with nonzero weight.


Average Weight = 0.8095238095


Last updated: May 07, 2026