I am at a complete loss on what I am doing wrong here.

I am trying to build a variogram. No matter what i do i get errors.

My Data:

     id       lon      lat                  datetime         m1      m2       m3
1      1 -121.3501 41.86009 2016-03-01 00:00:00-08:00    43.200  3993.071  3993.071
2      2 -121.3412 41.94472 2016-03-01 00:00:00-08:00    38.800  4036.954  4036.954
3      3 -121.5138 41.99801 2016-03-01 00:00:00-08:00    24.600  4023.301  4023.301

After converting to a Spatial DataFrame

class       : SpatialPointsDataFrame 
features    : 3196 
extent      : -124.2696, -116.1304, 33.11097, 42.01195  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
variables   : 5
names       : id,                  datetime,      m1,      m2,        m3 
min values  :   1, 2016-03-01 00:00:00-08:00,     0.000,     0.020,  0.0003920282 
max values  :   3196, 2016-03-01 00:00:00-08:00, 14360.500, -7470.500, -3.4202715765 

This is just a small piece of the data. About 3000 rows in total

My dataframe setup

df <- read.table("input.csv", header=TRUE, sep=",")
df = na.omit(df)
coordinates(df) = ~lon+lat

Some samples of what I have tried and the error messages:

v = variogram(m3~1, data=df)

Error in variogram(m3 ~ 1, data = df) : unused argument (data = df)

v = variogram(df$m3~1, data=df, dX=0)

Error in variogram(df$m3 ~ 1, data = df, dX = 0) : 
  unused arguments (data = df, dX = 0)

Since it keeps telling me these parameters are unused...I tried this:

v = variogram(df$m3~1)

Error in variogram(df$m3 ~ 1) : 
  argument "X" is missing, with no default

All I am trying to do at this point is create a basic variogram on the m2 or m3 column of data. m3 column is the m2 column with a normal score transformation done on it. I just left the code out for that.

What am I doing wrong?

  • Have you tried v = variogram(m3~1, locations = df ?
    – Jot eN
    Sep 13, 2018 at 9:10

1 Answer 1


If you look at the help for variogram, you'll see:

 # no trend:
 coordinates(meuse) = ~x+y
 variogram(log(zinc)~1, meuse)
 # residual variogram w.r.t. a linear trend:
 variogram(log(zinc)~x+y, meuse)

The first argument is a formula in the column names of the second argument, the data. Neither argument are named in the call. So for your case:

 variogram(m3~1, df)

should work. I don't understand why variogram(m3~1, data=df) doesn't work for you, since variogram(zinc~1, data=meuse) does....

If the above still fails, we might need to check out your data personally.

  • Thanks for your help here. I was doing the formula wrong-ish. I was trying to do log(m3)~1 but my data has negative values. I think this was causing the error. Arcgis helped find that issue trying to plot a histogram on the data. It is working just find using variogram(m3~1, data=df). I did not realize i could do it like that. So thank you very much.
    – Chris
    Sep 16, 2018 at 4:50

Your Answer

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

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