[R-sig-Geo] Error object 'can.sim2' not found in spatianl panel data - splm with spdep

Patrick Meyfroidt patrick.meyfroidt at uclouvain.be
Tue Oct 9 21:39:17 CEST 2012


Thanks Roger,

I hope it can help,

Patrick


> On Tue, 9 Oct 2012, Patrick Meyfroidt wrote:
>
>> OK, now it appears that probably my problem was due to poor
>> understanding
>> of how I had to create the listw object with spdep.
>>
>> Starting from the nearest neighbor identification, what I was doing was:
>> ruskn5 <- knearneigh(coords, k=5, longlat = NULL)
>> ruskn5.nb <- knn2nb(ruskn5, row.names=rus$index, sym = FALSE)
>> wrus.knb5 <- nb2listw(ruskn5.nb, glist=NULL, style="W",
>> zero.policy=NULL)
>>
>> which I used before to deal with simple cross-section data.
>>
>> Re-reading the spdep manual, I changed to:
>> ruskn5 <- knearneigh(coords, k=5, longlat = NULL)
>> ruskn5.nb <- knn2nb(ruskn5, row.names=rus$index, sym = FALSE)
>> wrus.knb5.mat <- nb2mat(ruskn5.nb, glist=NULL, style="W",
>> zero.policy=NULL)
>> wrus.knb5.lw <- mat2listw(wrus.knb5.mat, row.names =rus$index,
>> style="M")
>>
>> Using that "wrus.knb5.lw" object created with mat2listw, and indeed
>> explicitly indicating that object in both listw and listw2, I get a
>> result
>> to the spml function.
>>
>> Now I just have to figure out whether the result is meaningful.
>
> The actual underlying problem may be a missing assignment in R/spfeml.R of
> can.sim2 to env. The local environment env is used in maximum likelihood
> methods in splm and spdep to find the log-det (Jacobian), and should be
> set in the calling function, see ?do_ldet in spdep. The first error
> message was probably the important one. I have added the splm maintainer
> to the CCs.
>
> Because the log likelihood function is called often, it is much more
> efficient to put all the objects needed by the function in an environment,
> and only pass a pointer to the environment to the function, than to pass
> the objects separately at each call; this way of handling optimisation
> function efficiency was recommended among others by Doug Bates.
>
> Roger
>
>>
>> Thank you very much Rafael,
>>
>> best regards,
>>
>> Patrick
>>
>>
>>> Yes,
>>> in that case the error I get is:
>>>
>>> Error in match(x, table, nomatch = 0L) : object 'wrus.knb5' not found
>>>
>>> Thus, no matter I specify this for listw or listw2, in both cases R
>>> cannot
>>> find the object.
>>>
>>> Which I suppose answer my first question: it is not the "listw"
>>> function
>>> which is not found, but the object I use as argument of that function,
>>> right?
>>>
>>> But now I'm still unclear about what to do.
>>>
>>> Thanks anyway
>>>
>>>> Hi Patrick
>>>>
>>>> Have you tried what I suggested?
>>>>
>>>> spml(formula = fm, data = rusp9508.subsvars, index ="index", listw =
>>>> wrus.knb5,
>>>> listw2 = wrus.knb5, model = "within", lag = TRUE, spatial.error="b")
>>>>
>>>> Rafael
>>>>
>>>> On 09.10.2012, at 11:25, Patrick Meyfroidt wrote:
>>>>
>>>>> Hi Rafael,
>>>>>
>>>>> thank you very much for the answer.
>>>>>
>>>>> I read the page you referred to, and it was indeed very interesting,
>>>>> but
>>>>> I
>>>>> haven't yet figured out how to use that in my problem.
>>>>>
>>>>> When I do:
>>>>>  ls( envir = .GlobalEnv )
>>>>> I see that the object I use for listw, which is "wrus.knb5", is
>>>>> indeed
>>>>> located in .GlobalEnv
>>>>>
>>>>> I tried - not sure it was necessary or useful - to force spml to be
>>>>> enclosed in .GlobalEnv by doing:
>>>>>  environment( spml ) = .GlobalEnv
>>>>> But still the object listw is not found.
>>>>>
>>>>> I also tried to specify where to look for wrus.knb5, by using:
>>>>>  spml( ... listw = .GlobalEnv:::wrus.knb5 ...)
>>>>> but, as can be expected, it does not work because .GlobalEnv is not a
>>>>> package.
>>>>>
>>>>> So, two questions:
>>>>> - What is R looking in the wrong place? Is it the function listw, or
>>>>> the
>>>>> object wrus.knb5 that I use as input for listw ?
>>>>> - Based on that, how can I help R to look at the right place?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Patrick
>>>>>
>>>>>
>>>>>> Hi Patrick
>>>>>>
>>>>>> I can not judge whether it makes any sense, but if you want listw
>>>>>> and
>>>>>> listw2 to be the same, try:
>>>>>>
>>>>>> spml(formula = fm, data = rusp9508.subsvars, index ="index", listw =
>>>>>> wrus.knb5, listw2 = wrus.knb5, model = "within", lag = TRUE,
>>>>>> spatial.error
>>>>>> =
>>>>>> "b")
>>>>>>
>>>>>> Otherwise, I guess, R is looking for listw in the wrong place. Look
>>>>>> at
>>>>>> http://obeautifulcode.com/R/How-R-Searches-And-Finds-Stuff/
>>>>>> for explanations.
>>>>>>
>>>>>> HTH,
>>>>>> Rafael
>>>>>>
>>>>>> On 08.10.2012, at 13:47, Patrick Meyfroidt wrote:
>>>>>>
>>>>>>> OK, I may have some update, sorry for the disturbance.
>>>>>>>
>>>>>>> By explicitly indicating that listw2 is the same as listw, like
>>>>>>> that:
>>>>>>>
>>>>>>> spml(formula = fm, data = rusp9508.subsvars, index ="index", listw
>>>>>>> =
>>>>>>> wrus.knb5, listw2 = listw, model = "within", lag = TRUE,
>>>>>>> spatial.error
>>>>>>> =
>>>>>>> "b")
>>>>>>>
>>>>>>> I now get the following error message:
>>>>>>>
>>>>>>> Error in match(x, table, nomatch = 0L) : object 'listw' not found
>>>>>>>
>>>>>>> So apparently the listw object cannot be read.
>>>>>>>
>>>>>>> Is it because the weights were calculated once for each country,
>>>>>>> but
>>>>>>> the
>>>>>>> dataset is a panel one?
>>>>>>>
>>>>>>> Does someone have a clue?
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Patrick Meyfroidt
>>>>>>>
>>>>>>>
>>>>>>>> Dear list,
>>>>>>>>
>>>>>>>> I have spatial panel data (regions over years), that I subsetted
>>>>>>>> to
>>>>>>>> make
>>>>>>>> sure that the panel is balanced.
>>>>>>>>
>>>>>>>> Using spdep, I calculated weights using nearest neighbors on these
>>>>>>>> regions, with the following code:
>>>>>>>>
>>>>>>>> --
>>>>>>>> RUSCRS <- CRS("+proj=lcc +lat_1=15 +lat_2=65 +lat_0=30 +lon_0=95
>>>>>>>> +x_0=0
>>>>>>>> +y_0=0 +units=m +datum=WGS84")
>>>>>>>> rus <- readShapeSpatial([filename], IDvar = "index", proj4string =
>>>>>>>> RUSCRS)
>>>>>>>> coords <- coordinates(rus)
>>>>>>>> ruskn5 <- knearneigh(coords, k=5, longlat = NULL)
>>>>>>>> ruskn5.nb <- knn2nb(ruskn5, row.names=rus$index, sym = FALSE)
>>>>>>>> wrus.knb5 <- nb2listw(ruskn5.nb, glist=NULL, style="W",
>>>>>>>> zero.policy=NULL)
>>>>>>>> --
>>>>>>>>
>>>>>>>> Everything looks fine, i.e. I can print out the results at each
>>>>>>>> step,
>>>>>>>> and
>>>>>>>> each unit apparently has indeed 5 neighbors with 0.2 weight for
>>>>>>>> each.
>>>>>>>>
>>>>>>>> Then I use splm package to perform a spatial panel regression,
>>>>>>>> using
>>>>>>>> the
>>>>>>>> code:
>>>>>>>>
>>>>>>>> --
>>>>>>>> fm <- rnabd ~ rlex + pbpl
>>>>>>>> spml(formula = fm, data = rusp9508.subsvars, index ="index", listw
>>>>>>>> =
>>>>>>>> wrus.knb5, model = "within", lag = TRUE, spatial.error = "b")
>>>>>>>> --
>>>>>>>>
>>>>>>>> But I end up with the following error message:
>>>>>>>>
>>>>>>>> "Error in get("can.sim2", envir = env) : object 'can.sim2' not
>>>>>>>> found"
>>>>>>>>
>>>>>>>>
>>>>>>>> Can someone explain what is this "can.sim2" object and possible
>>>>>>>> reasons
>>>>>>>> for the error message?
>>>>>>>>
>>>>>>>> Thank you very much for any input,
>>>>>>>>
>>>>>>>> Patrick Meyfroidt
>>>>>>>> Université catholique de Louvain - Belgium
>>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> R-sig-Geo mailing list
>>>>>>> R-sig-Geo at r-project.org
>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Rafael Wüest
>>>>>> Swiss Federal Research Institute WSL
>>>>>> Zürcherstrasse 111
>>>>>> 8903 Birmensdorf
>>>>>> Switzerland
>>>>>>
>>>>>> +41 44 7392126
>>>>>> rafael.wueest at wsl.ch
>>>>>> http://www.wsl.ch/info/mitarbeitende/wueest/index_EN
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Rafael Wüest
>>>> Swiss Federal Research Institute WSL
>>>> Zürcherstrasse 111
>>>> 8903 Birmensdorf
>>>> Switzerland
>>>>
>>>> +41 44 7392126
>>>> rafael.wueest at wsl.ch
>>>> http://www.wsl.ch/info/mitarbeitende/wueest/index_EN
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>> _______________________________________________
>> 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, 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