Hi Jochen!
As far as I know, the idw estimator is just a weighted average of the
observed quantities (log(zinc) in your example), where the weights are
the square distances among the points. Such estimator does not provide
an estimate of the prediction variance, therefore var1.var is always NA.
See also [1, Chapter 8] for more details
Hope that helps
Andrea
[1] Bivand, R. S., Pebesma, E. J., & Gomez-Rubio, V. (2013). /Applied
spatial data analysis with R/ (2nd ed.). Springer.
On 11/7/2025 5:31 PM, Jochen Albrecht wrote:
> I am stumped by a failure of idw() to produce valid values for var1.var,
> the weighted squared distance. Here is my rather basic script:
>
> data(meuse)
> data(meuse.grid)
>
> # 1. Convert Sampled Points (meuse) to SpatialPointsDataFrame (sp
> format for gstat)
> meuse_sp <- meuse
> coordinates(meuse_sp) <- ~x+y
> proj4string(meuse_sp) <- CRS("+init=epsg:28992")
>
> # 2. Convert Prediction Grid (meuse.grid) to SpatialPixelsDataFrame
> # (sp format for gstat and prediction)
> meuse_grid_sp <- meuse.grid
> coordinates(meuse_grid_sp) <- ~x+y
> gridded(meuse_grid_sp) <- TRUE # Define it as a regular grid
> proj4string(meuse_grid_sp) <- CRS("+init=epsg:28992")
>
> # We use the idw() function directly for IDW
> idw_zinc <- idw(log(zinc) ~ 1, # Interpolate log(zinc) with
> a constant mean (~1)
> meuse_sp, # Using the sampled data
> newdata = meuse_grid_sp, # Predicting onto the grid
> idp = 2.0) # Inverse Distance Power = 2
>
> head(idw_zinc@data) var1.pred var1.var
> 1 6.257014 NA
> 2 6.399096 NA
> 3 6.300862 NA
> 4 6.213336 NA
> 5 6.647233 NA
> 6 6.482221 NA
>
> What am I missing here? How can prediction values be produced but the error
> values not?
>
>
> Cheers,
>
> Jochen
>
> Dr. Jochen Albrecht, GISP (he/him/his)
>
> Department of Geography and Environmental Science
> <http://www.geo.hunter.cuny.edu/>
>
> Hunter College CUNY
>
> 695 Park Avenue
>
> New York, NY 10065
>
> Member, Board of Directors, GIS Certification Institute
> <https://www.gisci.org/>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo