0

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

  • Did you tried with krige(Ba~RASTERVALU,locations= soil, newdata= slope, model=m)? – aldo_tapia May 31 '18 at 13:09
  • Yes and I get the error: Error in eval(predvars, data, env) : object 'RASTERVALU' not found – Hazzy-g May 31 '18 at 13:33
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.