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

use RcppRoll-package instead of zoo::rollapplyr in IDF.agg

parent dc65bf7c
......@@ -17,7 +17,7 @@ Description: Intensity-duration-frequency (IDF) curves are a widely used analysi
Imports: stats4,
evd,
ismev,
zoo,
RcppRoll,
pbapply
License: GPL (>=2)
Encoding: UTF-8
......
......@@ -10,6 +10,7 @@ export(gev.d.params)
export(pgev.d)
export(qgev.d)
export(rgev.d)
importFrom(RcppRoll,roll_sum)
importFrom(evd,dgev)
importFrom(evd,pgev)
importFrom(evd,qgev)
......@@ -30,5 +31,3 @@ importFrom(stats,lm)
importFrom(stats,make.link)
importFrom(stats,median)
importFrom(stats,optim)
importFrom(zoo,as.zoo)
importFrom(zoo,rollapplyr)
......@@ -34,8 +34,7 @@
#'
#' @export
#' @importFrom pbapply pbsapply
#' @importFrom zoo rollapplyr
#' @importFrom zoo as.zoo
#' @importFrom RcppRoll roll_sum
#'
#' @examples
#' dates <- as.Date("2019-01-01")+0:729
......@@ -69,10 +68,11 @@
# function 1: aggregate over single durations and find annual maxima:
agg.ts <- function(ds){
runmean <- rollapplyr(as.zoo(data.s[,names[2]]),ds/dtime,FUN=sum,fill =NA,align='right')
runmean <- runmean/ds #intensity per hour
runsum = RcppRoll::roll_sum(data.s[,names[2]],ds/dtime,fill=NA)
#runmean <- rollapplyr(as.zoo(data.s[,names[2]]),ds/dtime,FUN=sum,fill =NA,align='right')
runsum <- runsum/ds #intensity per hour
subset <- is.element(as.POSIXlt(data.s[,names[1]])$mon,which.mon)
max <- tapply(runmean[subset],(as.POSIXlt(data.s[,names[1]])$year+1900)[subset],
max <- tapply(runsum[subset],(as.POSIXlt(data.s[,names[1]])$year+1900)[subset],
function(vec){
n.na <- sum(is.na(vec))
max <- ifelse(n.na <= na.accept,max(vec,na.rm = TRUE),NA)
......
......@@ -14,6 +14,7 @@
#' @param xdat A vector containing maxima for different durations.
#' This can be obtained from \code{\link{IDF.agg}}.
#' @param ds A vector of aggregation levels corresponding to the maxima in xdat.
#' 1/60 corresponds to 1 minute, 1 corresponds to 1 hour.
#' @param ydat A matrix of covariates for generalized linear modelling of the parameters
#' (or NULL (the default) for stationary fitting). The number of rows should be the same as the
#' length of xdat.
......@@ -261,7 +262,6 @@ gev.d.fit<-
#' @description obtain initial values by fitting every duration seperately
#' @param xdat vector of maxima for differnt durations
#' @param ds vector of durations belonging to maxima in xdat
#' @param thetainit initial parameter for theta
#' @param link list of 5, link functions for parameters, created with \code{\link{make.link}}
#' @return list of initail values for mu_tilde, sigma_0, xi, eta
#' @importFrom stats lm
......@@ -300,7 +300,7 @@ gev.d.init <- function(xdat,ds,link){
#' computes negative log-likelihood of d-gev model
#'
#' @param xdat numeric vector containing observations
#' @param ds numeric vector containing coresponding durations
#' @param ds numeric vector containing coresponding durations (1/60 corresponds to 1 minute, 1 corresponds to 1 hour)
#' @param mut,sig0,xi,theta,eta numeric vectors containing corresponding mles for each of the parameters
#'
#' @return single value containing negative log likelihood
......
......@@ -30,7 +30,8 @@ gev.d.fit(
\item{xdat}{A vector containing maxima for different durations.
This can be obtained from \code{\link{IDF.agg}}.}
\item{ds}{A vector of aggregation levels corresponding to the maxima in xdat.}
\item{ds}{A vector of aggregation levels corresponding to the maxima in xdat.
1/60 corresponds to 1 minute, 1 corresponds to 1 hour.}
\item{ydat}{A matrix of covariates for generalized linear modelling of the parameters
(or NULL (the default) for stationary fitting). The number of rows should be the same as the
......
......@@ -12,8 +12,6 @@ gev.d.init(xdat, ds, link)
\item{ds}{vector of durations belonging to maxima in xdat}
\item{link}{list of 5, link functions for parameters, created with \code{\link{make.link}}}
\item{thetainit}{initial parameter for theta}
}
\value{
list of initail values for mu_tilde, sigma_0, xi, eta
......
......@@ -9,7 +9,7 @@ gev.d.nll(xdat, ds, mut, sig0, xi, theta, eta)
\arguments{
\item{xdat}{numeric vector containing observations}
\item{ds}{numeric vector containing coresponding durations}
\item{ds}{numeric vector containing coresponding durations (1/60 corresponds to 1 minute, 1 corresponds to 1 hour)}
\item{mut, sig0, xi, theta, eta}{numeric vectors containing corresponding mles for each of the parameters}
}
......
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