Skip to content

passing 'cutoff' to the 'autoKrige' function ('automap' package)

5 messages · Mauricio Zambrano-Bigiarini, Paul Hiemstra

#
Dear list,

Is there any way to pass the 'cutoff' argument (or 'width', or other
arguments of the 'variogram' function of the 'gstat' package)  to the
'autoKrige' function of the 'automap' package ?

I tried with:
but both arguments are ignored.


I also tried with:
but I got the following error message:

"Error in gstat(formula = formula, data = locations, model = model,
beta = beta,  :
 unused argument(s) (cutoff = 500, width = 50)"


Some session info:

R version 2.12.2 (2011-02-25)
automap_1.0-9
gstat_0.9-79


Here there is a reproducible example (for the 'autofitVariogram'
function, because I didn't find a way to pass the 'cutoff' and 'with'
arguments to the 'autoKrige' function):

------------ START ---------------

library(automap)

# Data preparation
data(meuse)
coordinates(meuse) =~ x+y
data(meuse.grid)
gridded(meuse.grid) =~ x+y

# Computing the 'boundaries' value for the 'variogram' function,
# in order to properly compare its results with those of the
'autofitVariogram' function

input_data <- meuse

x <- coordinates(input_data)[, 1]
y <- coordinates(input_data)[, 2]
scale_number <- (0.35 * sqrt((max(x) - min(x))^2 + (max(y) - min(y))^2)/100)
boundaries <- c(2, 4, 6, 9, 12, 15, 25, 35, 50, 65, 80, 100) * scale_number

# variogram computation. Case 1, default parameters
vgm.gstat   <- variogram(zinc ~ 1, locations=meuse, boundaries=boundaries)
vgm.automap <- autofitVariogram(zinc ~ 1, input_data=meuse)

# These variograms are the same
print(vgm.gstat)
print(vgm.automap$exp_var)

# variogram computation. Case 2, with 'cutoff' and 'width'
vgm.gstat2   <- variogram(zinc ~ 1, locations=meuse, cutoff=500, width=50)
vgm.automap2 <- autofitVariogram(zinc ~ 1, input_data=meuse,
cutoff=500, width=50)

# These variograms are NOT the same
print(vgm.gstat2)
print(vgm.automap2$exp_var)

# variogram computation. Case 3, with 'cutoff', 'width' and 'boundaries'
vgm.gstat3   <- variogram(zinc ~ 1, locations=meuse, cutoff=500,
width=50, boundaries=boundaries)
vgm.automap3 <- autofitVariogram(zinc ~ 1, input_data=meuse,
cutoff=500, width=50)

# These variograms are the same
print(vgm.gstat3)
print(vgm.automap3$exp_var)


------------ END ---------------


Looking at the examples, I think that the problem arises because the
'boundaries' argument superimpose its values to the 'cutoff' one, both
in the 'variogram' and 'autofitVariogram' functions.

However, whereas in the 'variogram' function the boundaries are
optional, in the 'autofitVariogram' they are computed internally (in a
smart way), but its maximum default value disable any shorter 'cutoff'
passed to the 'autofitVariogram' function.


In any case, I think that even after solving the issue related to
'cutoff' and 'boundaries', it will still be impossible to pass the
'cutoff' argument to the 'autoKrige' function, because the '...'
argument in 'autoKrige' is passed (internally) to the 'krige' function
and not to 'autofitVariogram' one. Am I right ?

I'm not sure if this could be considered a bug, but I thought it could
be useful to report this behaviour, for the next release of 'automap'.


Kind regards,

Mauricio Zambrano B.
1 day later
#
Hi,

The miscFitOptions parameter does not include the 'variogram' paramters. 
I will look into adding them, together with the option to set the 
boundaries manually. However, autofitVariogram at this stage defines a 
fixed set of boundaries, so I'm not sure if the parameters you mention 
will resort any effect even when passing them on. An option at this 
stage would be to use the normal krige function combined with 
autofitVariogram. autofitVariogram passes on parameters to variogram() 
using the ... .

Could you create a new issue in the bitbucket.org account which stores 
automap [1]? This way I can keep track of the issues that need to be 
fixed for autofitVariogram.

cheers,
Paul

[1] https://bitbucket.org/paulhiemstra/automap/issues/new
On 03/25/2011 08:57 AM, Mauricio Zambrano wrote:

  
    
1 day later
#
2011/3/26 Paul Hiemstra <p.hiemstra at geo.uu.nl>:
Thanks Paul for your answer.

I created the issue in bitbucket.org, as an 'enhancement', not a bug.

If you manage to include 'cutoff' and other  'variogram' paramters
into the 'autofitVariogram' function, a way to use its value could be
(after the definition of the 'scale_number'):


    scale_number = (0.35 * sqrt((max(x) - min(x))^2 + (max(y) -
        min(y))^2)/100)
    if (!is.na(cutoff))
      scale_number <- min(scale_number, cutoff/100)
    boundaries = c(2, 4, 6, 9, 12, 15, 25, 35, 50, 65, 80, 100) * scale_number


Do you think it may work ?

In the mean time the combination of 'autofitVariogram' with 'krige'
that you mention is a nice way to overcome the issue with cutoff.

Thanks again for such a useful package.

Cheers,

Mauricio
#
On 03/28/2011 10:47 AM, Mauricio Zambrano wrote:
Thanks for creating the issue, I'm not sure when I'll come round to 
fixing the issue though ;). I'll probably fix the problem by giving the 
user the freedom to change all inputs to variogram(), including 
boundaries. But I'll figure that out later.
Could be an option.

cheers,
Paul

  
    
#
2011/3/28 Paul Hiemstra <p.hiemstra at geo.uu.nl>:
It would be great if -when you find the time- you can  give the user
the possibility to change all inputs to variogram().
Cheers,

Mauricio