I have trouble running a bootstrapping method to estimate p-value in a periodogram of my timeseries (myts) from spec.pgram():
# Defining a function for computing the periodogram of a time series
periodogram_fun <- function(x, ind) {
spec.pgram(ts(x[ind], start=1, end=365), plot=FALSE)$spec
}
# Using the "boot" function to create a set of bootstrapped periodograms
bootstrapped_periodograms <- boot(myts, periodogram_fun, R=1000)
# Calculating a p-value based on the comparison of the observed periodogram
# to the distribution of bootstrapped periodograms
pvalue <- sum(spec.pgram(myts)$spec > quantile(bootstrapped_periodograms$t[,2], probs=0.95)) / 1000
If anyone has an idea about how to calculate p-value from timeseries in a periodogram I would thank so much.