[R-sig-Geo] passing 'cutoff' to the 'autoKrige' function ('automap' package)

Mauricio Zambrano hzambran.newsgroups at gmail.com
Mon Mar 28 10:47:36 CEST 2011


2011/3/26 Paul Hiemstra <p.hiemstra at geo.uu.nl>:
> 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.

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

-- 
=======================================================
FLOODS Action
Land Management and Natural Hazards Unit
Institute for Environment and Sustainability
European Commission, Joint Research Centre
work-phone : (+39)-(0332)-789588
work-fax   : (+39)-(0332)-786653
=======================================================
DISCLAIMER:
"The views expressed are purely those of the writer
and may not in any circumstances be regarded as stating
an official position of the European Commission."
=======================================================
Linux user #454569 -- Ubuntu user #17469
=======================================================
"Go as far as you can see; when you get there,
you'll be able to see farther."
(John Pierpont Morgan)

>
> cheers,
> Paul
>
> [1] https://bitbucket.org/paulhiemstra/automap/issues/new
>
> On 03/25/2011 08:57 AM, Mauricio Zambrano wrote:
>>
>> 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:
>>
>>
>>>
>>> x.ok<- autoKrige(zinc~1, meuse, meuse.grid,
>>> miscFitOptions=list(maxdist=100,  cutoff=500, width=50) )
>>>
>>
>> but both arguments are ignored.
>>
>>
>> I also tried with:
>>
>>
>>>
>>> x.ok<- autoKrige(zinc~1, meuse, meuse.grid, maxdist=100,  cutoff=500,
>>> width=100)
>>>
>>
>> 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.
>>
>>
>>
>
>
> --
> Paul Hiemstra, MSc
> Department of Physical Geography
> Faculty of Geosciences
> University of Utrecht
> Heidelberglaan 2
> P.O. Box 80.115
> 3508 TC Utrecht
> Phone:  +3130 253 5773
> http://intamap.geo.uu.nl/~paul
> http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770
>
> currently @ KNMI
> paul.hiemstra_AT_knmi.nl
>
>



More information about the R-sig-Geo mailing list