# [R-sig-Geo] geoR: error fitting a linear model

Andre Schützenmeister andre.schuetzenmeister at uni-hohenheim.de
Wed Dec 2 12:32:31 CET 2009

```Hi All,

Does anybody know how to fit a linear model to an empirical semivariogram?
Something just does not work out.

I have tried this:

# generate data

> grid <- expand.grid(1:10,1:10)[,2:1]
> z <- grid[,1]*grid[,2]*rnorm(100,20,5)
> grid <- cbind(grid,z)
> colnames(grid) <- c("X","Y","Z")

# compute empirical semivariogram

> esvg <- variog(coords=grid[,c("X","Y")], data=grid[,"Z"],
breaks=seq(.5,10,.5) )

# fit exponential model to 'esvg'

> exp_mod <- variofit(esvg, cov.model="exp", ini.cov.pars=c(8e5,10),
nugget=1e5)

> exp_mod
variofit: model parameters estimated by WLS (weighted least squares):
covariance model is: exponential
parameter estimates:
tausq     sigmasq         phi
0.0000 803538.4015     13.3603
Practical Range with cor=0.05 for asymptotic range: 40.02385

variofit: minimised weighted sum of squares = 3.559216e+13

# fit linear model to 'esvg', and an error occurs

> exp_mod <- variofit(esvg, cov.model="lin", ini.cov.pars=c(8e5,0),
nugget=1e5)

Error in uniroot(findRange, interval = c(0, 50 * phi + 1), cm = cov.model,
:
f() values at end points not of opposite sign

I would appreciate any help. Thanks in advance.

Andre

```