[R-sig-Geo] How to calculate R2 coefficient of determination for variogram ?
Sébastien Durand
v8extra at gmail.com
Mon Mar 7 02:25:25 CET 2011
Hello,
I found the following trend on the web, and I am facing the same problem.
I am trying to compute the r2 from my fit, but I end up with a negative value ...
So I have two quick questions for you:
1- What do you mean by : "the same weighting scheme should have been used" and how would you code that?
2-I guess the code that was provide by Kili, should work for any variogram fit...
Thanks a lot for you time.
N.B.: I was unsure how to pursue this discussion on the web, so my apologies for contacting you directly!
Sébastien
> It looks quite OK; I suspect however that instead of using
> mean(s.v$gamma) for SSTot, for this mean the same weighting scheme
> should have been used.
> --
> Edzer
>
> On 09/02/2010 02:59 PM,
> kili at grf.rs
> wrote:
>> Hi list,
>> I'm not sure in my calculation of R2 coefficient of determination for
>> variogram. Could someone check it, or give the better way.
>> Here is an example:
>> library(sp)
>> library(gstat)
>> data(meuse)
>> coordinates(meuse) <- ~x+y
>> s.v<- variogram(log1p(zinc)~sqrt(dist), meuse)
>> vr.fit <- fit.variogram(variogram(log1p(zinc)~sqrt(dist), meuse), vgm(0,
>> "Exp", 300, 1))
>> ## SSErr is it summ of weighted squares of residuals ?
>> (SSErr<-attr(vr.fit,"SSErr"))
>>
>> ## SStot total sum of weighted squares
>> weig<-s.v$np/s.v$dist^2 #fit.method fitting method, used by gstat. The
>> default method uses weights $N_h/h^2$ with $N_h$ the number of point pairs
>> and $h$ the distance.
>> (SStot<- sum(weig*(s.v$gamma-mean(s.v$gamma))^2) )
>>
>> (R2<-1-SSErr/SStot ) # R2 coefficient of determination
>> Best regards,
>> Kili
>>
>
More information about the R-sig-Geo
mailing list