0

I am trying to generate variogram and perform ordinary kriging on log10 transformed data in r using gstat package. My issue is on error in fitting. I have posted the code below and bubble plot of transformed rainfall data. If someone help me/show me directions on how to fix this issue? Is it because uneven distribution of sample points? enter image description here

# loading necessary packages
install.packages("gstat")
library(gstat)  
install.packages("sp")
library(sp)

# give file location

setwd("C:/Users/c/Downloads/Documents")
data <- read.csv("ECtrans.csv",TRUE,",")


# fit variogram using gstat
data.vgm <- variogram(logtrans~1,data)
data.fit = fit.variogram(data.vgm, model = vgm(1, "Sph", 1000000, 1))
Error in fit.variogram(data.vgm, model = vgm(1, "Sph", 1e+06, 1)) : 
  fit.method 7 will not work with zero distance semivariances; use another fit.method value
plot(data.vgm, data.fit)
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'y' in selecting a method for function 'plot': object 'data.fit' not found

# to do kriging
data.grid <- read.csv("newgrid.csv",TRUE,",")
coordinates(data.grid) = ~X+Y
> class(data.grid)
[1] "SpatialPoints"
attr(,"package")
[1] "sp"
gridded(data.grid) = TRUE
class(data.grid)
[1] "SpatialPixels"
attr(,"package")
[1] "sp"
data.kriged = krige(logtrans~1, data, data.grid, model = data.fit)
Error in gstat(formula = formula, data = locations, model = model, beta = beta,  : 
  object 'data.fit' not found
spplot(data.kriged["var1.pred"])
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'obj' in selecting a method for function 'spplot': object 'data.kriged' not found
plot(data.grid)
data.dir = variogram(logtrans~1, data, alpha = c(0, 45, 90, 135))
datadir.fit = vgm(.59, "Sph", 1200, .05, anis = c(45, .4))
plot(data.dir, datadir.fit, as.table = TRUE)
data.fit
Error: object 'data.fit' not found

1 Answer 1

1

The first error is here:

data.fit = fit.variogram(data.vgm, model = vgm(1, "Sph", 1000000, 1))
Error in fit.variogram(data.vgm, model = vgm(1, "Sph", 1e+06, 1)) : 
  fit.method 7 will not work with zero distance semivariances; use another fit.method value

(the rest of your question after that is basically noise because data.fit isn't found - please try and only include relevant code up to the first error).

"Zero distance" means you have coincident points. Check the help for fit.variogram and try another value for fit.method.

3
  • First thank you for your relpy. I am new to variogram modeling in r. How can I change the value of the fit.method?
    – Yon Balcha
    Commented Jun 30, 2021 at 7:42
  • If you read the help for the fit.variogram function you will see it is a parameter to the function. Are you new to R as well?
    – Spacedman
    Commented Jun 30, 2021 at 9:31
  • yes. I am beginner.
    – Yon Balcha
    Commented Jun 30, 2021 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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