Skip to contents

Remove irrelevant frequencies

Usage

dftse(x, low_freq = NULL, high_freq = NULL)

Arguments

x

Vector, data.frame, matrix or any similar 1D/2D object containing values for filtering.

low_freq

Number indicating the lowest period of oscillation as fractions of \(\pi\). If low_freq > 1, indicating that the direct frequency of the data is provided, this is transformed internally into 2 / high_freq. The default is NULL, meaning that the ifelse(freq > 1, trunc(freq * 1.5), 2) will be used.

high_freq

Number indicating the highest period of oscillation as radians of \(\pi\). If high_freq > 1, indicating that the direct frequency of the data is provided, this is transformed internally into 2 / low_freq. The default is NULL, meaning that the trunc(freq * 8) will be used.

Details

This is a pure R implementation of removing the irrelevant frequencies. First, DFT is applied on the data and this result is filtered according to low_freq and high_freq. Finally, an inverse DFT is performed on these relevant frequencies. Both low_freq and high_freq must be either between 0 and 1, meaning that they are frequencies of the period as radians, or both >1, indicating that both are starting and ending periods of the cycle.

low_freq and high_freq are used for keeping the relevant frequencies. These are meant to be the ones inside the range \([ low \_ freq, high \_ freq ]\). Therefore, values outside this range are removed.

For 2-dimensional objects x, this transformation is applied per column.

Value

Filtered object with length/dimensions same with the input x. Note that for inputs with dimensions (e.g. matrix, data.frame) a matrix object will be returned.

References

Corbae, D., Ouliaris, S., & Phillips, P. (2002), Band Spectral Regression with Trending-Data. Econometrica 70(3), pp. 1067-1109.

Corbae, D. & Ouliaris, S. (2006), Extracting Cycles from Nonstationary Data, in Corbae D., Durlauf S.N., & Hansen B.E. (eds.). Econometric Theory and Practice: Frontiers of Analysis and Applied Research. Cambridge: Cambridge University Press, pp. 167–177. doi:10.1017/CBO9781139164863.008 .

Shaw, E.S. (1947), Burns and Mitchell on Business Cycles. Journal of Political Economy, 55(4): pp. 281-298. doi:10.1086/256533 .

See also

Examples

# Apply on ts object
data(USgdp)
res <- dftse(USgdp, low_freq = 0.0625, high_freq = 0.3333)
head(res)
#> [1] -2261.247 -6330.034 -7993.036 -7150.108 -4947.435 -2890.135

# Apply on vector
res <- dftse(c(USgdp), low_freq = 0.0625, high_freq = 0.3333)
head(res)
#> [1] -2261.247 -6330.034 -7993.036 -7150.108 -4947.435 -2890.135

# Apply on matrix per column
mat <- matrix(USgdp, ncol = 4)
res <- dftse(mat, low_freq = 0.0625, high_freq = 0.3333)
head(res)
#>           [,1]       [,2]      [,3]       [,4]
#> [1,] -192.2898  -552.4067 -1069.575  -919.8675
#> [2,] -711.1214 -1211.6718 -2525.133 -2489.2995
#> [3,] -970.8496 -1498.3225 -3172.692 -3294.7414
#> [4,] -943.4586 -1390.1547 -2993.074 -3243.3326
#> [5,] -738.1949 -1056.4415 -2343.065 -2642.7021
#> [6,] -521.5195  -732.0659 -1695.942 -1966.0607

# Apply on data.frame per column
dfmat <- as.data.frame(mat)
res <- dftse(dfmat, low_freq = 0.0625, high_freq = 0.3333)
head(res)
#>           [,1]       [,2]      [,3]       [,4]
#> [1,] -192.2898  -552.4067 -1069.575  -919.8675
#> [2,] -711.1214 -1211.6718 -2525.133 -2489.2995
#> [3,] -970.8496 -1498.3225 -3172.692 -3294.7414
#> [4,] -943.4586 -1390.1547 -2993.074 -3243.3326
#> [5,] -738.1949 -1056.4415 -2343.065 -2642.7021
#> [6,] -521.5195  -732.0659 -1695.942 -1966.0607