user2338823
user2338823

Reputation: 543

How to run a complex regression in R (for instance for frequency domain detrending)?

I am trying to detrend in a frequency domain.

Here is the paper that I am following: Paper. Here is the paper which talks about detrending a frequency domain: Second-Paper.

My reprex:

library(quantmod)
getSymbols.FRED("GDPC1",env=.GlobalEnv)
# dim(GDPC1)
index(GDPC1) = as.yearqtr(index(GDPC1))
GDPC2 = ts(GDPC1,frequency = length(GDPC1))
time.trend = ts(1:310/310, frequency = 310)
N = 310
mytheta  = exp(-2i*pi/N)
W = outer(0:(N-1), 0:(N-1), function(i, j) mytheta^(i*j)) / sqrt(N)

lm( W %*% GDPC2 ~  W %*% time.trend)

which fails with

Error in model.matrix.default(mt, mf, contrasts) : complex variables are not currently allowed in model matrices In addition: Warning message: In storage.mode(v) <- "double" : imaginary parts discarded in coercion

How to run a regression with complex numbers in R?

Upvotes: 2

Views: 68

Answers (0)

Related Questions