[R-sig-Geo] "Spdep" linear regression code
Roger Bivand
Roger.Bivand at nhh.no
Tue Oct 25 19:36:17 CEST 2011
On Tue, 25 Oct 2011, Mariana Benitez rojas wrote:
> Dear list,
>
> I am trying to study the code for spatial econometrics models in the
> "spdep" package. The code is understandable but I have some parts that I
> don't? understand for example why we need to do lm(y ~ x - 1) instead of
> just lm(y ~ x) since in other regression models in R we supposedly are
> doing this way instead of reducing the x by one.
You are looking at the implementation code, but do not say what version.
The code is not written to be understandable, but to work - most code
tries to handle corner cases. Here, the lm() function is being used on the
matrix of right-hand side variables, including the intercept, to see
whether the user has included aliased (very collinear) variables.
Consequently, -1 is added to the formula to tell lm() not to include an
intercept. If covariates are aliased, they are omitted in ML fitting.
>
> Also for "lagsarlm" we use three types of regression lm.base(), lm.lag()
> and the simple (y~1) model so I am not sure which model is being used to
> compare against the lm.lag() or how we get the LR statistics.
The intercept-only model is used to prepare a part of the Nagelkerke
pseudo-R2.
> Fore
> "errorsarlm" and "sacsarlm" we have the same situation but using
> lm.target() instead of lm.lag().
>
You probably need to know more R to read the code - these sub-objects and
steps are not of great interest, and do not give you the log likelihood,
which is shown in the summary(), and (surprisingly) logLik() methods for
sarlm objects. For LR statistics, use the LR.sarlm() function.
>
> I would be so thankful if anybody could give the answer or show me the
> material that I can use for my study.
You have not explained what the point of your study is, as far as I can
see. The functions are fitting by maximum likelihood, and doing lots of
extra things to accommodate for example alternative methods for computing
the Jacobian, and for estimating the coefficient covariance matrix. So the
lines you have chosen to report are not very odd, just auxiliary
regressions used in getting to the user's chosen model fit.
Hope this clarifies,
Roger
>
>
>
> ?
> Mariana Benitez Rojas
>
>
> Centro Federal de Educa??o Tecnol?gico (CEFET-PA)
>
> [[alternative HTML version deleted]]
>
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list