• No se han encontrado resultados

Función descomponer(y,frequency,type)

In document Econometria con Series de Fourier (página 71-77)

En base al modelo de regresión en el dominio de la frecuencia descompone una serie yt en los factores de

tendencia T D, estacionales ST , e irregulares IR. La función se desarrolla en los siguientes pasos:

1) Se calcula el periodograma de la serie, y se ordena según el vector de frecuencias para crear diferentes indices de orden.

2) Se obtiene un modelo de tendencia, a partir de las frecuencias mayores que n

2∗f requency si la serie es par

y las mayores que n−1

2∗f requency si la serie es impar. Para ello, se realiza la regresión en domininio de la

frecuencia entre la serie yty los regresores que se obtienen con la matriz auxiliar W xtInWT, donde xtes

el resultado de ajustar un modelo lineal del tipo yt= a + bt + eta la serie de datos (tipo=1) ó un modelo

cuadrático del tipo yt= a + bt + ct2+ et, en donde solo se consideran los regresores correspondientes a

las diferentes frecuencias seleccionadas. Una vez obtenidos los parámetros del modelo, se calcula la serie en el dominio de la frecuencia que una vez convierten al dominio del tiempo da como resultado la serie de tendencia T D.

3) Se obtiene la serie residual IRST = yt− T D, se y sobre esa serie se realiza una nueva selección de

frecuencias, las correspondientes a los factores estacionales es decir: n 2∗f requency,

2n 2∗f requency,

3n 2∗f requency,

etc. . . .. Se realiza la regresión en el dominio de la frecuencia entre IRST y los regresores correspondientes a las frecuencias seleccionadas obtenidas a partir de a matriz auxiliar W xtInWT, donde x

tes el resultado

de ajustar un modelo lineal del tipo IRST = a + bt + et a la serie de datos (tipo=1) ? un modelo

cuadr?tico del tipo IRST = a + bt + ct2+ e

t. Una vez obtenidos los parámetros del modelo, se calcula

la serie en el dominio de la frecuencia que una vez convierten al dominio del tiempo da como resultado la serie de tendencia ST .

4) Se obtiene la serie irregular a partir de IR = IRST − ST . y=BJsales.lead

frequency=4

type=2

descomponer <- function (y,frequency,type) {

# Author: Francisco Parra Rodriguez # http://rpubs.com/PacoParra/24432 # date:"y", frequency:"frequency".

# Use 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.

n <- length(y)

y <- matrix(y,ncol=1)

M <- MW(n) #crea la matriz de harvey para los n datos

f1 <- NULL

if(n%%2==0) {f2 <- n/(2*frequency)} else { f2 <- (n-1)/(2*frequency)}

#Modelo para obtener serie con tendencia

c <- seq(from=2, to=(2+(n/frequency) ))

i <- seq(1:n)

i <- seq(1:n)

i2 <- i*i

if (type==1)

{eq <- lm(y~i)

z <- eq$fitted} else {

if (type==2) eq <- lm(y~i+i2)

z <- eq$fitted} cx <- M%*%diag(z) cx <- cx%*%t(M) id <- seq(1,n) S1 <- data.frame(cx) S2 <- S1[1:(2+(n/frequency)),] X <- as.matrix(S2) cy <- M%*%y B <- solve(X%*%t(X))%*%(X%*%cy) Y <- t(X)%*%B BTD <- B XTD <- t(M)%*%t(X) TD <- t(M)%*%Y

# Genero la serie residual

IRST <- y-TD

# Realizo la regresion dependiente de la frecuenca utilizando como explicativa IRST. # modelo para obtener serie con estacionalidad con trunc.

frecuencia <- seq(0:(n/2))

frecuencia <- frecuencia-1

S <- data.frame(f1=frecuencia) sel <- subset(S,f1==trunc(2*f2))

c <- seq(from=2,to=(n/f2))

for (i in c) {sel1 <- subset(S,f1==i*trunc(2*f2))

sel <- rbind(sel,sel1)} m1 <- c(sel$f1 * 2) m2 <- c(m1+1) c <- c(m1,m2) n3 <- length(c) d <- rep(1,n3) s <- data.frame(c,d) S=s[with(s, order(c)), ]

l <- frequency*trunc(n/frequency)

ML <- MW(l) i <- seq(1:l) i2 <- i*i if (type==1) {eq <- lm(y[1:l]~i) z <- eq$fitted} else {

if (type==2) eq <- lm(y[1:l]~i+i2)

z <- eq$fitted}

cx <- ML%*%diag(z) #problema

cx <- cx%*%t(ML)

id <- seq(1,l)

S1 <- data.frame(cx,c=id)

S2 <- merge(S,S1,by.x="c",by.y="c") S3 <- rbind(c(1,1,cx[1,]),S2) m <- l+2

X1 <- S3[,3:m]

# matriz de regresores a l

X1 <- as.matrix(X1)

# la paso al dominio del tiempo

X2 <- data.frame(t(ML)%*%t(X1))

if (n==l) X3 <- X2 else X3 <- rbind(X2,X2[1:(n-l),])

# la paso al dominio de la frecuencia

X4 <-M%*%as.matrix(X3) cy <- M%*%IRST B1 <- solve(t(X4)%*%X4)%*%(t(X4)%*%cy) Y <- X4%*%B1 BST <- B1 XST <- M%*%X4 ST <- t(M)%*%Y TDST <- TD+ST IR <- IRST-ST data <- data.frame(y,TDST,TD,ST,IR) regresoresTD <- data.frame(XTD) regresoresST <- data.frame(XST)

list(datos=data,regresoresTD=regresoresTD,regresoresST=regresoresST,coeficientesTD=BTD,coeficientesST=BST) }

Función gdescomponer (y,freq,type,year,q))

Gráfico de la función descomponer.

gdescomponer <- function(y,freq,type,year,q) {

# Author: Francisco Parra Rodriguez

# http://econometria.wordpress.com/2013/08/21/estimation-of-time-varying-regression-coefficients/

serie <- descomponer (y,freq,type) TdsT <- c(serie$datos$TDST)

Td <- c(serie$datos$TD)

sT <- c(serie$datos$ST)

TDST <- ts(TdsT,frequency=freq,start = c(year,q)) TD <- ts(Td,frequency=freq,start = c(year,q)) ST <- ts(sT,frequency=freq,start = c(year,q)) par(mfrow=c(3,1)) plot (TDST) plot (TD) plot (ST) } Ejemplo 14

Realizamos una descomposicion temporal para el IPI de Cantabria, con una asociacion quadratica. library(descomponer)

data(ipi)

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

60 80 100 130

y

70 90 110

TDST

90 100 110 2 4 6 8 10 12

TD

Time

−25 −10 0 10

ST

−10 0 5 2 4 6 8 10 12

IR

Time

ts(datos$datos, frequency = 12)

gdescomponer(ipi,12,1,2002,1) Time TDST 2002 2004 2006 2008 2010 2012 2014 70 Time TD 2002 2004 2006 2008 2010 2012 2014 95 Time ST 2002 2004 2006 2008 2010 2012 2014 −25 5

Bibliografia

Alvarez N. (1990). Una aproximación a los ciclos económicos. Economía aplicada cuantitativa Cuadernos de la UNED. 1990: 143-201.

Artis M.; Clavel J.G.; Hoffmann M. y Nachane D. (2007) “Harmonic Regression Models: A Comparative Review with Applications”. Institute for Empirical Research in Economics”. University of Zurich. Working Paper Series .September 2007 SSRN-Harmonic Regression Models: A Comparative Review with Applications by Michael Artis; José Clavel; Mathias Hoffmann; DILIP NACHANE

Ashley, Richard A. (1984), “A Simple Test for Regression Parameter Instability,” Economic Inquiry 22, No. 2, 253-267.

Barnett; W. A. (1983). “New Indices of Money Supply and the Flexible Laurent Demand System.” J. Bus. and Econ. Statist. 7-23.

Bartlett M.S. (1954); "Problémes de l’analyse spectrale des séries temporelles stationnaries“. Inst. Statist. Univ. Paris 3; 119-34

Bartlett M.S. (1966). “An introduction to Stochastic Processes”; 2 end.Ed. Cambridge University Press. Berndt; E. R.; and M. S. Khaled (1979). “Parametric Productivity Measurement and Choice Among Flexible Functional Forms.” J. Polit. Econ. 87.1220-45.

Bhansali; R.J. (1979) “A Mixed Spectrum Analysis of the Lynx Data;”Journal of the Royal Statistical Society; Ser. A; 142(2); 199-209.

Brunk; H.D. (1962). “On the range of the difference between hypothetical distribution function and Pyke’s modified empirical distribution function”. Ann. Marh. Statist. 33; 525-32.

Campbell; M.J. and Walker; A.M. (1977); A Survey of Statistical Work on the Mackenzie River Series of Annual Canadian Lynx Trappings for the Years 1821-1934 and a New Analysis;" Journal of the Royal Statistical Society; Ser. A; 140(4); 411-431.

Caves; W.; Christensen; L. R. y Tretheway; M. W. (1980): “Flexible cost functions for multiproduct firms”. The Review of Economics and Statistics. Nº 62; págs 477-481.

Contreras; D y Escolano J (1984): EI análisis espectral como instrumento para detectar la estacionalidad. ESTADISTICA ESPAÑOLA Núm. 104; 1984; págs. 101 a 144

Chalfant J. y Gallant A. (1985); “Estimating substitution elasticities with the Fourier costs function; some Monte Carlo results”; Journal of Econometrics; 28; 205-222.

Christensen; L. R.; D. W. Jorgenson; and L. J. Lau. “Transcendental Logarithmic Production Frontiers.” Rev. Econ. and Statist. 55(1973):28-45.

De Janvry; A. (1972) “The Generalized Power Function.” Amer J. Agr.Econ. 54. 234-37.

Deaton A. y Muellbauer J. (1980); “An Almost Ideal Demand System”; American Economic Review; 70; 312-326

Denny; M. (1974). “The Relationship Between Forms of the Production Function.” Can. J. Econ. 7.21-31. Despotakis; K. A. (1986). “Economic Performance of Flexible Functional Forms.” Eur. Econ. Rev. 30.1107-43. Diewert; W. E. (1971). “An Application of the Shephard Duality Theorem: A Generalized Leontief Production Function.” J. Polit. Econ. 79. 481-507.

Diewert W. y Wales T. (1987); “Flexible Functional Forms and Global Curvature Conditions”; conometrica; 55; No. 1; 43-68.

Diewert W. y Wales T. (1988); “A Normalized Quadratic Semiflexible Functional Form”; Journal of Econo- metrics; 37; 327-42.

Durbin J. (1969); “Test for serial correlation in regresion analisys based on the periodogram of least squared residuals”. Biometrica; vol 56; nº1; (mar-1969); pp 1-15.

Engle R. (1972). “Band spectrum regression”. Working Paper Department of economics. MIT. Nº26. November 1972.

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

Elbadawi; I.; A. R. Gallant; and G. Souza. (1983). “An Elasticity Can Be Estimated Consistently without A Priori Knowledge of Functional Form.” Econometrica 51.1731-51.

Fleissig A.; Kastns T. y Terrell D. (1997); “Semi-nonparametric estimates of substitution elasticities”; Economics Letters; 54; No. 3; 209-219.

Fuss; M.; D. McFadden; and Y. Mundlak. (1978). “A Survey of Functional Forms in the Economic Analysis of Production.” Production Economics: A Dual Approach toTheory and Applications; ed. M. Fuss and D. Mc-Fadden; pp. 219-68. Amsterdam: North-Holland Publishing Co.

Gallant; A. R.(1981) “On the Bias in Flexible Functional Forms and an Essentially Unbiased Form.” J. Econometrics 15(1981):211-45.

Gallant; A. R. (1982). “Unbiased Determination of Production Technologies.” J. Econometrics 20. 285-323. Gallant; A. R.(1984) “The Fourier Flexible Form.” Amer. J. Agr. Econ.66(1984):204-15.

Gallant A. y Golub G. (1984); “Imposing Curvature Restrictions on Flexible Functional Forms”; Journal of Econometrics; 26; 295-321

Gonzalez G: Series de Fourier; Transformadas de Fourier y Aplicaciones; disponible en www.dmae.upm.es/WebpersonalBartolo/VariableCompleja/VCParteI/9_Series_de_Fourier.ppt Griffin R.C.; Montgomery J.M.; and Rister M.E. (1987). Selecting Functional Form in Production Function.

Análisis Western Journal of Agricultural Economics; 12(2): 216-227

Guilkey D. y Lovell C. (1980); “On the Flexibility of the Translog Approximation”; International Economic Review; 21; 137-147.

Halter; A. N.; H. O. Carter; and J. G. Hocking. (1957) “A Note on the Transcendental Production Function.” J. Farm Econ. 39. 966-74.

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

Hannan; E.J.(1971); “Non-linear Time Series Regression;” Journal ofApplied Probability; 8; 767-780. Hannan; E.J.(1973); “The Asymptotic Theory of Linear Time Series Models;” Journal of Applied Probability; 10; 130-145.

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

Heady; E. 0.; and J. L. Dillon; eds. (1961). “Agricultural Production Functions”. Ames: Iowa State University Press.

Hui;T and Ashley R. (1999): “An elementary method for detecting and modelling regression parameter variation across frequencies whit an application to testing the permanent income hypothesis”. Macroeconomic Dynamics / Volume 3 / Issue 01 / March 1999, pp 69-831999 Cambridge University Press.(http://ashleymac. econ.vt.edu/working_papers/e9702.pdf)

Kay; S.M. and Marple; S.L. (1981); “Spectrum Analysis - A Modern Perspective;” Proceedings of the IEEE; 69; 1380-1419.

Lau; L. J. (1978) “Testing and Imposing Monotonicity; Convexity and Quasi-Convexity Constraints.” Produc- tion Economics: A Dual Approach to Theory and Applications; ed. M. Fuss and D. McFadden; pp. 409-53. Amsterdam: North-Holland Publishing Co.

Lilyan E. Fulginiti; Richard K. Perrin and Bingxin Yu (2003): “Institution and agricultural productivity in sub-sahara Africa”. 25 International Conference of Agricultural Economists (IAAE). Durban South Africa. Marple; S. (1987) “Digital Spectral Analysis with Applications”; Prentice-Hall; Englewood Clios; N.J. Martínez M., Gómez L., Serrano J.A., Vila J., Gómez J. (2009): “Filtros Digitales”. Curso 2009-2010. Escola Tècnica Superior Ingenieria. Departament d´Enginyeria Electrònica Universidad de Valencia.

Melis F. (1991): “La Estimación del ritmo de variación de las series económicas”. Estadística Española. Vol 22. Num. 126; 1991.

McFadden; D. (1963). “Constant Elasticity of Substitution Production Functions.” Rev. Econ. Stud. 30.73-83. Maddala; G. S. Econometrics. New York: McGraw-Hill Book Co.; 1977.

Parra F (2014): Seasonal Adjustment by Frequency Analysis. Package R Version 1.1. URL:http://cran.r- project.org/web/packages/descomponer/index.html

Pyke R. (1959). “The supremun and infimum of the Poisson process”. Ann. Math. Statist.30; 568-76. Pisarenko; V.F. (1973); “The Retrieval of Harmonics from a Covariance Function;” Geophysical Journal of Royal Astronomical Society; 33; 347-366.

Priestley; M.B. (1964); “Estimation of the Spectral Density Function in the Presence of Harmonic Components;” Journal of the Royal Statistical Society; Ser. B; 26; 123-132.

Priestley; M.B. (1981); “Spectral Analysis and Time Series; Academic Press; London.

Ramajo J. “Avances recientes en el análisis econométrico de la demanda “.http://eco.unex.es/jramajo/ivcnea.pdf Silberberg; E. (1978). The Structure of Economics: A Mathematical Analysis. New York: McGraw-Hill Book Co.

Truong-Van; B. (1990); “A New Approach to Frequency Analysis with Amplied armonics;” Journal of the Royal Statistical Society; Ser.B; 52(1); 203-221.

Tweeten; L. (1983). “Hypothesis Testing in Economic Science.” Amer. J.Agr. Econ. 65.548-52.

Uzawa; H. (1962). “Production Functions with Constant Elasticity of Substitution.” Rev. Econ. Stud. 29.291-99.

Venables and Ripley (2002), “Modern Applied Statistics with S” (4th edition, 2002).

Villarreal F. (2005): “Elementos teóricos del ajuste estacional de series económicas utilizando X-12-ARIMA y TRAMO-SEATS”. Serie 38. Estudios estadísticos y prospectivos División de Estadística y Proyecciones Económicas. Santiago de Chile; Diciembre del 2005. www.eclac.org/publicaciones/xml/9/24099/lcl2457e.pdf Whittle; P. (1952); “Tests of Fit in Time Series;” Biometrika; 39; 309-318.

White; H. (1980). “Using Least Squares to Approximate Unknown Regression Functions.” Int. Econ. Rev. 21.149-70.

Young; P.C.; Pedregal; D.J. and W.Tych (1999); “Dynamic harmonic regression;” Journal of Forecasting; 18; 369-394

In document Econometria con Series de Fourier (página 71-77)

Documento similar