Options for parsing bootstrap replicates
I would like to plot confidence bands around seasonal trends. It looks like the only way to do this using the current functions in EGRETci is to run the bootAnnual reps for each season by changing paStart and paLong, but this means a separate bootstrap run for each season, which is inefficient. I would prefer a more flexible way of aggregating the Daily frame that each bootstrap rep produces under the hood. For example, I modified the bootAnnual code as follows:
bootSeasonal <- function(eList, blockLength = 200, startSeed = 494817,
verbose = FALSE, jitterOn = FALSE, V = 0.2){
Sample <- eList$Sample
Daily <- eList$Daily
INFO <- eList$INFO
if(is.null(INFO$edgeAdjust)){
INFO$edgeAdjust <- FALSE
}
paStart <- 10
paLong <- 12
if(!is.null(INFO$paLong)){
paLong <- INFO$paLong
}
if(!is.null(INFO$paStart)){
paStart <- INFO$paStart
}
bootSample <- blockSample(localSample = Sample, blockLength = blockLength, startSeed = startSeed)
if(jitterOn) bootSample <- jitterSam(bootSample, V = V)
eListBoot <- EGRET::as.egret(INFO,Daily,bootSample,NA)
if(isTRUE("runSeries" %in% names(attributes(eList)) && attr(eList, "runSeries"))){
#Indicates runSeries was run
seriesEList <- EGRET::runSeries(eList = eListBoot,
windowSide = INFO$windowSide,
surfaceStart = INFO$surfaceStart,
surfaceEnd = INFO$surfaceEnd,
flowBreak = INFO$flowBreak,
Q1EndDate = INFO$Q1EndDate,
QStartDate = INFO$QStartDate,
QEndDate = INFO$QEndDate,
wall = INFO$wall,
oldSurface = FALSE,
sample1EndDate = INFO$sample1EndDate,
sampleStartDate = INFO$sampleStartDate,
sampleEndDate = INFO$sampleEndDate,
paStart = INFO$paStart,
paLong = INFO$paLong,
minNumObs = INFO$minNumObs,
minNumUncen = INFO$minNumUncen,
windowY = INFO$windowY,
windowQ = INFO$windowQ,
windowS = INFO$windowS,
edgeAdjust = INFO$edgeAdjust,
verbose = verbose)
Daily1 <- seriesEList$Daily
} else {
surfaces1 <- EGRET::estSurfaces(eListBoot,
windowY = eList$INFO$windowY,
windowQ = eList$INFO$windowQ,
windowS = eList$INFO$windowS,
minNumObs = eList$INFO$minNumObs,
minNumUncen = eList$INFO$minNumUncen,
edgeAdjust = eListBoot$INFO$edgeAdjust,
verbose = verbose)
seriesEList <- EGRET::as.egret(INFO, Daily, bootSample, surfaces1)
Daily1 <- EGRET::estDailyFromSurfaces(seriesEList)
}
Daily1$season <- as.character(NA)
Daily1$season[Daily1$Month %in% c(12,1,2)] <- "winter"
Daily1$season[Daily1$Month %in% c(3,4,5)] <- "spring"
Daily1$season[Daily1$Month %in% c(6,7,8)] <- "summer"
Daily1$season[Daily1$Month %in% c(9,10,11)] <- "fall"
WYSeasonConc <- aggregate(list(FNConc = Daily1$FNConc),
by = list(waterYear = Daily1$waterYear, season = Daily1$season),
FUN = "mean")
WYSeasonFlux <- aggregate(list(FNFlux = Daily1$FNFlux),
by = list(waterYear = Daily1$waterYear, season = Daily1$season),
FUN = "sum")
seasonalResults <- merge(WYSeasonConc, WYSeasonFlux)
attr(seasonalResults, "blockLength") <- blockLength
return(seasonalResults)
}