bootstrap_month: Implements a monthly bootstrap

View source: R/bootstrap_month.R

bootstrap_monthR Documentation

Implements a monthly bootstrap

Description

Months in which at least one variable exceeds the user-specified minimum proportion of non-missing values are sampled with replacement. February of leap years are treated as a 13th month.

Usage

bootstrap_month(data, boot_prop = 0.8)

Arguments

data

Data frame of raw data detrended if necessary. First column should be of the Date.

block_prop

Numeric vector of length one specifying the minimum proportion of non-missing values of at least one of the variables for a month to be included in the bootstrap. Default is 0.8.

Value

Dataframe containing a bootstrap undertaken with replacement that accounts for monthly-scale seasonality.

Examples

#Let's assess the sampling variability in kendall's tau
#correlation coefficient between rainfall and OsWL at S-22.

#Data starts on first day of 1948
head(S22.Detrend.Declustered.df)

#Dataframe ends on 1948-02-03 
tail(S22.Detrend.Declustered.df)

#Adding dates to complete final month of combined records
final.month = data.frame(seq(as.Date("2019-02-04"),as.Date("2019-02-28"),by="day"),NA,NA,NA)
colnames(final.month) = c("Date","Rainfall","OsWL","Groundwater")
S22.Detrend.Declustered.df = rbind(S22.Detrend.Declustered.df,final.month)

#Generate 100 monthly bootstrap samples of rainfall and OsWL
cor = rep(NA,100)
for(i in 1:100){
 boot_df = bootstrap_month(S22.Detrend.df[,c(1:3)], boot_prop=0.8)
 boot_df = na.omit(boot_df)
 cor[i] = cor(boot_df$Rainfall, boot_df$OsWL, method="kendall")
}

#Compare means of bootstrap samples with the mean of the observed data 
hist(cor)
df = na.omit(S22.Detrend.df[,1:3])
abline(v=cor(df$Rainfall,df$OsWL, method="kendall"),col=2,lwd=2)

rjaneUCF/MultiHazard documentation built on March 29, 2025, 3:22 p.m.