[R-sig-Geo] GSTAT: Optimize power value for IDW
Paul Hiemstra
p.hiemstra at geo.uu.nl
Tue Dec 2 21:06:38 CET 2008
Zev Ross schreef:
> Hi All,
>
> ArcGIS has a nice little button that calculates the optimal power
> value to use for inverse distance weighting based on cross-validation
> and RMSPE. Just wondering if anyone had written something similar in R
> -- I'm using GSTAT and I'd like to avoid back and forth with ArcGIS
> (and obviously I'd like to avoid writing it myself as well!).
>
> Zev
>
Hi,
I don't have any code lying around, but a brute force optimization
approach should be quite easy. Also because the range of idw-powers is
relatively small. The speed would ofcourse depend on the size of the
dataset. In code it would look something like (actually works :)):
library(gstat)
data(meuse)
coordinates(meuse) = ~x+y
# make function to do the cv
do_cv = function(idp) {
meuse_idw = gstat(id = "zn", formula = zinc~1, data = meuse, set =
list(idp = idp))
out = gstat.cv(meuse_idw)
return(sqrt(mean(out$residual^2))) # RMSE as optimization criterium
}
idw_pow = seq(0.1,5, by = 0.2) # the idwpower values that will be checked
cv_vals = sapply(idw_pow, do_cv) # calculate the rmse
# List of outcomes
print(data.frame(idp = idw_pow, cv_rmse = cv_vals))
After this you select the idw value with the smallest RMSE.
cheers and hth,
Paul
--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone: +31302535773
Fax: +31302531145
http://intamap.geo.uu.nl/~paul
More information about the R-sig-Geo
mailing list