[R-sig-Geo] How to calculate R2 coefficient of determinationforvariogram ?

kili at grf.bg.ac.rs kili at grf.bg.ac.rs
Mon Mar 7 10:15:53 CET 2011


>>>1- What do you mean by  : "the same weighting scheme should have been
used" and how would you code that?

See fit.variogram function and argumnet fit.method .

If you do not check the argumrnt fit.method (the default value
fit.method=7)the weight function will be  $N_h/h^2$ with $N_h$ the number
of point pairs
and $h$ the distance.

So for this case you can use the formulas for any variogram.

R2variogram<-function(s.v,vr.fit){
 # s.v  - sample variogram

    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

    return(R2)
      }

Best regards,
Milan Kilibarda - Kili





-------Original Message-------

From: Sébastien Durand
Date: 7.3.2011 2:28:44
To: r-sig-geo at stat.math.ethz.ch
Subject: [R-sig-Geo] How to calculate R2 coefficient of
determinationforvariogram ?

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), me



More information about the R-sig-Geo mailing list