Estimate spatial parameters, via maximum likelihood, from data
rather than from time series residuals; Fit a GLS with these specifications.
fitGLS_opt fits a GLS by estimating spatial parameters from
data. fitCor, combined with fitGLS(nugget = NA),
gives better estimates of spatial parameters, but time-series residuals may
not be available in all cases. In these cases, spatial parameters can be
estimated from distances among points and a response vector. Mathematical
optimization of the log likelihood of different GLS models are computed by
calling optim() on fitGLS.
Distances are calculated with distm_FUN and a covariance matrix is
calculated from these distances with covar_FUN. Arguments to to
covar_FUN, except distances, are given by start and fixed.
Parameters specified in start will be be estimated while those given
by fixed will remain constant throughout fitting. Parameter names in
start and fixed should exactly match the names of arguments in
covar_FUN and should not overlap (though, fixed takes precedence).
In addition to arguments of covar_FUN a "nugget" component can
also be occur in start or fixed. If "nugget" does not occur
in either vector, the GLS are fit with nugget = 0. A zero nugget also
allows much faster computation, through recycling the common
inverse cholesky matrix in each GLS computation. A non-zero nugget requires
inversion of a different matrix at each iteration, which can be
substantially slower.
If opt.only = FALSE, the estimated parameters are used to fit the final
maximum likelihood GLS solution with fitGLS() and arguments
formula0, save.xx, save.invchol, and no.F.
Some parameter combinations may not produce valid covariance matrices. During
the optimization step messages about non-positive definitive V may result on
some iterations. These warnings are produced by fitGLS and NA
log-likelihoods are returned in those cases.
Note that fitGLS_opt fits multiple GLS models, which requires
inverting a large matrix for each one (unless a fixed 0 nugget is used).
This process is very computationally intensive and may take a long time to
finish depending upon your machine and the size of the data.
Sometimes optim can have a difficult time finding a reasonable solution
and without any constraits on parameter space (with certain algorithms), results
may even be nonsensical. To combat this, fitGLS_opt has the arguments
trans and backtrans which allow you to transform
(and back-transform) parameters to a different scale. For example, you may
want to force the 'range' parameter between 0 and 1. The logit function can
do just that, as its limits are -Inf and Inf as x approaches 0 and 1,
respectively. So, we can set trans to the logit function:
trans = list(range = function(x)log(x/(1-x))). Then we need to set
backtrans to the inverse logit function to return a parameter value
between 0 and 1: backtrans = list(range = function(x)1/(1+exp(-x))).
This will force the optimizer to only search for the range parameter in the
space from 0 to 1. Any other constraint function can be used for trans
provided that there is a matching back-transformation.