Commit 3535fd24 authored by Jana Ulrich's avatar Jana Ulrich
Browse files

be able to pass init.vals, so that in iterations init.vals need to only be calculated once

parent 10e8be56
......@@ -31,6 +31,7 @@
#' @param show Logical; if TRUE (the default), print details of the fit.
#' @param method The optimization method used in \code{\link{optim}}.
#' @param maxit The maximum number of iterations.
#' @param init.vals vector of length 5, giving initial values for parameter intercepts
#' @param ... Other control parameters for the optimization.
#' @return A list containing the following components.
#' A subset of these components are printed after the fit.
......@@ -47,6 +48,9 @@
#' A zero indicates successful convergence.}
#' \item{data}{data is standardized to standart Gumbel.}
#' \item{cov}{The covariance matrix.}
#' \item{vals}{Parameter values for every data point.}
#' \item{init.vals}{Initial values that where used.}
#' \item{ds}{Durations for every data point.}
#' @seealso \code{\link{dgev.d}}, \code{\link{IDF.agg}}, \code{\link{gev.fit}}, \code{\link{optim}}
#' @export
#' @importFrom stats optim
......@@ -69,7 +73,7 @@ gev.d.fit<-
function(xdat, ds, ydat = NULL, mul = NULL, sigl = NULL, shl = NULL, thetal = NULL, etal = NULL,
mulink = identity, siglink = identity, shlink = identity, thetalink = identity, etalink = identity,
muinit = NULL, siginit = NULL, shinit = NULL, thetainit = NULL, etainit = NULL,
show = TRUE, method = "Nelder-Mead", maxit = 10000, ...)
show = TRUE, method = "Nelder-Mead", maxit = 10000, init.vals = NULL, ...)
{
#
# obtains mles etc for d-gev distn
......@@ -88,7 +92,9 @@ gev.d.fit<-
z$trans <- FALSE # indicates if fit is non-stationary
# calculate initial values for mu.d, sigma_0, xi, eta using IDF.init: (thetainit=0)
if(any(is.null(c(muinit,siginit,shinit,etainit)))){
if(!is.null(init.vals)){init.vals <- data.frame(mu = init.vals[1], sigma = init.vals[2], xi = init.vals[3]
,theta = init.vals[4], eta = init.vals[5])}
if(any(is.null(c(muinit,siginit,shinit,etainit)))& is.null(init.vals)){
init.vals <- gev.d.init(xdat,ds,ifelse(is.null(thetainit),0,thetainit[1]))
}
# TODO: transform initial values with link function
......@@ -217,6 +223,7 @@ gev.d.fit<-
}
z$se <- sqrt(diag(z$cov)) # sqrt(digonal entries) = standart error of mle's
z$vals <- cbind(mut, sc0, xi, theta, eta)
z$init.vals <- as.numeric(init.vals)
colnames(z$vals) <- c('mut','sigma0','xi','theta','eta')
z$ds <- ds
if(show) {
......
......@@ -9,7 +9,7 @@ gev.d.fit(xdat, ds, ydat = NULL, mul = NULL, sigl = NULL,
siglink = identity, shlink = identity, thetalink = identity,
etalink = identity, muinit = NULL, siginit = NULL, shinit = NULL,
thetainit = NULL, etainit = NULL, show = TRUE,
method = "Nelder-Mead", maxit = 10000, ...)
method = "Nelder-Mead", maxit = 10000, init.vals = NULL, ...)
}
\arguments{
\item{xdat}{A vector containing maxima for different durations.
......@@ -41,6 +41,8 @@ duration dependency of the location and shape parameter.}
\item{maxit}{The maximum number of iterations.}
\item{init.vals}{vector of length 5, giving initial values for parameter intercepts}
\item{...}{Other control parameters for the optimization.}
}
\value{
......@@ -58,7 +60,10 @@ duration offset and duration exponent, resp.}
\item{conv}{The convergence code, taken from the list returned by \code{\link{optim}}.
A zero indicates successful convergence.}
\item{data}{data is standardized to standart Gumbel.}
\item{cov}{The covariance matrix.}
\item{cov}{The covariance matrix.}
\item{vals}{Parameter values for every data point.}
\item{init.vals}{Initial values that where used.}
\item{ds}{Durations for every data point.}
}
\description{
Modified \code{\link[ismev]{gev.fit}} function for Maximum-likelihood fitting
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment