[R-sig-Geo] SPLM sphtest Hausman test not working with Maximum Likelihood

Roger Bivand Roger.Bivand at nhh.no
Fri Feb 28 15:58:32 CET 2014


On Fri, 28 Feb 2014, Patrick Meyfroidt wrote:

> Thanks Roger, and sorry. 
>
> My code and data are a bit long to put here, but thanks to Caleb 
> Gallemore which had a similar problem, I can post here a test code that 
> he made for students, which uses data from Ecdat package.
>
> This code below, as well as my code, were tested with:
> R 2.15.1 and splm_1.1-0 (the current stable version)
> and R 3.0.2 and splm_1.2-0 (the development version)
>
> I hope that this addresses your rightful concerns,
>
> Now, if anyone has a suggestion (other than moving to Matlab..), that 
> would be very welcome?

<flare>Feel free, silly remarks really motivate us to improve the 
software</flare>, seriously, have you any idea how much of their own time 
R and package developers use to keep all this running?

The actual response below - if you want to benefit from community effort, 
do try to understand how things work. If you are "above that", just keep 
to our rules here and keep your jokes to yourself.

>
> Patrick 
>
>
> # CODE OF REPRODUCIBLE EXAMPLE:
> #-------------------------------------------------------------------------------
>

library(Ecdat)
library(plm)
data(Produc) #THIS IS THE DATA
library(splm)
library(spdep)
data(usaww) #THIS IS THE ROW-STANDARDIZED QUEEN'S CASE CONTIGUITY WEIGHTS MATRIX FOR 
prod.panel <- pdata.frame(Produc, index = c("state", "year"))
usa.sp <- mat2listw(usaww) #JUST WHAT IT SOUNDS LIKE; TURNS A MATRIX INTO A SPATIAL
prod.fm <- log(gsp) ~ 1 + log(pcap) + log(pc) + log(emp)
sphtest(prod.fm, data=prod.panel, listw=usa.sp, spatial.model="sarar",
   method="ML")

shortens this somewhat, the rest is superfluous and is not a big deal. The 
error is reproducible with 1.1-0 and 1.2-0. I've CC'd the maintainer.

Standard practice is to run traceback() to identify the failing function:

> traceback()
5: stop("'arg' must be NULL or a character vector")
4: match.arg(spatial.error)
3: spml(x, data = data, index = index, listw = listw, lag = lag,
        spatial.error = spatial.error, model = "within", errors = errors)
2: sphtest.formula(prod.fm, data = prod.panel, listw = usa.sp, 
spatial.model = "sarar", method = "ML")
1: sphtest(prod.fm, data = prod.panel, listw = usa.sp, spatial.model = 
"sarar", method = "ML")

here spml.

Running inside debug(spml) shows that match.arg(spatial.error) occurs in a 
context where it has been given a logical value TRUE by sphtest.formula, 
but should be one of c("b","kkp","none").

The package has been being simplified and the arguments have got mixed up, 
it happens. The examples for sphtest() only check its performance with 
method="GM" - they work OK, so additional checks with method="ML" are 
needed, but perhaps within a \donttest block, once the problem has been 
resolved.

Users who find issues with software are expected to help developers 
promptly, in a case like this by doing as much of the debugging as 
possible themselves, and then at least contacting the maintainer of the 
involved package.

From viewing the SVN repository, it isn't immediately obvious where the 
bug has come from, but spatial.error is used in sphtest.formula with lag 
to pass through the kind of model rather than the type of spatial error. 
The authors of the package would welcome further analysis and patches.

Roger

>
> # HERE IS THE PROBLEM: THE TEST RETURNS: 
> # "Error in match.arg(spatial.error) :   'arg' must be NULL or a character vector"
>
> # JUST TO CHECK: THE RANDOM EFFECTS AND FIXED EFFECTS MODELS DO WORK PROPERLY:
> prod.fm.rd <- spml(formula = prod.fm,
> 			data = prod.panel,
> 			listw = usa.sp,
> 			listw2 = usa.sp,
> 			model = "random",
> 			effect = "individual",
> 			lag = TRUE,
> 			spatial.error = "b")
> summary.splm(prod.fm.rd)
> prod.fm.fe <- spml(formula = prod.fm,
> 			data = prod.panel,
> 			listw = usa.sp,
> 			listw2 = usa.sp,
> 			model = "within",
> 			effect = "individual",
> 			lag = TRUE,
> 			spatial.error = "b")
> summary.splm(prod.fm.fe)
>
> #-------------------------------------------------------------------------------
>
>
>
>
> ________________________________________
> De : Roger Bivand <Roger.Bivand at nhh.no>
> Envoyé : mardi 25 février 2014 15:11
> À : Patrick Meyfroidt
> Cc : r-sig-geo at r-project.org
> Objet : Re: [R-sig-Geo] SPLM sphtest Hausman test not working with Maximum Likelihood
>
> On Tue, 25 Feb 2014, Patrick Meyfroidt wrote:
>
>> Dear List,
>>
>> I have a problem using splm package: across various datasets and models,
>> the sphtest function never works when I try to calculate the Hausman
>> test with a model using Maximum Likelihood. I always receive the
>> following error message:
>>
>> Error in match.arg(spatial.error) :
>>  'arg' must be NULL or a character vector
>>
>> I see that several other people posted the same problem before, but
>> apparently there was not solution proposed on the list: in September
>> 2011:
>> https://stat.ethz.ch/pipermail/r-sig-geo/2011-September/012826.html and
>> in May 2013:
>> https://stat.ethz.ch/pipermail/r-sig-geo/2013-May/018256.html
>>
>> Does anyone have a solution?
>
> Please never guess, it only misleads you and readers of your posting.
>
> Please always state the output of sessionInfo() - we don't know which
> version of splm you are using.
>
> Please always include a reproducible example of the code leading to the
> error with a built in data set.
>
> Do check that the problem is not already resolved in the development
> version on R-forge, here:
>
> https://r-forge.r-project.org/R/?group_id=352
>
>>
>> Thank you very much,
>>
>>
>> Patrick Meyfroidt ------ F.R.S. - FNRS and Universit? catholique de
>> Louvain - UCLouvain
>>
>>
>>       [[alternative HTML version deleted]]
>
> Finally, do not post HTML, much of the extensive carbon footprint of lists
> like this comes from scanning HTML postings for unwanted and/or dangerous
> payloads.
>
> Hope this helps,
>
> Roger
>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> --
> 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 95 43
> e-mail: Roger.Bivand at nhh.no

-- 
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 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list