Skip to content
Prev 21949 / 29559 Next

Cause of error in spdep::errorsarlm

Thanks very much Roger and Frede

This was very helpful.  

I have somehow managed to run some quite intricate model fitting and model selection code over several years, while handling formulas entirely as text, and being almost completely unaware of the formula class and associated functions such as model.frame.  But now I am elightened!

By the way Roger, I just found that errorsarlm works beautifully with dredge {MuMIn} for model selection and averaging.  The two together have just saved large amounts of time and coding compared to previous analyses.

cheers
Dan

-----Original Message-----
From: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Sent: Thursday, 6 November 2014 11:46 PM
To: Frede Aakmann T?gersen
Cc: Dan Rosauer; r-sig-geo at r-project.org
Subject: RE: Cause of error in spdep::errorsarlm
On Wed, 5 Nov 2014, Frede Aakmann T?gersen wrote:

            
Thanks for a careful diagnosis. I've committed (R-forge, revision 563) simple fixes to all model fitting functions in spdep that used the formula argument without checking that it is of class "formula". Only spautolm() used the full model.frame() mechanism before, and this distinction remains.

With released spdep:

SAR.mod <- errorsarlm(as.formula(my_formula), data=df,
   listw=weight_list)

and

SAR.mod <- spautolm(my_formula, data=df, listw=weight_list)

give the same output. With the next release, the as.formula() is done internally. spautolm() was written in 2005/6, the others from 1998 onwards, and the differences in handling model.frame objects stem from practice in lm() at those times.

I can see that using a string to hold a formula may seem attractive as it permits paste() and other string functions to be used to modify the formula. I would however suggest that using the update() method for formulae is at least as flexible, and that formula arguments be given as formula objects, not as strings, even if this usage is possible.

Best wishes,

Roger
--
Roger Bivand
Department of Economics, Norwegian School of Economics, Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no