Package 'descomponer'

Title: Seasonal Adjustment by Frequency Analysis
Description: Decompose a time series into seasonal, trend and irregular components using transformations to amplitude-frequency domain.
Authors: Francisco Parra <[email protected]>
Maintainer: Francisco Parra <[email protected]>
License: GPL (>= 2)
Version: 1.6
Built: 2024-10-29 05:46:50 UTC
Source: https://github.com/cran/descomponer

Help Index


Get Auxiliary Matrix

Description

Gets the auxiliary matrix to vector in time domain, pre-multiplies the vector by the orthogonal matrix,W, and its transpose, Parra F. (2013)

Usage

cdf(y)

Arguments

y

a vector of the observed time-serie values

Value

a matrix of sine and cosine waves adjusted to time-serie

Author(s)

Francisco Parra

References

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

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

Examples

n<-100;x<-seq(0,24*pi,length=n);y<-sin(x)+rnorm(n,sd=.3)
cdf(y)

Consumption of electricity in Spain

Description

A vector: celec, Miles de Tep, 1995 a 2013

Usage

data(celec)

Source

Instituto Nacional de Estadistica Spain


Time series decomposition

Description

Decompose a time series into seasonal, trend and irregular components using the transform amplitude-frequency domain to time series.

Usage

descomponer(y,frequency,type)

Arguments

y

a Vector of the observed time-serie values

frequency

Number of times in each unit time interval

type

lineal (1), quadratic(2)

Details

One could use a value of 7 for frequency when the data are sampled daily, and the natural time period is a week, or 4 and 12 when the data are sampled quarterly and monthly and the natural time period is a year.

Transforms the time series in amplitude-frequency domain, by a band spectrum regresion (Parra, F. ,2013) of the serie y_t and a OLS lineal trend, in which regression is carried out in the low and the sesaonal amplitude-frequency_t .The low frequency are the periodicity a n/2*frequency or (n-1)/2*frequency , if n is odd. The seasonal frequency are the periodicity: 2n/2*frequency,3n/2*frequency,4n/2*frequency,.. .

Use the "sort.data.frame" function, Kevin Wright (http://tolstoy.newcastle.edu.au/R/help/04/07/1076.html).

Slow computer in time series higher 1000 data.

The output is a data.frame object.

Value

y

The Vector of the observed time-serievalues

TDST

The trend and seasonal time serie of y

TD

The trend time serie of y

ST

The seasonal time serie of y

IR

The remainder time serie of y

regresoresTD

The regressors matrix use to the trend estimated

regresoresST

The regressors matrix use to the seasonal estimated

coeficientesTD

The coefficient vector use to the trend estimated

coeficientesSD

The coefficient vector use to the seasonal estimated

References

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

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

Examples

data(ipi)
datos <- descomponer(ipi,12,2)
plot(ts(datos$datos,frequency=12))

Prediction whit Regression in domain frequency

Description

Make a prediction for a rdf object

Usage

estimardf(a,b)

Arguments

a

a model rdf

b

An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used.

Details

Use predict.lm, with interval="prediction"

Slow computer in time series higher 1000 data.

Value

fit

vector or matrix as above

References

DURBIN, J., "Tests for Serial Correlation in Regression Analysis based on the Periodogram ofLeast-Squares Residuals," Biometrika, 56, (No. 1, 1969), 1-15.

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

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

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

Examples

data(PIB)
data(celec)
mod1=rdf(celec,PIB)
newdata=c(20000)
estimardf(mod1,newdata)

Regression in Fourier Flexible Form

Description

Make a Fourier Flexible Form Regression

Usage

FFF(y,x)

Arguments

y

a Vector of the dependent variable

x

a Vector of the independent variable

Details

The regresion FFF use LM for fitted into the serie y_t and the fourier coefficients expansion described in Gallant (1984).

The output is a data.frame object.

Value

fitted

The time - serie fitted

X

The X time - series fourier coefficients

residuals

The time - serie fitted

References

DURBIN, J., "Tests for Serial Correlation in Regression Analysis based on the Periodogram ofLeast-Squares Residuals," Biometrika, 56, (No. 1, 1969), 1-15.

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

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

Gallant; A. R.(1984), The Fourier Flexible Form. Amer. J. Agr. Econ.66(1984):204-15.

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

Parra, F.(2021), Econometria con Series de Fourier (https://econometria.files.wordpress.com/2020/12/curso-de-econometria-avanzado.pdf)

Examples

data(PIB)
data(celec)
FFF(celec,PIB)

Plotting the trend and seasonal

Description

Plotting the trend and seasonal of time series.

Usage

gdescomponer(y,freq,type,year,q)

Arguments

y

a vector of the observed time-serie values

freq

Number of times in each unit time interval

type

lineal (1), quadratic(2)

year

the year of the first observation

q

the time of the first observation

References

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

See Also

descomponer

Examples

data(ipi)
gdescomponer(ipi,12,1,2002,1)

Get Frequency Data

Description

Transforms the data from the amplitude-time domain the amplitude-frequency domain pre-multiplied by the orthogonal matrix ,W, whose elements are defined in Harvey A.C. (1978).

Usage

gdf(y)

Arguments

y

a vector of the observed time-series values

Value

a vector of the estimated coefficients fourier

Author(s)

Francisco Parra

References

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

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

See Also

gdt

Examples

n<-100;x<-seq(0,24*pi,length=n);y<-sin(x)+rnorm(n,sd=.3)
gdf(y)

Get Time Data

Description

Transforms the data from the amplitude-frequency domain the amplitude-time domain pre-multiplied by inverse of the orthogonal matrix ,W, whose elements are defined in Harvey A.C. (1978).

Usage

gdt(y)

Arguments

y

a vector of the coefficients fourier

Value

a vector of the observed time-series values

Author(s)

Francisco Parra

References

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

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

See Also

gdf

Examples

n<-100;x<-seq(0,24*pi,length=n);y<-sin(x)+rnorm(n,sd=.3)
coef <- gdf(y)
gdt(coef)

Plotting method for specturm

Description

Plotting method for specturm calculate by periodograma function.

Usage

gperiodograma(y)

Arguments

y

a vector of the observed time-serie values

References

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

See Also

periodograma

Examples

n<-100;x<-seq(0,24*pi,length=n);y<-sin(x)+rnorm(n,sd=.3)
gperiodograma(y)

Plotting method for specturm

Description

Plotting cumulative periodogram test.

Usage

gtd(y)

Arguments

y

a vector of the observed time-serie values

References

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

See Also

td

Examples

data(PIB)
gtd(PIB)

Indice de Produccion Industrial de Cantabria

Description

A vector: IPI, Base: 2010. Enero 2002 a Abril 2014

Usage

data(ipi)

Source

Instituto Nacional de Estadistica Spain


Get Frequency Data

Description

Orthogonal matrix defined in Harvey (1978)

Usage

MW(n)

Arguments

n

rows and columuns number

Value

Orthogonal matrix of n X n dimensions

Author(s)

Francisco Parra

References

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

See Also

gdt,gdf,cdf

Examples

MW(80)

Periodogram

Description

Calculates and displays the spectrum of the time serie

Usage

periodograma(y)

Arguments

y

a vector of the observed time-serie values

Value

frecuencia

Vector of frequencies at which the spectral density is estimated. The units are the reciprocal of cycles per unit time.

omega

Is calculated by pi*frecuencia/(n/2)

periodos

n/frecuencia

densidad

Vector of estimates of the spectral density at frequencies corresponding to frecuencia.

References

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

See Also

gperiodograma

Examples

n<-100;x<-seq(0,24*pi,length=n);y<-sin(x)+rnorm(n,sd=.3)
periodograma(y)

GDP Volume Index in Spain

Description

A vector: PIB, Base: 2010. 1995 a 2013

Usage

data(PIB)

Source

Instituto Nacional de Estadistica Spain


Prediction whit Regression in FFF

Description

Make a prediction for a rdf object

Usage

predictFFF(y,x,new)

Arguments

y

a Vector of the dependent variable

x

a Vector of the independent variable

new

A data frame in which to look for variables with which to predict. If omitted, the fitted values are used.

Details

Use predict.lm, with interval="confidence"

Value

fit

vector or matrix as above

References

DURBIN, J., "Tests for Serial Correlation in Regression Analysis based on the Periodogram ofLeast-Squares Residuals," Biometrika, 56, (No. 1, 1969), 1-15.

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

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

Gallant; A. R.(1984), The Fourier Flexible Form. Amer. J. Agr. Econ.66(1984):204-15.

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

Parra, F.(2021), Econometria con Series de Fourier (https://econometria.files.wordpress.com/2020/12/curso-de-econometria-avanzado.pdf)

Examples

data("ipi")
t=seq(1:length(ipi))
Mod1=FFF(ipi,t)
plot(ipi)
lines(Mod1$fitted)
new=(length(t)+1):(length(t)+12)
Mod2=predictFFF(ipi,t,new)

Prediction whit Regression in domain frequency

Description

Make a prediction for a rdf object

Usage

predictrdf(a,b)

Arguments

a

a model rdf

b

An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used.

Details

Use predict.lm, with interval="prediction"

Slow computer in time series higher 1000 data.

Value

fit

vector or matrix as above

References

DURBIN, J., "Tests for Serial Correlation in Regression Analysis based on the Periodogram ofLeast-Squares Residuals," Biometrika, 56, (No. 1, 1969), 1-15.

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

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

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

Examples

data(PIB)
data(celec)
mod1=rdf(celec,PIB)
newdata=c(100)
predictrdf(mod1,newdata)

Regression in domain frequency

Description

Make a Band Spectrum Regression using the comun frequencies in cross-spectrum .

Usage

rdf(y,x)

Arguments

y

a Vector of the dependent variable

x

a Vector of the independent variable

Details

Transforms the time series in amplitude-frequency domain, order the fourier coefficient by the comun frequencies in cross-spectrum, make a band spectrum regresion (Parra, F. ,2013) of the serie y_t and x_t for every set of fourier coefficients, and select the model to pass the Durbin test in the significance chosen.

If not find significance for Band Spectrum Regression, make a OLS.

The generalized cross validation (gcv), is caluculated by: gcv=n*sse/((n-k)^2)

where "sse" is the residual sums of squares, "n" the observation, and k the coefficients used in the band spectrum regression.

Slow computer in time series higher 1000 data.

The output is a data.frame object.

Value

datos$Y

The Y time-serie

datos$X

The X time-serie

datos$F

The time - serie fitted

datos$reg

The error time-serie

Fregresores

The matrix of regressors choosen in frequency domain

Tregresores

The matrix of regressors choosen in time domain

Nregresores

The coefficient number of fourier chosen

sse

Residual sums of squares

gcv

Generalized Cross Validation

References

DURBIN, J., "Tests for Serial Correlation in Regression Analysis based on the Periodogram ofLeast-Squares Residuals," Biometrika, 56, (No. 1, 1969), 1-15.

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

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

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

Examples

data(PIB)
data(celec)
rdf(celec,PIB)

Cumulative periodogram test

Description

Cumulative periodogram test.

Usage

td(y)

Arguments

y

a vector of the observed time-serie values

Details

The output is a data.frame object.

Value

s2

Cumulative periodogram.

min

Is calculated by -c+(t/length(y))

max

Is calculated by c+(t/length(y))

References

Parra, F. (2014), Amplitude time-frequency regression, (http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/)

See Also

periodograma

Examples

data(PIB)
td(PIB)