ESTIMATION OF TIME-VARYING REGRESSION COEFFICIENTS

Francisco Parra

UNED Doctor Economy

December 15, 2013

parrafj@unican.es

franciscoparrod@gmail.com

http://econometria.wordpress.com/2013/07/29/estimacion-con-parametros-dependientes-del-tiempo/

Introduction

The time series can be seen from an aplitude-time domain or an amplitude-frequency domain. The amplitude-frecuency domain are used to analyze properties of filters used to decompose a time series into a trend, seasonal and irregular component investigating the gain function to examine the effect of a filter at a given frequency on the amplitude of a cycle for a particular time series. The ability to decompose data series into different frequencies for separate analysis and later recomposition is the first fundamental concept in the use of spectral techniques in forecasting, such as regression espectrum band, have had little development in econometric work. The low diffusion of this technique has been associated with the computing difficulties caused the need to work with complex numbers, and inverse Fourier transform in order to convert everything back into real terms. But the problems from the use of the complex Fourier transform may be circumvented by carrying out the Fourier transform of the data in real terms, pre-multiplied the time series by the orthogonal matrix Z whose elements are defined in Harvey (1978).

The spectral analysis commences with the assumption that any series can be transformed into a set of sine and cosine waves, and can be used to both identify and quantify apparently nonperiodic short and long cycle processes (first section). In Band spectrum regression (second section) , is a brief summary of the regression of the frequency domain (Engle, 1974) The application of spectral analysis to data containing both seasonal (high frequency) and non-seasonal (low frequency) components may produce adventages, since these different frequencies can be modelled separately and then may be re-combined to produce fitted values. Durbin (1967 and 1969) desing a technique for studying the general nature of the serial dependence in a satacionary time series, that can be use to statistic contraste in This type of exercises (third section). The time-varying regression, or the regression whit the vector of parameters time.varying can be understood in this context (four section). To explain this technique is used a regression analisys with the final energy consumption power (TEP) and the GDP in millions at constant euros in Spain for 1992 to 2007.

Spectral analysis

Nerlove (1964) and Granger (1969) were the two foremost researchers on the application of spectral techniques to economic time series.

The use of spectral analysis requires a change of focus from an amplitude-time domain to an amplitude-frequency domain. Thus spectral analysis commences with the assumption that any series, \( X_t \), can be transformed into a set of sine and cosine waves such as:

\[ \begin{equation} X_t=\eta+\sum_{j=1}^N[a_j\cos(2\pi\frac{ft}n)+b_j\sin(2\pi\frac{ft}n)] \end{equation} \]

where \( \eta \) is the mean of the series, \( a_j \) and \( b_j \) are the amplitude, f is the frequency over a span of n observations, t is a time index ranging from 1 to N where N is the number of periods for which we have observations, the fraction (ft/n) for different values of t converts the discrete time scale of time series into a proportion of 2 and j ranges from 1 to n where n= N/2. The highest observable frequency in the series is n/N (i.e., 0.5 cycles per time interval). High frequency dynamics (large f) are akin to short cycle processes while low frequency dynamics (small f) may be likened to long cycle processes. If we let \( \frac{ft}n=w \) then equation (1) can be rewritten more compactly as:

\[ \begin{equation} X_t=\eta+\sum_{j=1}^N[a_j\cos(\omega_j)+b_j\sin(\omega_j)] \end{equation} \]

Spectral analysis can be used to both identify and quantify apparently nonperiodic short and long cycle processes. A given series \( {X_t} \) may contain many cycles of different frequencies and amplitudes and such combinations of frequencies and amplitudes may yield cyclical patterns which appear non-periodic with irregular amplitude. In fact, in such a time series it is clear from equation (2) that each observation can be broken down into component parts of different length cycles which, when added together (along with an error term), comprise the observation (Wilson and Perry, 2004).

Band spectrum regression

Hannan (1963) first proposed regression analysis in the frequency domain,later examining the use of this technique in estimating distributed lag models (Hannan, 1965, 1967). Engle (1974) demonstrated that regression in the frequency domain has certain advantages over regression in the time domain. Consider the linear regression model \[ \begin{equation} y=X\beta+u \end{equation} \] where X is an n x k matrix of fixed observations on the independent variables, \( \beta \) is a k x I vector of parameters, y is an n x 1 vector of observations on the dependent variable, and u is an n x I vector of disturbance terms each with zero mean and constant variance, \( \sigma^2 \).

The model may be expressed in terms of frequencies by applying a finite Fourier transform to the dependent and independent variables.For Harvey (1978) there are a number of reasons for doing this. One is to permit the application of the technique known as 'band spectrum regression', in which regression is carried out in the frequency domain with certain wavelengths omitted. Another reason for interest in spectral regression is that if the disturbances in (3) are serially correlated, being generated by any stationary stochastic process, then regression in the frequency domain will yield an asymptotically efficient estimator of \( \beta \).

Engle (1974) compute the full spectrum regression with he complex finite Fourier transform based on the {n x n} matrix \( W \), in which element \( (t, s) \) is given by

\( w_{ts}=\frac{1}{\sqrt n} e^{i\lambda_t s} \) , \( s= 0,1,...,n-1 \)

where \( \lambda_t = 2\pi \frac {t}n \), t=0,1,…,n-1, and \( i=\sqrt{-1} \).

Pre-multiplying the observations in observations in (3) by \( W \) yields \[ \begin{equation} \dot y=\dot X\beta+\dot u \end{equation} \] where \( \dot y = Wy \),\( \dot X = WX \), and \( \dot u = Wu \).

If the disturbance vector in (4) obeys the classical assumptions, viz. \( E[u] = 0 \) and \( E[uu']=\sigma^2 I_n \). then the transformed disturbance vector, \( \dot u \), will have identical properties. This follows because the matrix W is unitary, i.e., \( WW^{T}= I \), where \( W^T \) is the transpose of the complex conjugate of W. Furthermore the observations in (4) contain precisely the same amount of information as the untransformed observations in (3).

Application of OLS to (4) yields, in view of the properties of \( \dot u \), the best linear unbiased estimator (BLUE) of \( \beta \). This estimator is identical to the OLS estimator in (3), a result which follows directly on taking account of the unitary property of \( W \). When the relationship implied by (4) is only assumed to hold for certain frequencies, band spectrum regression is appropriate, and this may be carried out by omitting the observations in (4) corresponding to the remaining frequencies. Since the variables in (4) are complex, however, Engle (1974) suggests an inverse Fourier transform in order to convert everything back into real terms (Harvey,1974).

The problems which arise from the use of the complex Fourier transform may be circumvented by carrying out the Fourier transform of the data in real terms. In order to do this the observations in (3) are pre-multiplied by the orthogonal matrix \( Z \) whose elements are defined as follows (Harvey,1978):

\[ \begin{equation} Z_{jt} = \left\lbrace \begin{array}{ll} \left(\frac{1}T\right) ^\frac{1}2 & \forall j=1\\ \left(\frac{2}T\right) ^\frac{1}2 \cos\left[\frac{\pi j(t-1)}T\right] & \forall j=2,4,6,..\frac{(T-2)}{(T-1)}\\ \left(\frac{2}T\right) ^\frac{1}2 \sin\left[\frac{\pi (j-1)(t-1)}T\right] & \forall j=3,5,7,..\frac{(T-2)}T\\ \left(\frac{1}T\right) ^\frac{1}2 (-1)^{t+1} & \forall j=T \end{array} \right. \end{equation} \]

The resulting frequency domain regression model is:

\[ \begin{equation} y^{**}=X^{**}\beta+v \end{equation} \] where \( y^{**}=Zy \),\( X^{**}=ZX \) and \( v=Zu \).

In view of the orthogonality of \( Z \), \( E[vv']=\sigma^2 I_n \) when \( E[uu']=\sigma^2 I_n \) and the application of OLS to (5) gives the BLUE of \( \beta \).

Since all the elements of \( y** \) and \( X** \) are real, model may be treated by a standard regression package. If band spectrum regression is to be carried out, the number of rows in \( y** \) and \( X** \) is reduced accordingly, and so no problems arise from the use of an inappropriate number of degrees of freedom.

Function gdf(a)

Transforms the data from the amplitude-time domain to the amplitude-frequency domain pre-multiplied by the orthogonal matrix \( Z \) (Harvey ,1978).

gdf <- function(a) {
    a <- matrix(a, nrow = 1)
    n <- length(a)
    uno <- as.numeric(1:n)
    A <- matrix(rep(sqrt(1/n), n), nrow = 1)
    for (i in 3:n - 1) {
        if (i%%2 == 0) {
            A1 <- matrix(sqrt(2/n) * cos(pi * i * (uno - 1)/n), nrow = 1)
            A <- rbind(A, A1)
        } else {
            A2 <- matrix(sqrt(2/n) * sin(pi * (i - 1) * (uno - 1)/n), nrow = 1)
            A <- rbind(A, A2)
        }
    }
    AN <- matrix(sqrt(1/n) * (-1)^(uno + 1), nrow = 1)
    A <- rbind(A, AN)
    A %*% t(a)
}

Function gdt(a)

Transforms the data from the amplitude-frequency domain to the amplitude-time domain ppre-multiplied by the transpose of \( Z \) (Harvey ,1978).

gdt <- function(a) {
    a <- matrix(a, nrow = 1)
    n <- length(a)
    uno <- as.numeric(1:n)
    A <- matrix(rep(sqrt(1/n), n), nrow = 1)
    for (i in 3:n - 1) {
        if (i%%2 == 0) {
            A1 <- matrix(sqrt(2/n) * cos(pi * i * (uno - 1)/n), nrow = 1)
            A <- rbind(A, A1)
        } else {
            A2 <- matrix(sqrt(2/n) * sin(pi * (i - 1) * (uno - 1)/n), nrow = 1)
            A <- rbind(A, A2)
        }
    }
    AN <- matrix(sqrt(1/n) * (-1)^(uno + 1), nrow = 1)
    A <- rbind(A, AN)
    t(A) %*% t(a)
}

Function rbs (a)

Band spectrum regression, “a” is the dependent variable, “b” is the independent variables, “d” the starting frequencies, and “c” the frequencies number for cosine or sine.

rbs <- function(a, b, c, d) {
    a <- matrix(a, nrow = 1)
    n <- length(a)
    A <- c(1, rep(0, c - 1), rep(1, d), rep(0, n - c - d))
    unos <- rep(1, n)
    lm1 <- lm(diag(A) %*% gdf(a) ~ 0 + diag(A) %*% gdf(b) + diag(A) %*% gdf(unos))
    summary(lm1)
}

Test based on residuals from frequency domain regresion

Durbin (1967 and 1969) desing a technique for studying the general nature of the serial dependence in a satacionary time series.

Suppose \( \hat \beta \) is an estimator of \( \beta \). The n x 1 vector of residuals is then defined by

\[ \hat u=y-X\hat \beta \]

Similarly the n x 1 vector of residuals in the transformed model, (7), is given by

\[ \hat v=y^{**}-X^{**}\hat \beta = Z(y-X\hat \beta) = Z \hat u \]

Id \( p_j \) denotes the ordinate of the periodogram de \( \hat u \) at frequency \( \lambda_j=2\pi j/n \), and \( \hat v_j \) denote the j-th element of \( \hat v \), then

\[ p_j=\hat v_{2j}^{2}+\hat v_{2j+1}^{2} \]

\( j = 1,...\frac{n}{2}-1 \) to n even, and $ j = 1,…\frac{n-1}{2}$to n odd,

\[ p_j=\hat v_{2j}^{2} \]

\( j = \frac{n}{2}-1 \) n even

\[ p_0=\hat v_{1}^{2} \]

Thus the squares of the elements in \( \hat v \) may be used to form a consistent estimator of the power spectrum of \( \hat u \) by a suitable averaging process. Furthermore, if \( \hat \beta \) is a consistent estimator of \( \beta \), then this will also be a consistent estimator of the power spectrum of the true disturbances in the model (Harvey, 1974).

As regards test statistics, if \( \hat \beta \) is the OLS estimator of \( \beta \) then the elements of \( {\hat v} \) may be used directly in Durbin's cumulative periodogram test. This test is based on the quantities

\[ s_j=\frac{\sum_{r=1} ^j p_r}{\sum_{r=1}^m p_r} \]

where \( m=\frac{1}{2}n \) for n even and \( \frac{1}{2}(n-1) \) for n odd.The procedure is a bounds test and upper and lower critical values may be constructed using the tables provided in Durbin (1969). Note that po does not enter into the test statistic as \( p_o \) does not enter in to test statitstic as \( p_o=\hat v_1=0 \).

Alt tect

Function periodograma (a)

Calculates and displays the spectrum of the variable “a”

periodograma <- function(a) {
    cf <- gdf(a)
    n <- length(a)
    if (n%%2 == 0) {
        m1 <- c(0)
        m2 <- c()
        for (i in 1:n) {
            if (i%%2 == 0) 
                m1 <- c(m1, cf[i]) else m2 <- c(m2, cf[i])
        }
        m2 <- c(m2, 0)
        frecuencia <- seq(0:(n/2))
        frecuencia <- frecuencia - 1
        omega <- pi * frecuencia/(n/2)
        periodos <- n/frecuencia
        densidad <- (m1^2 + m2^2)/(4 * pi)
        tabla <- data.frame(omega, frecuencia, periodos, densidad)
        tabla$densidad[(n/2 + 1)] <- 2 * tabla$densidad[(n/2 + 1)]
        data.frame(tabla[2:(n/2 + 1), ])
    } else {
        m1 <- c(0)
        m2 <- c()
        for (i in 1:(n - 1)) {
            if (i%%2 == 0) 
                m1 <- c(m1, cf[i]) else m2 <- c(m2, cf[i])
        }
        m2 <- c(m2, cf[n])
        frecuencia <- seq(0:((n - 1)/2))
        frecuencia <- frecuencia - 1
        omega <- pi * frecuencia/(n/2)
        periodos <- n/frecuencia
        densidad <- (m1^2 + m2^2)/(4 * pi)
        tabla <- data.frame(omega, frecuencia, periodos, densidad)
        data.frame(tabla[2:((n + 1)/2), ])
    }
}

Function gperiodogrma (a)

Plot to the spectrum of a variable “a”

gperiodograma <- function(a) {
    tabla <- periodograma(a)
    plot(tabla$frecuencia, tabla$densidad, main = "Espectro", ylab = "densidad", 
        xlab = "frecuencia", type = "l", col = "#ff0000")
}

Fuction td (a,b)

Calculates and shows the results of testing Durbin (Durbin, 1969), applied to the variable “a” and the significance level “b”

td <- function(a, b) {
    per <- periodograma(a)
    p <- as.numeric(per$densidad)
    n <- length(p)
    s <- p[1]
    t <- 1:n
    for (i in 2:n) {
        s1 <- p[i] + s[(i - 1)]
        s <- c(s, s1)
        s2 <- s/s[n]
    }
    while (n > 75) n <- 75
    if (b == 1) 
        c <- Test[n, 1] else {
        if (b == 2) 
            c <- Test[n, 2] else {
            if (b == 2) 
                c <- Test[n, 3] else c <- Test[n, 4]
        }
    }
    min <- -c + (t/length(p))
    max <- c + (t/length(p))
    data.frame(s2, min, max)
}

Fuction gtd (a,b)

Plot to the Durbin test (Durbin, 1969), applied to the variable “a” and the significance level “b”

gtd <- function(a, b) {
    S <- td(a, b)
    plot(ts(S), plot.type = "single", xlab = "frecuencia", lty = 1:3)
}

Alternatively you can use the cpgram function from MASS package (src/library/stats/R/cpgram.R)

cpgram <- function(ts, taper = 0.1, main = paste("Series: ", deparse(substitute(ts))), 
    ci.col = "blue") {
    main
    if (NCOL(ts) > 1) 
        stop("only implemented for univariate time series")
    x <- as.vector(ts)
    x <- x[!is.na(x)]
    x <- spec.taper(scale(x, TRUE, FALSE), p = taper)
    y <- Mod(fft(x))^2/length(x)
    y[1L] <- 0
    n <- length(x)
    x <- (0:(n/2)) * frequency(ts)/n
    if (length(x)%%2 == 0) {
        n <- length(x) - 1
        y <- y[1L:n]
        x <- x[1L:n]
    } else y <- y[seq_along(x)]
    xm <- frequency(ts)/2
    mp <- length(x) - 1
    crit <- 1.358/(sqrt(mp) + 0.12 + 0.11/sqrt(mp))
    oldpty <- par(pty = "s")
    on.exit(par(oldpty))
    plot(x, cumsum(y)/sum(y), type = "s", xlim = c(0, xm), ylim = c(0, 1), xaxs = "i", 
        yaxs = "i", xlab = "frequency", ylab = "")
    lines(c(0, xm * (1 - crit)), c(crit, 1), col = ci.col, lty = 2)
    lines(c(xm * crit, xm), c(0, 1 - crit), col = ci.col, lty = 2)
    title(main = main)
    invisible()
}

Time-varying regression

Consider now the linear regression model

\[ \begin{equation} y_t=\beta_tx_t+u_t \end{equation} \]

where \( x_t \) is an n x 1 vector of fixed observations on the independent variable, \( \beta_t \) is a n x 1 vector of parameters,\( y \) is an n x 1 vector of observations on the dependent variable, and \( u_t \) is an n x 1 vector de errores distribuidos con media cero y varianza constante.

Whit the assumption that any series, \( y_t \),\( x_t \),\( \beta_t \) and \( ut \), can be transformed into a set of sine and cosine waves such as:

\[ y_t=\eta^y+\sum_{j=1}^N[a^y_j\cos(\omega_j)+b^y_j\sin(\omega_j) \]

\[ x_t=\eta^x+\sum_{j=1}^N[a^y_j\cos(\omega_j)+b^y_j\sin(\omega_j)] \]

\[ \beta_t=\eta^\beta+\sum_{j=1}^N[a^\beta_j\cos(\omega_j)+b^\beta_j\sin(\omega_j)] \]

Pre-multiplying (6) by \( Z \):

\[ \dot y=\dot x\dot\beta+\dot u \]

donde \( \dot y = Zy \),$ \dot x = Zx$, $ \dot \beta = Z\beta$ y $ \dot u = Zu$

The system (8) can be rewritten as (see appendix):

\[ \dot y=Zx_tI_nZ^T\dot \beta + ZI_nZ^T\dot u \]

If we call \( \dot e = ZI_nZ ^ T \dot u \), It can be found the \( \dot \beta \) that minimize the sum of squared errors \( E_T = Z ^ T \dot e \).

Once you have found the solution to this optimization, the series would be transformed into the time domain for the system (8).

Function cdf(a)

Gets the auxiliary matrix vector operations in time domain and frequency domain, pre-multiplies a vector by the orthogonal matrix Z and its transpose, Parra F. (2013)

cdf <- function(a) {
    a <- matrix(a, nrow = 1)
    n <- length(a)
    uno <- as.numeric(1:n)
    A <- matrix(rep(sqrt(1/n), n), nrow = 1)
    for (i in 3:n - 1) {
        if (i%%2 == 0) {
            A1 <- matrix(sqrt(2/n) * cos(pi * i * (uno - 1)/n), nrow = 1)
            A <- rbind(A, A1)
        } else {
            A2 <- matrix(sqrt(2/n) * sin(pi * (i - 1) * (uno - 1)/n), nrow = 1)
            A <- rbind(A, A2)
        }
    }
    AN <- matrix(sqrt(1/n) * (-1)^(uno + 1), nrow = 1)
    A <- rbind(A, AN)
    I <- diag(c(a))
    B <- A %*% I
    B %*% t(A)
}

Function rtd(a)

Time-varying regression , “a” is the dependent variable, “b” is the independent variables,and “d” the frequencies number for cosine or sine.

rdt <- function(a, b, d) {
    a <- matrix(a, nrow = 1)
    b <- matrix(b, nrow = 1)
    n <- length(a)
    f <- function(x) {
        for (i in 1:d) x[i]
        A <- c(x[1:d], rep(0, n - d))
        B <- c(x[d + 1], rep(0, n - 1))
        unos <- c(rep(1, n))
        colSums((gdf(a) - cdf(b) %*% t(t(A)) - cdf(unos) %*% t(t(B)))^2)
    }
    xmin <- optim(c(rep(1, d + 1)), f, NULL, method = "BFGS")
    A <- c(xmin$par[1:d], rep(0, n - d))
    B <- c(xmin$par[d + 1], rep(0, n - 1))
    unos <- c(rep(1, n))
    fitted <- cdf(b) %*% t(t(A)) + cdf(unos) %*% t(t(B))
    plot(b, a, pch = 19, col = "blue")
    points(b, gdt(fitted), pch = 19, col = "red")
    print(xmin)
    fitted <- gdt(fitted)
    betas <- gdt(A)
    alfha <- gdt(B)
    ta <- t(a)
    error <- ta - fitted
    ajuste <- 1 - colSums(error^2)/colSums(ta^2)
    resultados <- data.frame(fitted, betas, alfha)
    print(resultados)
    print(ajuste)
    plot(b, error, pch = 19, col = "blue")
    gtd(error, 2)
    cpgram(error, 0)
}

A solution to the above optimization can be obtained using ordinary least squares, based on the \( X \) matrix of explanatory variables whose first column would be the vector of size \( T \) \( (1,0,0,...) \), the second column would be the first row of the \( \Theta^{\dot x\dot x} \) matrix, and the following columns, are the rows \( \Theta^{\dot x\dot x} \) corresponding to the frequencies of sinus and cosines we want to use.

The coefficients of the OLS solution: \[ \dot \beta = (X'X)^{-1}X'\dot y \] are: \( \dot \beta_0 \) the associated constant, \( \dot \beta_1 \) the slope associated, \( \dot \beta_2 ... \) the frequencies associated with sines and cosines.

Función rdtmco (a,b,d,c)

OLS estimation of time-dependent regression of the series “a” and “b” for frequencies starting with “c” and ending with “d”.

rdtmco <- function(a, b, c, d) {
    a <- matrix(a, nrow = 1)
    b <- matrix(b, nrow = 1)
    n <- length(a)
    unos <- c(rep(1, n))
    X1 <- c(1, rep(0, n - 1))
    XT <- cdf(b)
    X2 <- XT[1, ]
    X3 <- XT[c:d, ]
    X <- rbind(X1, X2, X3)
    y <- gdf(a)
    B <- solve(X %*% t(X)) %*% (X %*% y)
    Y <- t(X) %*% B
    fitted <- gdt(Y)
    plot(b, a, pch = 19, col = "blue")
    points(b, fitted, pch = 19, col = "red")
    error <- t(a) - fitted
    alfa <- gdt(c(B[1, ], rep(0, n - 1)))
    beta <- gdt(c(B[2, ], rep(0, c - 2), B[(c + 1):(d + 1), ], rep(0, n - d)))
    resultados <- data.frame(fitted, y, alfa, beta)
    print(resultados)
    plot(b, error, pch = 19, col = "blue")
    gtd(error, 2)
    cpgram(error, 0)
}

Example: Regression band spectrum between the final energy consumption power (TEP) and the GDP in millions at constant euros in Spain

The Table 1 shows the final energy consumption power (TEP) and the GDP in millions at constant euros in Spain for 1992 to 2007.

Table 1 Series in time domain

Year Final Energy Consumption Power (TEP) (\( y \)) GDP (Meuros). Base year: 2000 (\( x \))
1993 11237 479583,3
1994 11777 491011,6
1995 12116 515405
1996 12655 527862,4
1997 13672 548283,8
1998 14202 572782
1999 15241 599965,8
2000 16205 630263
2001 17279 653255
2002 17759 670920,4
2003 18916 691694,7
2004 19834 714291,2
2005 20827 740108
2006 22052 769850,2
2007 22548 797366,8
2008 22817 804223,1

EUROSTAT

Test de Durbin(1969) :

Test <- read.csv("http://dl.dropbox.com/s/cvy9mgy5tfp5nyh/TD.csv", header = TRUE, 
    sep = ";", dec = ",")
datos <- read.csv("http://dl.dropbox.com/s/cfhfjelj1r2rpue/energia.csv", header = TRUE, 
    sep = ";", dec = ",")
celec <- datos$Y
PIB <- datos$X

Spectral Analysis of GDP

periodograma(PIB)
##    omega frecuencia periodos  densidad
## 2 0.3927          1   16.000 9.153e+09
## 3 0.7854          2    8.000 2.266e+09
## 4 1.1781          3    5.333 1.035e+09
## 5 1.5708          4    4.000 6.284e+08
## 6 1.9635          5    3.200 4.254e+08
## 7 2.3562          6    2.667 3.206e+08
## 8 2.7489          7    2.286 2.575e+08
## 9 3.1416          8    2.000 2.406e+08
plot(ts(PIB), plot.type = "single", lty = 1:3)

plot of chunk unnamed-chunk-13

gperiodograma(PIB)

plot of chunk unnamed-chunk-13

gtd(PIB, 3)

plot of chunk unnamed-chunk-13

cpgram(PIB, 0)

plot of chunk unnamed-chunk-13

Spectral Analysis of Energy Consumption Power (TEP)

periodograma(celec)
##    omega frecuencia periodos densidad
## 2 0.3927          1   16.000 13006872
## 3 0.7854          2    8.000  2958837
## 4 1.1781          3    5.333  1210786
## 5 1.5708          4    4.000   660886
## 6 1.9635          5    3.200   454065
## 7 2.3562          6    2.667   408582
## 8 2.7489          7    2.286   447815
## 9 3.1416          8    2.000   297085
plot(ts(celec), plot.type = "single", lty = 1:3)

plot of chunk unnamed-chunk-14

gperiodograma(celec)

plot of chunk unnamed-chunk-14

gtd(celec, 3)

plot of chunk unnamed-chunk-14

cpgram(celec, 0)

plot of chunk unnamed-chunk-14

OLS Regresión between the final energy consumption power (TEP) and the GDP in millions at constant euros in Spain

lm1 <- lm(celec ~ PIB)
plot(PIB, celec, pch = 19, col = "blue")
lines(PIB, lm1$fitted, lwd = 3, col = "red")

plot of chunk unnamed-chunk-15

summary(lm1)
## 
## Call:
## lm(formula = celec ~ PIB)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##   -334   -187   -111    213    378 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -6.65e+03   3.74e+02   -17.8  5.4e-11 ***
## PIB          3.68e-02   5.79e-04    63.5  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 245 on 14 degrees of freedom
## Multiple R-squared:  0.997,  Adjusted R-squared:  0.996 
## F-statistic: 4.04e+03 on 1 and 14 DF,  p-value: <2e-16
plot(lm1$residuals, celec, pch = 19, col = "blue")

plot of chunk unnamed-chunk-15

gperiodograma(lm1$residuals)

plot of chunk unnamed-chunk-15

gtd(lm1$residuals, 3)

plot of chunk unnamed-chunk-15

cpgram(lm1$residuals, 0)

plot of chunk unnamed-chunk-15

OLS Regresión between the final energy consumption power (amplitude-frequency domain) and the GDP in millions at constant euros in Spain (amplitude-frequency domain)

unos <- rep(1, 16)
lm2 <- lm(gdf(celec) ~ 0 + gdf(PIB) + gdf(unos))
summary(lm2)
## 
## Call:
## lm(formula = gdf(celec) ~ 0 + gdf(PIB) + gdf(unos))
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -367.2  -29.7  115.6  214.2  370.5 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## gdf(PIB)   3.68e-02   5.79e-04    63.5  < 2e-16 ***
## gdf(unos) -6.65e+03   3.74e+02   -17.8  5.4e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 245 on 14 degrees of freedom
## Multiple R-squared:     1,   Adjusted R-squared:     1 
## F-statistic: 3.98e+04 on 2 and 14 DF,  p-value: <2e-16

Regresión band spectrum between the final energy consumption power and the GDP in millions at constant euros in Spain to frequency of 16 and 8 period.

rbs(celec, PIB, 1, 4)
## 
## Call:
## lm(formula = diag(A) %*% gdf(a) ~ 0 + diag(A) %*% gdf(b) + diag(A) %*% 
##     gdf(unos))
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##   -216      0      0      0    403 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## diag(A) %*% gdf(b)     3.74e-02   4.03e-04    92.6  < 2e-16 ***
## diag(A) %*% gdf(unos) -7.01e+03   2.60e+02   -26.9  1.8e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 153 on 14 degrees of freedom
## Multiple R-squared:     1,   Adjusted R-squared:     1 
## F-statistic: 1.01e+05 on 2 and 14 DF,  p-value: <2e-16
A <- c(rep(1, 5), rep(0, 11))
unos <- rep(1, 16)
lm5 <- lm(gdf(celec) ~ 0 + cdf(unos) %*% gdf(PIB) + gdf(unos))
plot(PIB, celec, pch = 19, col = "blue")
lines(PIB, gdt(lm5$fitted), lwd = 3, col = "red")

plot of chunk unnamed-chunk-18

summary(lm5)
## 
## Call:
## lm(formula = gdf(celec) ~ 0 + cdf(unos) %*% gdf(PIB) + gdf(unos))
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -367.2  -29.7  115.6  214.2  370.5 
## 
## Coefficients:
##                         Estimate Std. Error t value Pr(>|t|)    
## cdf(unos) %*% gdf(PIB)  3.68e-02   5.79e-04    63.5  < 2e-16 ***
## gdf(unos)              -6.65e+03   3.74e+02   -17.8  5.4e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 245 on 14 degrees of freedom
## Multiple R-squared:     1,   Adjusted R-squared:     1 
## F-statistic: 3.98e+04 on 2 and 14 DF,  p-value: <2e-16

Time-varying regression between the final energy consumption power and the GDP in millions at constant euros in Spain to frequency of 16 and 8 period.

rdt(celec, PIB, 5)

plot of chunk unnamed-chunk-19

## $par
## [1]  1.377e-01  2.540e-04 -1.743e-03 -4.620e-04 -2.305e-04 -2.072e+04
## 
## $value
## [1] 276584
## 
## $counts
## function gradient 
##      117       14 
## 
## $convergence
## [1] 0
## 
## $message
## NULL
## 
##    fitted   betas alfha
## 1   11295 0.03435 -5180
## 2   11564 0.03410 -5180
## 3   12330 0.03397 -5180
## 4   12741 0.03395 -5180
## 5   13447 0.03397 -5180
## 6   14292 0.03400 -5180
## 7   15224 0.03401 -5180
## 8   16280 0.03405 -5180
## 9   17144 0.03417 -5180
## 10  17904 0.03441 -5180
## 11  18834 0.03472 -5180
## 12  19834 0.03502 -5180
## 13  20877 0.03521 -5180
## 14  21922 0.03520 -5180
## 15  22734 0.03501 -5180
## 16  22717 0.03469 -5180
## [1] 0.9999

plot of chunk unnamed-chunk-19 plot of chunk unnamed-chunk-19 plot of chunk unnamed-chunk-19

rdtmco(celec, PIB, 2, 5)

plot of chunk unnamed-chunk-19

##    fitted        y  alfa    beta
## 1   11295  67284.2 -5180 0.03435
## 2   11564  -1712.9 -5180 0.03410
## 3   12330 -12669.5 -5180 0.03397
## 4   12741  -2161.6 -5180 0.03395
## 5   13447  -5701.7 -5180 0.03397
## 6   14292  -2396.9 -5180 0.03400
## 7   15224  -3077.4 -5180 0.03401
## 8   16280  -2052.7 -5180 0.03405
## 9   17144  -2022.7 -5180 0.03417
## 10  17904  -2129.0 -5180 0.03441
## 11  18834  -1083.2 -5180 0.03472
## 12  19834  -2069.1 -5180 0.03502
## 13  20877   -923.8 -5180 0.03521
## 14  21922  -2306.0 -5180 0.03520
## 15  22734   -556.6 -5180 0.03501
## 16  22717  -1366.2 -5180 0.03469

plot of chunk unnamed-chunk-19 plot of chunk unnamed-chunk-19 plot of chunk unnamed-chunk-19

Bibliography

Engle, Robert F. (1974), “Band Spectrum Regression”, International Economic Review 15,1-11.

Hannan, E.J. (1963), “Regression for Time Series”, in Rosenblatt, M. (ed.), Time Series Analysis, New York, John Wiley.

Harvey, A.C. (1978), “Linear Regression in the Frequency Domain”, International Economic Review, 19, 507-512.

Wilson, P.J. and Perry, L.J. (2004). “Forecasting Australian Unemployment Rates Using Spectral Analysis” Australian Jurnal of Labour Economics, vol 7,no 4, December 2004, pp 459-480.

Parra, F.(2013). “Regresión con parámetros dependientes del tiempo”:http://econometria.wordpress.com/2013/07/29/estimacion-con-parametros-dependientes-del-tiempo/