1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
\name{RFfit}
\alias{RFfit}
%\alias{mleRF}% obsolete
\alias{RFfit.default}
\title{Fitting model parameters to spatial data (regionalised variables)
and to linear (mixed) models}
\description{
The function estimates arbitrary parameters of
a random field specification with various methods.
Currently, the models to be fitted can be
\itemize{
\item{\link[=RPgauss]{Gaussian random fields}}
\item{\link[=RFformula]{linear models}}
}
The fitting of max-stable random fields and others
has not been implemented yet.
}
\usage{
RFfit(model, x, y = NULL, z = NULL, T = NULL, grid=NULL, data,
lower = NULL, upper = NULL, methods,
sub.methods, optim.control = NULL, users.guess = NULL,
distances = NULL, dim, transform = NULL, params=NULL, ...)
}
\arguments{
\item{model,params}{\argModel
All parameters that are set to \code{NA} will be estimated;
see the examples below.
Type \code{\link{RFgetModelNames}(type="variogram")} to get all options
for \code{model}.
}
\item{x}{\argX}
\item{y,z}{\argYz}
\item{T}{\argT}
\item{grid}{\argGrid}
\item{data}{\argData}
\item{lower}{\argLower}
\item{upper}{\argUpper}
\item{methods}{\argFitmethods}
\item{sub.methods}{\argFitsubmethods. See Details.}
\item{users.guess}{\argUsersguess}
\item{distances,dim}{\argDistances}
\item{optim.control}{\argOptimcontrol}
\item{transform}{\argTransform}
\item{...}{\argDots}
}
\details{
For details on the simulation methods see
\itemize{
\item \link{fitgauss} for \link[=RPgauss]{Gaussian random fields}
\item \link{fitgauss} for \link[=RFformula]{linear models}
}
If \code{x}-coordinates are not given, the function will check
\code{data} for \code{NA}s and will perform imputing.
The function has many more options to tune the optimizer,
see \command{\link{RFoptions}} for details.
If the model defines a Gaussian random field, the options
for \code{methods} and \code{submethods} are currently
\code{"ml"} and \code{c("self", "plain", "sqrt.nr", "sd.inv", "internal")},
respectively.
}
\note{
\itemize{
\item
An important optional argument is \code{boxcox} which indicates
a Box-Cox transformation; see \code{boxcox} in \command{\link{RFoptions}}
and \code{RFboxcox} for details.
\item
Instead of \command{\link[stats]{optim}}, other optimisers can be used,
see \link{RFfitOptimiser}.
\item
Several advanced options can be found in sections \sQuote{General
options} and \sQuote{fit} of \command{\link{RFoptions}}.
\item
In particular, \code{boxcox}, \code{boxcox_lb}, \code{boxcox_ub}
allow Box-Cox transformation.
\item
This function does not depend on the value of
\command{\link{RFoptions}}\code{()$PracticalRange}.
The function \code{RFfit} always uses the standard specification
of the covariance model as given in \command{\link{RMmodel}}.
}
}
\value{
The result depends on the logical value of
\code{\link[=RFoptions]{spConform}}.
If \code{TRUE}, an S4 object is created. In case the model indicates
a Gaussian random field, an
\link[=RFfit-class]{RFfit} object is created.
If \code{spConform=FALSE}, a list is returned.
In case the model indicates
a Gaussian random field, the details are given in \link{fitgauss}.
}
\references{
\itemize{
\item Burnham, K. P. and Anderson, D. R. (2002)
\emph{Model selection and Multi-Model Inference: A Practical
Information-Theoretic Approach.}
2nd edition. New York: Springer.
}
}
\me
\seealso{
\command{\link{RFfitOptimiser}},
\command{\link{RFlikelihood}},
\command{\link{RFratiotest}},
\command{\link{RMmodel}},
\code{\link[=RandomFields-package]{RandomFields}},
\command{\link{weather}}.
}
\examples{\dontshow{StartExample()}
RFoptions(seed=0) ## *ANY* simulation will have the random seed 0; set
## RFoptions(seed=NA) to make them all random again
% options(error=recover)
% source("RandomFields/tests/source.R")
% to do bsp mit box cox
RFoptions(modus_operandi="sloppy")
#########################################################
## simulate some data first ##
points <- 100
x <- runif(points, 0, 3)
y <- runif(points, 0, 3) ## random points in square [0, 3]^2
model <- RMgencauchy(alpha=1, beta=2)
d <- RFsimulate(model, x=x, y=y, grid=FALSE, n=100) #1000
#########################################################
## estimation; 'NA' means: "to be estimated" ##
estmodel <- RMgencauchy(var=NA, scale=NA, alpha=NA, beta=2) +
RMtrend(mean=NA)
RFfit(estmodel, data=d)
#########################################################
## coupling alpha and beta ##
estmodel <- RMgencauchy(var=NA, scale=NA, alpha=NA, beta=NA) +
RMtrend(NA)
RFfit(estmodel, data=d, transform = NA) ## just for information
trafo <- function(a) c(a[1], rep(a[2], 2))
fit <- RFfit(estmodel, data=d,
transform = list(c(TRUE, TRUE, FALSE), trafo))
print(fit)
print(fit, full=TRUE)
\dontshow{\dontrun{
#########################################################
## Estimation with fixed sill (variance + nugget ##
## equals a given constant) ##
estmodel <- RMgencauchy(var=NA, scale=NA, alpha=NA, beta=NA) +
RMnugget(var=NA) + RMtrend(mean=NA)
RFfit(estmodel, data=d, fit.sill=1, fit.optim_var_elimination="try")
#########################################################
## estimation in a anisotropic framework ##
x <- y <- (1:3)/4
model <- RMexp(Aniso=matrix(nc=2, c(4,2,-2,1)), var=1.5)
d <- RFsimulate(model, x=x, y=y, n=n)
estmodel <- RMexp(Aniso=matrix(nc=2, c(NA,NA,-2,1)), var=NA) +
RMtrend(mean=NA)
RFfit(estmodel, data=d, fit.nphi=20)
#########################################################
## AN EXAMPLE HOW TO USE OF PARAMETER 'transform' ##
## estimation of coupled parameters (first column of ##
## the matrix 'Aniso' has identical entries) ##
# source("RandomFields/tests/source.R")
RFfit(estmodel, data=d, transform=list()) # shows positions of NAs
f <- function(param) param[c(1,2,2)]
RFfit(estmodel, data=d, transform=list(c(TRUE, TRUE, FALSE), f))
}}
\dontshow{RFoptions(modus_operandi="normal")}
\dontshow{FinalizeExample()}}
\keyword{spatial}
\keyword{optimize}
|