[R-sig-Geo] all localR2 has NA values in gwr
Roger Bivand
Roger.Bivand at nhh.no
Fri Oct 1 15:47:22 CEST 2010
On Fri, 1 Oct 2010, Roger Bivand wrote:
> On Thu, 30 Sep 2010, Danlin Yu wrote:
>
>>
>> Jorge:
>>
>> From what I see on your code, I would suspect that you kind of confuse the
>> bandwidth with numbers of nearest neighbor. In your code, you use 20, and I
>> assume that meant the 20 nearest neighbors that you want for GWR
>> calibration. Yet you didn't specify the adapt parameter in the code, which
>> make the code think 20 is a distance value. I am not sure how the distance
>> of 20 with longitude and latitude values would be, but I suspect this might
>> be the cause.
>
> See ?spDistsN1, the distances are in kilometers.
>
>> In addition, in the coordinates specification, longitude shall be the x,
>> and latitude the y.
>>
>
> Exactly!
>
>> Try:
>>
>> test=gwr(y~x1+x2,data=yourdata,cbind(longitude,
>> latitude),adapt=0.05,gwr.bisquare,longlat=T)
>>
>> to see what happens (I use 0.05 just for testing purpose, which means 5% of
>> the total sample as the nearest neighbor for local estimation. Since you
>> have more than 10,000 samples, the value will result in a local sample
>> (local nearest neighbors) of 500. If you wan to try 20, then you can
>> probably use 0.002 for the adapt parameter).
>>
>
> I agree that adapt= may here be a better choice than a fixed bandwidth. I do
> not, however, think that local R2 will be available for this number of data
> points, as the hat matrix would be too big for memory. Please read up on the
> difference between fit points and data points, and consider fitting a model
> with hat matrix on a subset of the data, then using the fittedGWRobject=
> argument to provide the elements needed to get to local R2 (which is not the
> R2 of each local fit, it seems). Have you tried fitting in GWR3, SAM, or
> ArcGIS?
My analysis was incorrect, and the NA localR2 are coming from the very low
sums of weights for each observation:
library(spgwr)
res.adpt <- gwr(PctBach ~ TotPop90 + PctRural + PctEld + PctFB + PctPov +
PctBlack, data=gSRDF, adapt=0.01)
summary(res.adpt$SDF)
res.adpt <- gwr(PctBach ~ TotPop90 + PctRural + PctEld + PctFB + PctPov +
PctBlack, data=gSRDF, adapt=0.001)
summary(res.adpt$SDF)
With sums of local weights of 1, so only including the i'th observation in
its own local regression, the localR2 suffers numerical meltdown in
several elements. The hat matrix is not required to compute the localR2 if
the data points are the fit points. In your case, and with a 20km fixed
bandwidth, you most likely only have the i'th observations in their own
local regressions.
Hope this helps more,
Roger
>
> Hope this helps,
>
> Roger
>
>> Hope this helps.
>>
>> Cheers,
>> Dr. Danlin Yu
>>
>>
>>
>> On 2010-9-30 12:53, Jorge Fernando Saraiva de Menezes wrote:
>>> Dear list,
>>>
>>> When I run a gwr using a model with two independent variables my local R2
>>> only has NA values. I've read in some topic that this is problably because
>>> the function cannot estimate localR2 correctly.
>>> I tryed to get the same result with the columbus data, but was not able
>>> to.
>>> Does anyone know what usually cause this? maybe a small or large bandwdth?
>>> And a side question, when longlat=T,and your coordinates are in WGS84 the
>>> values of bandwidth must be given in degrees?
>>>
>>>
>>> I'm using R2.10.1 and package spgwr version 0.6-2. i give a summary of my
>>> variables below. also my data is information collected in 10433 islands of
>>> the American continent, which mean that I have distances between my points
>>> varying from few meters to thousands of kilometers. I use a bandwidth of
>>> 20,
>>> and used the bisquare method.
>>>
>>> summary of my data
>>> y x1 x2
>>> Min. 0.00 1.310e-02 4.254e-02
>>> 1st Qu. 32.00 8.319e-01 1.628e+00
>>> Median 47.00 1.696e+00 2.005e+01
>>> Mean 84.25 2.043e+02 1.329e+02
>>> 3rd Qu. 143.00 5.822e+00 1.758e+02
>>> Max. 425.00 5.152e+05 3.114e+03
>>>
>>> code
>>> test=gwr(y~x1+x2,,cbind(latitude,longitude),20,gwr.bisquare,longlat=T)
>>>
>>> Thanks in advance,
>>> Jorge Menezes
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at stat.math.ethz.ch
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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