I have a data table with the following columns in a CSV file.
X Y Zinc L F C --- --- ----- -- --- ----
Of course, I can import the CSV file as a data frame
a <- read.csv('givendata.csv', header = T)
And convert this data into spatial data by
coordinates(a) = ~X + Y
Now, I wish to run kriging by using L, F and C as spatial input variables and Zinc as the output variable. How do I achieve this?
Edit: I am new to Kriging.
I am adding some more explanation to the question, based on a comment that I do not have an idea about linear modelling.
If I do the following
A1 <- read.csv('givendata.csv', header = T) mymodel <- lm(Zinc ~ L + F + C, data = A1)
it gives the output, with all the regression coefficients and the constant. But, these observations have spatial inputs (see the meuse dataset), which is why it is referred to as a spatial variable (this is GIS.SE!).
Now suppose I were to take the following steps:
x.range <- (range(A1@coords[,1])) y.range <- (range(A1@coords[,2])) A1.grd <- expand.grid(x=seq(from=x.range, to=x.range, by=30), y=seq(from=y.range, to=y.range, by=30)) coordinates(A1.grd) <- ~x+y gridded(A1.grd) <- TRUE library(automap) kZinc <- autoKrige(Zinc ~ L + F + C, A1, A1.grd)
I get the following error:
Error in eval(expr, envir, enclos) : object 'L' not found
which is funny because the
lm was working and the Kriging does not work!