SPLM sphtest Hausman test not working with Maximum Likelihood
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?
Patrick
# CODE OF REPRODUCIBLE EXAMPLE:
#-------------------------------------------------------------------------------
#FOR THIS LAB, WE WILL BE USING A BUILT-IN DATA PACKAGE IN R. WE'RE GOING TO BE
#ADHERING PRETTY CLOSELY TO THE APPROACH USED IN THE ARTICLE ON SPATIAL PANEL MODELS
#YOU LOOKED AT FOR CLASS.
install.packages("Ecdat") #THIS IS WHERE THE DATA ARE FOUND.
library(Ecdat)
install.packages("plm") #THIS IS THE PANEL MODEL PACKAGE
library(plm)
#THE DATA WE WILL BE USING IS DATA ON ECONOMIC PRODUCTIVITY IN THE UNITED STATES.
data(Produc) #THIS IS THE DATA
#MAYBE IT'S TIME FOR THE SPATIAL PANEL MODEL!
#IN ADDITION TO THE PACKAGES WE USED FOR THE PANEL MODEL, WE'LL NEED THESE:
install.packages("splm") #THIS IS THE SPATIAL PANEL MODEL PACKAGE
library(splm)
install.packages("spdep") #TO HELP US WITH OUR SPATIAL DATA
library(spdep)
#THE Ecdat LIBRARY CONVENIENTLY HAS A NEIGHBOR'S MATRIX FOR CONTIGUOUS US STATES:
data(usaww) #THIS IS THE ROW-STANDARDIZED QUEEN'S CASE CONTIGUITY WEIGHTS MATRIX FOR
#THE CONTIGUOUS US STATES
prod.panel <- pdata.frame(Produc, index = c("state", "year"))
#FIRST, LET'S CONVERT THAT REGULAR MATRIX INTO A SPATIAL WEIGHTS MATRIX:
usa.sp <- mat2listw(usaww) #JUST WHAT IT SOUNDS LIKE; TURNS A MATRIX INTO A SPATIAL
#WEIGHTS MATRIX.
#OKAY, SO THESE SUGGEST WE HAVE SOME ISSUES WITH SPATIAL AUTOCORRELATION AND
#INDIVIDUAL EFFECTS. BUT WE STILL NEET TO DETERMINE WHETHER WE CAN USE FIXED OR
#RANDOM EFFECTS. FORTUNATELY, WE HAVE A SPATIAL VERSION OF THE HAUSMAN TEST TO
#HELP US WITH THIS:
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"
)
# 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