mean - When to define new columns in krige in R? -
mean - When to define new columns in krige in R? -
i wondering: ever necessary redefine own columns when kriging? error below seems indicate this:
warning: singular model in variogram fit > sk1 <- krige(formula=zs~1, locations=~xs+ys, data=sampled, newdata=pred.grid, model=fit.sph, beta=0) error in `[.data.frame`(object, , -coord.numbers, drop = false) : undefined columns selected
is there problem i'm not seeing? or, need define own columns? thanks.
the next programme reproducable , runnable here down:
library(gstat) x <- seq(0,2000,by=20) y <- seq(0,2000,by=20) x = sample(x,10,replace=t) y = sample(y,10,replace=t) z = sample(0.532:3.7,10,replace=t) samples = data.frame(x,y,z) # detrend samples: print(mean(samples$z)) #create object of class gstat h <- gstat(formula=z~1, locations=~x+y, data=samples) samples.vgm <- variogram(h) # create method of class "gstatvariogram" plot(samples.vgm,main='variogram of samples not detrended') # plot method class "gstatvariogram" # detrend z = samples$z x = samples$x y = samples$y trend <- lm(z~x+y) c = trend$coefficients[[1]] = trend$coefficients[[2]] b = trend$coefficients[[3]] #z_prime = z - (a*x + b*y +c) # subtract predicted line xs <- c() ys <- c() zs <- c() print('started loop') (i in 1:nrow(samples)){ = samples[i,] x=i$x y=i$y z=i$z z_prime = z - (a*x+b*y+c) xs <- c(xs,x) ys <- c(ys,y) zs <- c(zs,z_prime) } sampled <- data.frame(xs=xs,ys=ys,zs=zs) print(sampled) print('the length of sampled is') print(length(sampled[[1]])) # "result" new dataset z's detrended # print(levelplot(zs~xs+ys,sampled)) # define domain or kriging estimation x <- seq(0,2000,by=20) y <- seq(0,2000,by=20) # create info frame prediction locations pred.grid <- data.frame(x=rep(x,times=length(y)),y=rep(y,each=length(x))) #create object of class gstat g <- gstat(formula=zs~1, locations=~xs+ys, data=sampled) sampled.vgm <- variogram(g) # create method of class "gstatvariogram" plot(sampled.vgm,main='variogram of samples detrended') # plot method class "gstatvariogram" vg.sph <- vgm(psill=1.0,model='sph', range = 500) fit.sph <- fit.variogram(sampled.vgm, model = vg.sph) sk1 <- krige(formula=zs~1, locations=~xs+ys, data=sampled, newdata=pred.grid, model=fit.sph, beta=0)
add library(gstat)
top of code, it's reproducible.
to reply question directly, reason receive undefined columns selected
error because newdata
not have right column names. column names need match info column names, xs , ys in case. redefine pred.grid have columns xs
, ys
solve problem. tested, , code runs.
pred.grid <- data.frame(xs=rep(x,times=length(y)),ys=rep(y,each=length(x)))
as other comments: warning: singular model in variogram fit
result of not beingness able fit model based on sample semivariogram data. if take @ plot of info (below), it's clear no empirical function able fit this. in case, because have 1 point per bin (11 points total) there's not plenty info fit semivariogram. reducing number of bins, there still not plenty info back upwards fit empirical semivariogram.
changing number of samples 500,
x = sample(x,500,replace=t) y = sample(y,500,replace=t) z = sample(0.532:3.7,500,replace=t)
it becomes clear info generating uncorrelated such samples closer 1 in x-y space not more similar samples farther away (pure nugget semivariogram). wanted?
r mean kriging
Comments
Post a Comment