I have been trying to fit a Spatio-Temporal Variogram using non-separable
classes of covariances using the WLS criterion(attached is my data file). But
I'm not getting any result using optim() or nls(). Here is the way I'm
using the optim() function for a single parametric model.
weights<-c(with(coord.smooth,table(tlag,slag)))
weights<-weights[-1]
##Parametric ST variogram Families
weightedLS<-function(par){
Sigma<-par[1]
Tau<-par[2]
a<-par[3]
b<-par[4]
n<-weights
observed<-coord.smooth[,3]
h<-coord.smooth[,2]
u<-coord.smooth[,1]
eg1<-exp(-b^2*h^2/(a^2*u^2+1))/(a^2*u^2+1)
pred<-Sigma*(1-eg1)+Tau
wls<-sum(n*(observed/pred)-1)^2
return(wls)
}
eg1.fit<-optim(c(0,0,0,0),fn=weightedLS,
method="L-BFGS-B",lower=rep(0,4))
On Mon, Mar 10, 2014 at 7:42 PM, Humayera Islam <hislam at isrt.ac.bd> wrote:
I have been trying to fit a Spatio-Temporal Variogram using non-separable
classes of covariances using the WLS criterion, as described in papers such
as Cressie and Huang(1999), Gneiting (2002). Attached is the .Rda file
which includes a data set named coord.smooth having three variables time
lag, space lag and variogram values. I have plotted a wireframe as well.
But I'm not getting any result using optim() or nls(). Here is the way I'm
using the optim() function for a single parametric model.
weights<-c(with(coord.smooth,table(tlag,slag)))
weights<-weights[-1]
##Cressie Huang (1991)
##Parametric ST variogram Families
weightedLS<-function(par){
Sigma<-par[1]
Tau<-par[2]
a<-par[3]
b<-par[4]
n<-weights
observed<-coord.smooth[,3]
h<-coord.smooth[,2]
u<-coord.smooth[,1]
eg1<-exp(-b^2*h^2/(a^2*u^2+1))/(a^2*u^2+1)
pred<-Sigma*(1-eg1)+Tau
wls<-sum(n*(observed/pred)-1)^2
return(wls)
}
eg1.fit<-optim(c(0,0,0,0),fn=weightedLS,
method="L-BFGS-B",lower=rep(0,4))
I have obtained the following error:
Error in optim(c(0, 0, 0, 0), fn = weightedLS, method = "L-BFGS-B", lower
= rep(0, :
L-BFGS-B needs finite values of 'fn'
-------------- next part -------------- An HTML attachment was scrubbed... URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140310/e2524186/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: coord.smooth.Rda Type: application/octet-stream Size: 25454 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140310/e2524186/attachment.obj>