# [R] Simple lm/regression question

James Annan jdannan at jamstec.go.jp
Tue Feb 7 02:32:48 CET 2012

```On 6/2/12 19:36 , peter dalgaard wrote:

> Actually, I think the issue is slightly different:  IDL assumes that
> the errors _are_ something (notice that setting measure_errors to 1
> is not equvalent to omitting them), R assumes that they are
> _proportional_ to the inverse weights

Yes, I think this is correct.

> There are a couple of ways to avoid the use of the estimated
> multiplicative dispersion parameter in R, one is to extract
> cov.unscaled from the summary,

Thanks, this appears to give me what I am looking for. In fact it seems
that cov and cov.unscaled give identical results which *do* account for
the weights in each case. The default seems to be weights = 1 (ie, an
actual measurement error of 1). Anyway, this now reconciles with what I
was used to with IDL.

eg:

> summary(lm(y~x))\$cov
(Intercept)    x
(Intercept)         1.5 -0.5
x                  -0.5  0.2
> summary(lm(y~x))\$cov.unscaled
(Intercept)    x
(Intercept)         1.5 -0.5
x                  -0.5  0.2
> summary(lm(y~x,weights=c(10,10,10,10)))\$cov
(Intercept)     x
(Intercept)        0.15 -0.05
x                 -0.05  0.02
> summary(lm(y~x,weights=c(10,10,10,10)))\$cov.unscaled
(Intercept)     x
(Intercept)        0.15 -0.05
x                 -0.05  0.02
> summary(lm(y~x,weights=c(10,10,1,1)))\$cov.unscaled
(Intercept)           x
(Intercept)   0.2669039 -0.13167260
x            -0.1316726  0.07829181
> summary(lm(y~x,weights=c(10,10,1,1)))\$cov
(Intercept)           x
(Intercept)   0.2669039 -0.13167260
x            -0.1316726  0.07829181

and the last case in IDL:

IDL>
vec=linfit(x,y,sigma=sig,measure_errors=[sqrt(.1),sqrt(.1),1,1],covar=cov)
IDL> print,cov
0.266904    -0.131673
-0.131673    0.0782918

(the other parameters also agree!)

--
James D Annan jdannan at jamstec.go.jp Tel: +81-45-778-5618 (Fax 5707)
Senior Scientist, Research Institute for Global Change, JAMSTEC
Yokohama Institute for Earth Sciences, 3173-25 Showamachi,
Kanazawa-ku, Yokohama City, Kanagawa, 236-0001 Japan
http://www.jamstec.go.jp/frcgc/research/d5/jdannan/

```