[R-sig-Geo] How to get the Coefficient of Determination in the results of GWR
Roger Bivand
Roger.Bivand at nhh.no
Fri May 14 10:40:44 CEST 2010
On Thu, 13 May 2010, huangykiz wrote:
> Hi,
>
> My coordinates geographical are decimal degrees. I am soryy I donot know
> how to and what do copy and paste from SAM to gwr()? I cannot see the
> code of SAM.
If they are, then you must use longlat=TRUE, otherwise the distances
computed will be in inappropriate and varying arbitrary units. Please do
read the help pages for the functions you are trying to use. To compare
different implementations, here gwr.sel() and gwr() in R with SAM, you
must make sure that the implementations are receiving the same input.
>
> Thanks a lot.
>
> Cheers.
>
>
>
> 在2010-05-13 17:43:06,"Roger Bivand" <Roger.Bivand at nhh.no> 写道:
>> On Thu, 13 May 2010, huangykiz wrote:
>>
>>> Hi,
>>
>>> I am sorry I say that I cannot get the same R^2 between in R/spgwr and
>>> SAM in my data.
>>
>> Establish that the adaptive proportion is exactly the same.
>>
>> You haven't done that - copy and paste from SAM to gwr(), not using
>> gwr.sel(). Do it first for fixed Gaussian, then if you get a sensible
>> figure from SAM for adaptive, do the same there. I see very different
>> bandwidths chosen by SAM and by gwr.sel() and GWR3 - gwr.sel() and GWR3
>> usually agree fairly well for CV fixed bandwidths, but gwr.sel() typically
>> continues its search a little longer than GWR3.
>>
>> I don't know how SAM chooses its bandwidth or adaptive proportion, it is
>> closed source, so only its authors know.
>>
>> Is SAM using Great Circle distances, if so, you should set longlat=TRUE in
>> gwr.sel() and gwr()? Are your coordinates geographical (decimal degrees)
>> or projected (metres)?
>>
>> Roger
>>
>>> In R/spgwr
>>> R^2: 0.972989;
>>> AICc (GWR p. 61, eq 2.33; p. 96, eq. 4.21): 4668.92
>>> Effective number of parameters (model: traceS): 435.7586;
>>> Effective number of parameters (residual: 2traceS - traceS'S): 582.3581;
>>> Sigma (residual: 2traceS - traceS'S): 2.437066;
>>> Sigma (model: traceS): 1.927127;
>>> Sigma (ML): 1.325501;
>>>
>>> In SAM,
>>> Coefficient of Determination : 0.696
>>> Adjusted r-square (r?Adj): 0.693
>>> Sigma: 20.058
>>> Effective Number of Parameters: 10.002
>>> Akaike Information Criterion (AICc): 4838.299
>>> Correlation Coefficient (r): 0.834
>>> F: 207.852
>>>
>>> Here are my code:
>>> PET.adapt.gauss <- gwr.sel(SPECIES_RI ~ PET, data=Environmental_variables, coords=cbind(Environmental_variables$LONGX,
>>> Environmental_variables$LATY),adapt=TRUE)
>>>
>>> PET.gauss<- gwr(SPECIES_RI ~ PET, data=Environmental_variables, coords=cbind(Environmental_variables$LONGX,
>>> Environmental_variables$LATY), gweight=gwr.Gauss,adapt=PET.adapt.gauss,hatmatrix=TRUE)
>>>
>>> 1 - (PET.gauss$results$rss/crossprod(scale(Environmental_variables$SPECIES_RI, scale=FALSE)))
>>>
>>> In SAM, I selecte "spatial Weighting Function"=gaussian, adaptive
>>> Spatial Kernel, and compute Geographical Distances based on longitudinal
>>> coordinate(X) and latitudinal coordinate(Y). I donot select method for
>>> AIC optimisation.
>>>
>>> So I donot know where is wrong.
>>>
>>> Thank you very much for your great helps.
>>>
>>>
>>>
>>>
>>>
>>>
>>> 在2010-05-13 00:07:23,"Roger Bivand" <Roger.Bivand at nhh.no> 写道:
>>>> On Wed, 12 May 2010, Roger Bivand wrote:
>>>>
>>>>> On Wed, 12 May 2010, huangykiz wrote:
>>>>>
>>>>>> Hi, Is "adapt=TRUE"(spgwr) not the same as "adaptive Spatial
>>>>>> Kernel"(SAM)?The result of "adaptive Spatial Kernel" may be better than
>>>>>> fixed bandwidth. If I want to ues "adaptive Spatial Kernel" in spgwr, how
>>>>>> to write the code?
>>>>>
>>>>> READ THE HELP PAGES!
>>>>>
>>>>> adaptive_proportion <- gwr.sel(...)
>>>>>
>>>>> result <- gwr(..., adapt=adaptive_proportion; ...)
>>>>>
>>>>> exactly as on the example om the help page:
>>>>>
>>>>> data(georgia)
>>>>> g.adapt.gauss <- gwr.sel(PctBach ~ TotPop90 + PctRural + PctEld + PctFB +
>>>>> PctPov + PctBlack, data=gSRDF, adapt=TRUE)
>>>>> res.adpt <- gwr(PctBach ~ TotPop90 + PctRural + PctEld + PctFB + PctPov +
>>>>> PctBlack, data=gSRDF, adapt=g.adapt.gauss)
>>>>> res.adpt
>>>>>
>>>>> Clear?
>>>>
>>>> I have now compared the same data in R/spgwr and SAM for effective number
>>>> of parameters, sigma, and your questionable R^2, and they agree adequately
>>>> when the kernel and the bandwidth are the same. Having the algorithm
>>>> choose the bandwidth does obscure what is going on. You should use SAM if
>>>> you prefer GUI and not needing to know how things work, and remember that
>>>> GWR is a very doubtful approach for anything beyond exploring
>>>> non-stationarity, its original motivation.
>>>>
>>>>>
>>>>>>
>>>>>> Thanks a lot.
>>>>>>
>>>>>> Cheers.
>>>>>>
>>>>>>
>>>>>>> Hi,
>>>>>>> I think that I use the same bandwidth and kernel. In SAM, I use "spatial
>>>>>>> Weighting Function"=gaussian, adaptive Spatial Kernel, and compute
>>>>>>> Geographical Distances based on longitudinal coordinate(X) and latitudinal
>>>>>>> coordinate(Y). In spgwr, gweight is gwr.Gauss and adapt is TRUE.
>>>>>>>
>>>>>>> For example, this is my code:
>>>>>>
>>>>>>> PET.bw <- gwr.sel(SPECIES_RI ~ PET, data=variables,
>>>>>>> coords=cbind(variables$LONGX, variables$LATY),adapt=TRUE)
>>>>>>
>>>>>>> PET.gauss <- gwr(SPECIES_RI ~ PET, data=variables,
>>>>>>> coords=cbind(variables$LONGX, variables$LATY), bandwidth=PET.bw,
>>>>>>> gweight=gwr.Gauss,adapt=TRUE,hatmatrix=TRUE)
>>>>>>
>>>>>> So where do you pass PET.bw to the gwr() function? adapt=TRUE will treat
>>>>>> the adaptive proportion as 1, so include all data points. If you want to
>>>>>> compare, use a fixed bandwidth in both, with no CV selection. Then you
>>>>>> compare like with like.
>>>>>>
>>>>>> Note that your messages are *not* reaching the list, they must be sent to:
>>>>>>
>>>>>> r-sig-geo at stat.math.ethz.ch, not
>>>>>>
>>>>>> r-sig-geo-request at stat.math.ethz.ch
>>>>>>
>>>>>> You are not thinking carefully and are rushing into things and drawing
>>>>>> wrong conclusions.
>>>>>>
>>>>>>>
>>>>>>> Thanks a lot.
>>>>>>>
>>>>>>> Cheers.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> 在2010-05-12 20:28:47,"Roger Bivand" <Roger.Bivand at nhh.no> 写道:
>>>>>>>> On Wed, 12 May 2010, huangykiz wrote:
>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>> One of SAM author ("José Alexandre Felizola Diniz
>>>>>>>>> Filho"<diniz at icb.ufg.br>) say that they also base on GWR3 (the
>>>>>>>>> Fotherigham book) and the data used within each kernel may be some
>>>>>>>>> slight differences
>>>>>>>>
>>>>>>>> Naturally, if you are not using exactly the same kernel and bandwidth,
>>>>>>>> you should not be surprised by differences in values. Please make sure
>>>>>>>> that the bandwidth and kernel are the same and try again.
>>>>>>>>
>>>>>>>> Roger
>>>>>>>>
>>>>>>>>> Cheers
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> 在2010-05-12 20:28:47,"Roger Bivand" <Roger.Bivand at nhh.no> 写道:
>>>>>>> On Wed, 12 May 2010, huangykiz wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>> One of SAM author ("José Alexandre Felizola Diniz
>>>>>>>> Filho"<diniz at icb.ufg.br>) say that they also base on GWR3 (the
>>>>>>>> Fotherigham book) and the data used within each kernel may be some
>>>>>>>> slight differences
>>>>>>>
>>>>>>> Naturally, if you are not using exactly the same kernel and bandwidth, you
>>>>>>> should not be surprised by differences in values. Please make sure that
>>>>>>> the bandwidth and kernel are the same and try again.
>>>>>>>
>>>>>>> Roger
>>>>>>>
>>>>>>>> Cheers.
>>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> 在2010-05-12 15:27:58,"Roger Bivand" <Roger.Bivand at nhh.no> 写道:
>>>>>>> On Wed, 12 May 2010, huangykiz wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I am sorry I donot know how to install module spgwr from sourceforge (I
>>>>>>>> can find it on the web
>>>>>>>> http://r-spatial.cvs.sourceforge.net/viewvc/r-spatial/spgwr/R/gwr.R?view=log).
>>>>>>>> So I use the code sketch to calculate quasi-global R2. The results are
>>>>>>>> different between SAM and spgwr(Attached are the results ). The
>>>>>>>> quasi-global R2 in R is 0.4515894, but in SAM is 0.696.
>>>>>>>> This is my code:
>>>>>>>>
>>>>>>>> library(spgwr)
>>>>>>>> Environmental_variables<-read.csv("Environmental_variables100.csv",header=TRUE)
>>>>>>>> attach(Environmental_variables)
>>>>>>>> region_PET.bw <- gwr.sel(SPECIES_RI ~ PET, data=Environmental_variables,
>>>>>>>> coords=cbind(Environmental_variables$LONGX,
>>>>>>>> Environmental_variables$LATY),adapt=TRUE)
>>>>>>>> region_PET.gauss <- gwr(SPECIES_RI ~ PET, data=Environmental_variables,
>>>>>>>> coords=cbind(Environmental_variables$LONGX,
>>>>>>>> Environmental_variables$LATY), bandwidth=region_PET.bw,
>>>>>>>> gweight=gwr.Gauss,adapt=TRUE,hatmatrix=TRUE)
>>>>>>>> names(region_PET.gauss$SDF)
>>>>>>>> region_PET.gauss$SDF$localR2
>>>>>>>> 1 -
>>>>>>>> (region_PET.gauss$results$rss/crossprod(scale(Environmental_variables$SPECIES_RI,
>>>>>>>> scale=FALSE)))
>>>>>>>>
>>>>>>>> Thank you very much.
>>>>>>>
>>>>>>> SAM is closed source - ask them how they compute it. For spgwr, the code
>>>>>>> is provided, so you can read it for yourself. For the record, the current
>>>>>>> gwr() code in spgwr gives the same value as GWR3, which is also closed
>>>>>>> source, and where the Effective number of parameters (model: traceS),
>>>>>>> Sigma, and Residual sum of squares also agree. I suppose SAM has a
>>>>>>> different understanding of GWR internals than the authors of the GWR book.
>>>>>>>
>>>>>>> Once again:
>>>>>>>
>>>>>>> Please *do* write to the R-sig-geo list rather than to me directly -
>>>>>>> others can answer your question as well, perhaps better, and in a more
>>>>>>> timely way than I can. In addition, threads in the list can be searched in
>>>>>>> the archives, so others can avoid the same problem later.
>>>>>>>
>>>>>>> Please summarise to the list if this resolves the problem.
>>>>>>>
>>>>>>> Roger
>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> 在2010-05-12 01:16:18,"Roger Bivand" <Roger.Bivand at nhh.no> 写道:
>>>>>>>>> On Wed, 12 May 2010, huangykiz wrote:
>>>>>>>>>
>>>>>>>>>> Hi, I just need one for global, not *each* fit point. In this case, how
>>>>>>>>>> can I select or do? Why in other software such as SAM(Spatial Analysis
>>>>>>>>>> in Macroecology) just gives one R2?
>>>>>>>>>
>>>>>>>>> If you believe theirs, good luck! The authors of the GWR book have local
>>>>>>>>> R^2 values in GWR3 and formulae that are wrong by their own admission in
>>>>>>>>> private emails. The localR2 now agrees with the as-yet unreleased GWR4
>>>>>>>>> from the GWR authors. How SAM can be "better", I don't know. What you
>>>>>>>>> are suggesting is that the model fitted with fit points at data points
>>>>>>>>> (but not at other fit points) might have a "quasi-global" R^2, based on
>>>>>>>>> the RSS of the pooled fit. For the columbus case, that might be:
>>>>>>>>>
>>>>>>>>> 1 - (col.gauss$results$rss/crossprod(scale(columbus$crime,
>>>>>>>>> scale=FALSE)))
>>>>>>>>>
>>>>>>>>> but I don't know whether this is in any way correct. I've added it as:
>>>>>>>>>
>>>>>>>>> Quasi-global R2:
>>>>>>>>>
>>>>>>>>> to the print output of a GWR model fitted with a hatmatrix, and have
>>>>>>>>> committed it to sourceforge, project r-spatial, module spgwr. Arguably,
>>>>>>>>> it ought to be adjusted by the ratio of degrees of freedom, but I don't
>>>>>>>>> trust the DF either. Could you please check out spgwr from sourceforge
>>>>>>>>> ,install it from source, and confirm that the "quasi-global R2" does the
>>>>>>>>> same as SAM, or use the code sketch above to do the same, and report
>>>>>>>>> back?
>>>>>>>>>
>>>>>>>>> Roger
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Thanks a lot.
>>>>>>>>>>
>>>>>>>>>> Cheers,
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> 在2010-05-11 23:59:44,"Roger Bivand" <Roger.Bivand at nhh.no> 写道:
>>>>>>>>>>> On Tue, 11 May 2010, huangykiz wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> There are 49 localR2 in the results. Which one do I need? The code
>>>>>>>>>>>> "look for localR2:" cannot run.
>>>>>>>>>>>
>>>>>>>>>>> Well, how many do you want? There is one for each fit point, they are
>>>>>>>>>>> *local* R2. Please do try to grasp what GWR does - it fits one moddel
>>>>>>>>>>> for *each* fit point.
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Thans a lot
>>>>>>>>>>>>
>>>>>>>>>>>> Cheers.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> 在2010-05-11 22:33:59,"Roger Bivand" <Roger.Bivand at nhh.no> 写道:
>>>>>>>>>>>>> On Tue, 11 May 2010, huangykiz wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi, OK. But I need it for compariation. In what some contexts to
>>>>>>>>>>>>>> get it? May you tell me how to get it?
>>>>>>>>>>>>>
>>>>>>>>>>>>> library(spgwr)
>>>>>>>>>>>>> data(columbus)
>>>>>>>>>>>>> col.bw <- gwr.sel(crime ~ income + housing, data=columbus,
>>>>>>>>>>>>> coords=cbind(columbus$x, columbus$y))
>>>>>>>>>>>>> col.gauss <- gwr(crime ~ income + housing, data=columbus,
>>>>>>>>>>>>> coords=cbind(columbus$x, columbus$y), bandwidth=col.bw,
>>>>>>>>>>>>> hatmatrix=TRUE)
>>>>>>>>>>>>> names(col.gauss$SDF)
>>>>>>>>>>>>>
>>>>>>>>>>>>> look for localR2:
>>>>>>>>>>>>>
>>>>>>>>>>>>> col.gauss$SDF$localR2
>>>>>>>>>>>>>
>>>>>>>>>>>>> But do not rely on it or use it for anything at all! Like all GWR,
>>>>>>>>>>>>> it is most unreliable!
>>>>>>>>>>>>>
>>>>>>>>>>>>> Roger Bivand
>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thank you very much for your great helps
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Best regards.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> 在2010-05-11 18:28:44,"Roger Bivand" <Roger.Bivand at nhh.no> 写道:
>>>>>>>>>>>>>>> On Tue, 11 May 2010, huangykiz wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Dear professor Bivand,
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> I am a strudent. I recently use GWR(Geographically weighted
>>>>>>>>>>>>>>>> regression) model. May I ask you a question? There is not
>>>>>>>>>>>>>>>> Coefficient of Determination in the results of GWR. How can I get
>>>>>>>>>>>>>>>> it? What is the programs to get it?
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Please address questions like this to the R-sig-geo list rather
>>>>>>>>>>>>>>> than to me directly in future.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> The local R2 values are available in some contexts when running
>>>>>>>>>>>>>>> gwr(), but are not well defined (neither in the GWR book nor in
>>>>>>>>>>>>>>> implementations). I advise against their use - they are most
>>>>>>>>>>>>>>> probably meaningless.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hope this helps,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Roger Bivand
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Thank you very much for your any helps.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Best regards.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Yong Huang
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> --
>>>>>>>>>>>>>>> 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
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> --
>>>>>>>>>>>>> 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
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> 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
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> 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
>>>>>>>
>>>>>>> --
>>>>>>> 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
>>>>>
>>>>>
>>>>
>>>> --
>>>> 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
>>
>> --
>> 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
--
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