1

I have a data.frame in R whose variables represent locations and whose observations are measures of a certain variable in those locations. I want to measure the decay of dependence for certain locations depending on distance, so the variogram comes particularly useful for my studies.

I am trying to use gstat library but I am a bit confused about certain parameters. As far as I understand the (empirical) variogram should only need as basic data:

  1. The locations of the variables
  2. Observations for these variables

And then other parameters like maximun distance, directions, ...

Now, gstat::variogram() function requires as first input an object of class gstat. Checking the documentation of function gstat() I see that it outputs an object of this class, but this function requires a formula argument, which is described as:

formula that defines the dependent variable as a linear model of independent variables; suppose the dependent variable has name z, for ordinary and simple kriging use the formula z~1; for simple kriging also define beta (see below); for universal kriging, suppose z is linearly dependent on x and y, use the formula z~x+y

Could someone explain me what this formula is for?

D1X
  • 5,025
  • 5
  • 21
  • 36

1 Answers1

1

try

methods(variogram)

and you'll see that gstat has several methods for variogram, one requiring a gstat object as first argument.

Given a data.frame, the easiest is to use the formula method:

variogram(z~1, ~x+y, data)

which specifies that in data, z is the observed variable of interest, ~1 specifies a constant mean model, ~x+y specify that the coordinates are found in columns x and y of data.

Edzer Pebesma
  • 3,814
  • 16
  • 26