[R-sig-Geo] Fitting variogram model using NLS function in R
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Wed Sep 4 19:39:51 CEST 2013
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 09/04/2013 05:50 PM, Moshood Agba Bakare wrote:
> Dear Dr. Edzer, Yes, I read about the various options of fit.method
> in gstat manual. The default value of fit.method for fitting
> variogram model to empirical variogram is 7. That is, the number of
> pair of points divided by squares of the distance, h. I refitted
> the model by setting fit.method =1 which is weighted least squares
> so that it would be the same with default estimation method of nls
> function. The comparison of the results differ greatly despite
> using the same inital starting value. I am worried! Is there wrong
> in my R script? Please help.
Instead of sharing emotions, you might as well share information.
You don't provide a reproducible example, and you haven't shown your R
script of the second attempt. In any case, I haven't seen you specify
weights for nls(), and hence don't share your worries.
>
> Thank you Moshood
>
>
> On Wed, Sep 4, 2013 at 4:40 AM, Edzer Pebesma
> <edzer.pebesma at uni-muenster.de
>> wrote:
>
> did you read the documentation of argument fit.method in function
> gstat::fit.variogram?
>
>
> On 09/04/2013 02:00 AM, Moshood Agba Bakare wrote:
>>>> Dear All, I tried to compare the result obtained by fitting
>>>> the spherical variogram model using fit.variogram and nls
>>>> functions. The large difference in the results is a great
>>>> concern for me knowing that the two functions use Weighted
>>>> Least Squares (WLS) approach for estimating parameters. The
>>>> steps taken are as follows:
>>>>
>>>> ## Fit empirical semivariogram using gstat
>>>> empvar<-variogram(yield ~ 1,canmod.sp,cutoff= 400,width = 25,
>>>> Cressie=TRUE)
>>>>
>>>> # Fitting Spherical variogram model to sample variogram
>>>>
>>>> sph.var<- vgm(psill =130, model = "Sph", range = 65, nugget =
>>>> 180) sph.mod<-fit.variogram(empvar, model = sph.var)
>>>> print(sph.mod)
>>>>
>>>> The result obtain from fitting the spherical model to sample
>>>> variogram is sph.mod model psill range 1
>>>> Nug 230.917736411 0.0000000000 2 Sph 108.323055319
>>>> 87.6889385431
>>>>
>>>> The non-linear least squares (NLS) approach use by default s
>>>> Gauss-newton algorithm in an iterative search process. I used
>>>> the initial values obtained from the empirical variogram
>>>> above (psill=130, range=65, and nugget=180) as starting
>>>> values for the iterative procedure.
>>>>
>>>> ## Define Spherical Variogram functions for NLS
>>>>
>>>> sph.vgram <- function(dist, range, psill, nugget){ dist <-
>>>> dist/range nugget + psill*ifelse(dist < 1, (1.5 * dist - 0.5
>>>> * dist^3),1) }
>>>>
>>>> ## Fitting spherical with NLS
>>>>
>>>> fit.var <- nls(gamma~sph.vgram(dist,range,psill,nugget),data
>>>> = empvar, start=list(psill=130, range=65,
>>>> nugget=180),trace=T)
>>>>
>>>> The result obtained from the nls fitting is
>>>>
>>>> Nonlinear regression model model: gamma ~ sph.vgram(dist,
>>>> range, psill, nugget) data: empvar psill range
>>>> nugget 90.7071423 342.1025007 278.9542178 residual
>>>> sum-of-squares: 1140.67875
>>>>
>>>> Number of iterations to convergence: 18 Achieved convergence
>>>> tolerance: 9.79837651e-06
>>>>
>>>> Could anyone explain why large difference in the two result?
>>>> Is the R script for fitting the NLS right? I am worried for
>>>> having such disparity. Thanks while looking forward to
>>>> reading your suggestion, comments and advice. Moshood.
>>>>
>>>> [[alternative HTML version deleted]]
>>>>
>>>> _______________________________________________ R-sig-Geo
>>>> mailing list R-sig-Geo at r-project.org
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>
>
>>
>> _______________________________________________ R-sig-Geo mailing
>> list R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>>
>
- --
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJSJ3BnAAoJEM1OCHCtOnfxMHUH/RQIPHQLzcEg3i1KF/WDJc2b
26rJ3JCvua27M5XB7HBfQBwkr9gdsI1BfSpVJwGSQKgy5zdX0KOl6Dk7jSqWJRH5
SCD7YLBBHvH+DeTC24NBo+1sdu4XaCAWxK3olp1oQ2v/q+KHQiIJ8Yv20wO0paFT
vWsthZeEOKfMd1x0JDXuN+KDPGz91QP5p33TQMDfKMdxOP2c0J7dhuNqgq7Tq8th
+tId+X5B3xyXvVLLM7s8OC+6L0BpAQM1YtjwmIhSEMdKM7ljRoN4JHgfZ9KKqOuX
20mVCBG0DQPZLVC0A6jUOPPPB9Zx4cqlicwnRdu9bdGLiBq7+oXctjv3QmeAOC8=
=Bg1J
-----END PGP SIGNATURE-----
More information about the R-sig-Geo
mailing list