library(PaleoSpec)
library(ggplot2)
6 Variance from a power spectrum
The integral of the full power spectrum is equal to the variance of the whole time series. We can calculate this by summing the spectral estimates and multiplying by delta_f.
set.seed(20240228)
<- 1e03
N = 1
delta_t
<- ts(rnorm(N), deltat = delta_t) * 5
ts1 <- SpecMTM(ts1, detrend = TRUE) sp1
gg_spec(sp1) +
scale_x_continuous()
Scale for colour is already present.
Adding another scale for colour, which will replace the existing scale.
Scale for x is already present.
Adding another scale for x, which will replace the existing scale.
Note that SpecMTM returns only the positive frequencies, therefore to get the total variance we must multiply by a factor of 2.
var(ts1)
[1] 25.29412
2 * sum(sp1$spec) * diff(sp1$freq)[1]
[1] 25.67279
Why are these not identical?
6.1 Variance by timescale
As we simulated a “white” time series, the total variance of the time series is spread equally across all frequencies. Therefore the integrals of the lower and upper halves of the power spectrum are expected to be equal to each other and sum to the variance of the whole time series.
PaleoSpec has a function GetVarFromSpectra()
which we will use to integrate sections of the power spectrum
<- c(1/N, 1/2)
f_range <- c(1/N, mean(f_range))
f_range_low <- c(mean(f_range), 1/2)
f_range_high
::GetVarFromSpectra(sp1, f_range) PaleoSpec
$var
[1] 25.63878
$dof
[1] 959.4585
::GetVarFromSpectra(sp1, f_range_low) PaleoSpec
$var
[1] 12.97496
$dof
[1] 481.1547
::GetVarFromSpectra(sp1, f_range_high) PaleoSpec
$var
[1] 12.66096
$dof
[1] 478.2898
::GetVarFromSpectra(sp1, f_range_low)$var +
PaleoSpec::GetVarFromSpectra(sp1, f_range_high)$var PaleoSpec
[1] 25.63592
In contrast, if we simulated a time series where the variance increases with timescale, integrating different parts of its power spectrum will yield different variances.
<- ts(PaleoSpec::SimPLS(N, beta = 1, alpha = 0.1))
ts2 plot(ts2)
<- SpecMTM(ts2)
sp2
gg_spec(sp2) +
scale_x_continuous()+
geom_vline(xintercept = mean(f_range), colour = "red")
Scale for colour is already present.
Adding another scale for colour, which will replace the existing scale.
Scale for x is already present.
Adding another scale for x, which will replace the existing scale.
<- PaleoSpec::GetVarFromSpectra(sp2, f_range_low)
var_low_2 <- PaleoSpec::GetVarFromSpectra(sp2, f_range_high)
var_high_2
var_low_2
$var
[1] 0.9412515
$dof
[1] 473.2349
var_high_2
$var
[1] 0.1324684
$dof
[1] 435.3166
The sum of the two variances calculated by integrating the two halves of the power spectrum should still be equal to the total variance of the time series.
$var + var_high_2$var var_low_2
[1] 1.07372
var(ts2)
[1] 1.24744
When a time series has increasing power at lower frequencies, the variance estimated from the power spectrum will be lower than the true variance, because the detrending of the time series prior to estimating the power spectrum removes power from the lowest frequencies. See Section 3.3 .