TransWikia.com

Error in gstat.formula.predict(d$formula, newdata, na.action = na.action, : NROW(locs) != NROW(X): this should not occur

Geographic Information Systems Asked by Hazzy-g on April 1, 2021

I’m trying to perform regression kriging using the code

creating variogram

m <- vgm(var(soil$Ba), "Sph", sqrt(areaSpatialGrid(slope))/4, nugget=0)
v <- fit.variogram(variogram(Ba~RASTERVALU, data= soil),model = m )
plot(variogram(Ba~RASTERVALU, data= soil),v, main="fitted by lt")

running kriging

slopeuk <- krige(soil$Ba~soil$RASTERVALU,locations= soil, newdata= slope, model=m)

However after the final line of code I get the error

Error in gstat.formula.predict(d$formula, newdata, na.action = na.action,  : 
  NROW(locs) != NROW(X): this should not occur
In addition: Warning messages:
1: 'newdata' had 2849126 rows but variables found have 195 rows 
2: 'newdata' had 2849126 rows but variables found have 195 rows 

Here are some images of the data
soilinfo.1

soilinfo.2
slopeinfo

One Answer

If you have not found your answer yet, I think you're getting the errors because you don't have the predictor variable(s) (i.e. RASTERVALU) in your newdata (i.e. slope). As far as I can understand from your screenshot, it's "band1"- a different variable than what is used in the variogram.

Also, you should use model = v:

slopeuk <- krige(soil$Ba~soil$RASTERVALU,locations= soil, newdata= slope, model=v)

instead of m:

slopeuk <- krige(soil$Ba~soil$RASTERVALU,locations= soil, newdata= slope, model=m)

Hope this helps.

Answered by MAH on April 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP