[R-sig-Geo] How to calculate R2 coefficient of determination for variogram ?

kili at grf.rs kili at grf.rs
Thu Sep 2 14:59:08 CEST 2010


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