Commit 03895576 authored by Laura Mack's avatar Laura Mack
Browse files

use NA instead of NULL as default for init.vals (vector)

parent 7fca7625
......@@ -97,8 +97,6 @@
#### IDF.plot ####
#' Plotting of IDF curves at a chosen station
#'
#' @param durations vector of durations for which to calculate the quantiles.
......@@ -108,8 +106,8 @@
#' (or \code{\link{gev.d.params}} for model with covariates).
#' @param probs vector of exeedance probabilities for which to plot IDF curves (p = 1-1/ReturnPeriod)
#' @param cols vector of colors for IDF curves. Should have same length as \code{probs}
#' @param add logical indicating if plot should be added to existing plot
#' @param legend logical indicating if legend should be plotted
#' @param add logical indicating if plot should be added to existing plot, default is FALSE
#' @param legend logical indicating if legend should be plotted (TRUE, the default)
#' @param ... additional parameters passed on to the \code{plot} function
#'
#' @export
......
......@@ -25,7 +25,7 @@
#' @param mulink,siglink,shlink,thetalink,etalink Link functions for generalized linear
#' modelling of the parameters, created with \code{\link{make.link}}.
#' @param init.vals vector of length 5, giving initial values for parameter intercepts
#' used to model the parameters (order: mu, sigma, xi, theta, eta). If NULL (the default) is given, initial parameters are obtained
#' used to model the parameters (order: mu, sigma, xi, theta, eta). If rep(NA,5) (the default) is given, initial parameters are obtained
#' internally by fitting the GEV separately for each duration and applying a linear model to obtain the
#' duration dependency of the location and shape parameter.
#' @param theta_zero Logical value, indicating if theta should be estimated (FALSE, the default) or
......@@ -75,7 +75,7 @@ gev.d.fit<-
function(xdat, ds, ydat = NULL, mul = NULL, sigl = NULL, shl = NULL, thetal = NULL, etal = NULL,
mulink = make.link("identity"), siglink = make.link("identity"), shlink = make.link("identity"),
thetalink = make.link("identity"), etalink = make.link("identity"),
init.vals = NULL, theta_zero = FALSE,
init.vals = rep(NA,5), theta_zero = FALSE,
show = TRUE, method = "Nelder-Mead", maxit = 10000, ...)
{
if (length(xdat) != length(ds)) {
......@@ -99,27 +99,34 @@ gev.d.fit<-
npar <- max(sapply(z$model,function(x){return(ifelse(is.null(x),0,max(x)))}))
if(any(npar>ncol(ydat),npar>0 & is.null(ydat)))stop("Not enough columns in covariates matrix 'ydat'.")
# if no initial values where passed, calculate initial values for mu.d, sigma_0, xi, eta using IDF.init
if(!is.null(init.vals)){
if(length(init.vals)!=5){
warning('Parameter init.vals is not used, because it is not of length 5.')
init.vals <- NULL
}else{
init.vals <- data.frame(mu = init.vals[1], sigma = init.vals[2], xi = init.vals[3]
# initial values
if(length(init.vals)!=5) {
warning('Parameter init.vals is not used, because it is not of length 5.')
init.vals <- rep(NA,5)
}
if(!any(is.na(init.vals))){ #all initial values are given
init.vals <- data.frame(mu = init.vals[1], sigma = init.vals[2], xi = init.vals[3]
,theta = init.vals[4], eta = init.vals[5])
}else if(any(!is.na(init.vals))) { #some initial values are given
init.vals.user <- init.vals
init.vals <- gev.d.init(xdat,ds,z$link) #calculate init.vals using gev.d.init
for (i in 1:length(init.vals)){ #overwrite the calculated initial values with the ones given by the user
if(!is.na(init.vals.user[i])) {
init.vals[i]<-init.vals.user[i]
}
}
if(is.null(init.vals)){
# message('Initial values are calculated.')
}else{ #no initial values are given
init.vals <- gev.d.init(xdat,ds,z$link)
}
if(theta_zero==TRUE) { #if theta should stay zero
init.vals[4] = 0
}
# generate covariates matrices:
if (is.null(mul)) {
if (is.null(mul)) { #stationary
mumat <- as.matrix(rep(1, length(xdat)))
muinit <- init.vals$mu
}else {
}else { #non stationary
z$trans <- TRUE
mumat <- cbind(rep(1, length(xdat)), ydat[, mul])
muinit <- c(init.vals$mu, rep(0, length(mul)))
......@@ -159,7 +166,7 @@ gev.d.fit<-
if(!theta_zero){#When theta parameter is not included (default)
init <- c(muinit, siginit, shinit, thetainit, etainit)
}else{ #Do not return initial value for theta if user does not want theta, as Hessian will fail.
}else{ #Do not return initial value for theta, if user does not want theta, as Hessian will fail.
init <- c(muinit, siginit, shinit, etainit)
}
......
......@@ -26,9 +26,9 @@ as obtained from \code{\link{gev.d.fit}}
\item{cols}{vector of colors for IDF curves. Should have same length as \code{probs}}
\item{add}{logical indicating if plot should be added to existing plot}
\item{add}{logical indicating if plot should be added to existing plot, default is FALSE}
\item{legend}{logical indicating if legend should be plotted}
\item{legend}{logical indicating if legend should be plotted (TRUE, the default)}
\item{...}{additional parameters passed on to the \code{plot} function}
}
......
......@@ -18,7 +18,7 @@ gev.d.fit(
shlink = make.link("identity"),
thetalink = make.link("identity"),
etalink = make.link("identity"),
init.vals = NULL,
init.vals = rep(NA, 5),
theta_zero = FALSE,
show = TRUE,
method = "Nelder-Mead",
......@@ -46,7 +46,7 @@ Parameters are: modified location, scale_0, shape, duration offset, duration exp
modelling of the parameters, created with \code{\link{make.link}}.}
\item{init.vals}{vector of length 5, giving initial values for parameter intercepts
used to model the parameters (order: mu, sigma, xi, theta, eta). If NULL (the default) is given, initial parameters are obtained
used to model the parameters (order: mu, sigma, xi, theta, eta). If rep(NA,5) (the default) is given, initial parameters are obtained
internally by fitting the GEV separately for each duration and applying a linear model to obtain the
duration dependency of the location and shape parameter.}
......
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