# [R] Problems with lqs()

Kathrin Schmidt kat.schmidt1 at web.de
Tue Aug 4 15:01:15 CEST 2009

```Dear List-Members,

I have a problem with the function lqs() from package MASS. In some cases it produces different results for the same settings and needs a random seed to be set, in other cases not.
I really cannot understand, why this happens. As well I do not understand what exactly you need the random seed for. Is it a starting point for iterations? Or do different results occur because of the estimation doesn't converge?

I tried data "phones" from package MASS. You find this example as well in the MASS-book on page 160.

> lqs(calls~year, data=phones, method="lms")
Call:
lqs.formula(formula = calls ~ year, data = phones, method = "lms")

Coefficients:
(Intercept)         year
-55.947        1.155

Scale estimates 0.9377 0.9095

>
> lqs(calls~year, data=phones, method="S")
Call:
lqs.formula(formula = calls ~ year, data = phones, method = "S")

Coefficients:
(Intercept)         year
-52.5          1.1

Scale estimates 2.129

You can do it over and over again and get the same coefficients. In contrast, if u use other data like cats from MASS or simulated data, u get different outputs every time u start the code if not electing a random.seed.

> lqs(Hwt~Bwt, data=cats, method="S")
Call:
lqs.formula(formula = Hwt ~ Bwt, data = cats, method = "S")

Coefficients:
(Intercept)          Bwt
0.2625       3.6250

Scale estimates 1.474

> lqs(Hwt~Bwt, data=cats, method="S")
Call:
lqs.formula(formula = Hwt ~ Bwt, data = cats, method = "S")

Coefficients:
(Intercept)          Bwt
0.4714       3.5714

Scale estimates 1.474

Example with simulated data:

> b0<--1
> b1<-6
> b2<-0.8
> b3<--0.5
>
> x1<-runif(200,-3,3)
> x2<-runif(200,20,40)
> x3<-rbinom(200, 1, 0.7)
> e<-rnorm(200,0,1)
> y<-b0+b1*x1+b2*x2+b3*x3+e
> lqs(y~x1, method="lms")
Call:
lqs.formula(formula = y ~ x1, method = "lms")

Coefficients:
(Intercept)           x1
22.239        4.964

Scale estimates 5.379 4.891

>
> lqs(y~x1, method="S")
Call:
lqs.formula(formula = y ~ x1, method = "S")

Coefficients:
(Intercept)           x1
23.193        5.743

Scale estimates 5.642

> lqs(y~x1, method="lms")
Call:
lqs.formula(formula = y ~ x1, method = "lms")

Coefficients:
(Intercept)           x1
21.176        5.255

Scale estimates 5.383 5.023

>
> lqs(y~x1, method="S")
Call:
lqs.formula(formula = y ~ x1, method = "S")

Coefficients:
(Intercept)           x1
22.55         5.46

Scale estimates 5.642

I appreciate it!

K. Schmidt

________________________________________________________________
Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/

```