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