Description of the MS-Regress R package (Rmetrics)

Similar documents
FORECASTS GENERATING FOR ARCH-GARCH PROCESSES USING THE MATLAB PROCEDURES

- The whole joint distribution is independent of the date at which it is measured and depends only on the lag.

Distribution of Estimates

ON DETERMINATION OF SOME CHARACTERISTICS OF SEMI-MARKOV PROCESS FOR DIFFERENT DISTRIBUTIONS OF TRANSIENT PROBABILITIES ABSTRACT

Vector autoregression VAR. Case 1

Mathcad Lecture #8 In-class Worksheet Curve Fitting and Interpolation

R t. C t P t. + u t. C t = αp t + βr t + v t. + β + w t

Robust estimation based on the first- and third-moment restrictions of the power transformation model

Bias in Conditional and Unconditional Fixed Effects Logit Estimation: a Correction * Tom Coupé

Solutions from Chapter 9.1 and 9.2

Testing for a Single Factor Model in the Multivariate State Space Framework

Introduction D P. r = constant discount rate, g = Gordon Model (1962): constant dividend growth rate.

BOX-JENKINS MODEL NOTATION. The Box-Jenkins ARMA(p,q) model is denoted by the equation. pwhile the moving average (MA) part of the model is θ1at

State-Space Models. Initialization, Estimation and Smoothing of the Kalman Filter

Reduction of the Supervisor Design Problem with Firing Vector Constraints

GMM - Generalized Method of Moments

Chapter 5. Heterocedastic Models. Introduction to time series (2008) 1

Chickens vs. Eggs: Replicating Thurman and Fisher (1988) by Arianto A. Patunru Department of Economics, University of Indonesia 2004

Written HW 9 Sol. CS 188 Fall Introduction to Artificial Intelligence

Math 333 Problem Set #2 Solution 14 February 2003

dt = C exp (3 ln t 4 ). t 4 W = C exp ( ln(4 t) 3) = C(4 t) 3.

Self assessment due: Monday 4/29/2019 at 11:59pm (submit via Gradescope)

Kalman filtering for maximum likelihood estimation given corrupted observations.

Comparing Means: t-tests for One Sample & Two Related Samples

Testing H 0 : ρ = 0: Comparing A Single Correlation to Zero

Two Coupled Oscillators / Normal Modes

APPLIED ECONOMETRIC TIME SERIES (2nd edition)

Econ107 Applied Econometrics Topic 7: Multicollinearity (Studenmund, Chapter 8)

1 Review of Zero-Sum Games

Diebold, Chapter 7. Francis X. Diebold, Elements of Forecasting, 4th Edition (Mason, Ohio: Cengage Learning, 2006). Chapter 7. Characterizing Cycles

fakultät für informatik informatik 12 technische universität dortmund Petri Nets Peter Marwedel TU Dortmund, Informatik /10/10

DYNAMIC ECONOMETRIC MODELS Vol. 7 Nicolaus Copernicus University Toruń An Application of Markov-Switching Model to Stock Returns Analysis

Modeling and Forecasting Volatility Autoregressive Conditional Heteroskedasticity Models. Economic Forecasting Anthony Tay Slide 1

Lecture 2-1 Kinematics in One Dimension Displacement, Velocity and Acceleration Everything in the world is moving. Nothing stays still.

Biol. 356 Lab 8. Mortality, Recruitment, and Migration Rates

Stability. Coefficients may change over time. Evolution of the economy Policy changes

Stability analysis of semiconductor manufacturing process with EWMA run-to-run controllers

Matlab and Python programming: how to get started

Generalized Least Squares

Two Popular Bayesian Estimators: Particle and Kalman Filters. McGill COMP 765 Sept 14 th, 2017

= ( ) ) or a system of differential equations with continuous parametrization (T = R

Math 2142 Exam 1 Review Problems. x 2 + f (0) 3! for the 3rd Taylor polynomial at x = 0. To calculate the various quantities:

STRUCTURAL CHANGE IN TIME SERIES OF THE EXCHANGE RATES BETWEEN YEN-DOLLAR AND YEN-EURO IN

Estimation of Poses with Particle Filters

Hamilton- J acobi Equation: Explicit Formulas In this lecture we try to apply the method of characteristics to the Hamilton-Jacobi equation: u t

Math 10B: Mock Mid II. April 13, 2016

Estimation Uncertainty

Chapter 3 Common Families of Distributions

3.1.3 INTRODUCTION TO DYNAMIC OPTIMIZATION: DISCRETE TIME PROBLEMS. A. The Hamiltonian and First-Order Conditions in a Finite Time Horizon

Conservation of Momentum. The purpose of this experiment is to verify the conservation of momentum in two dimensions.

Intermediate Macroeconomics: Mid-term exam May 30 th, 2016 Makoto Saito

Instructor: Barry McQuarrie Page 1 of 5

Pattern Classification (VI) 杜俊

V L. DT s D T s t. Figure 1: Buck-boost converter: inductor current i(t) in the continuous conduction mode.

STATE-SPACE MODELLING. A mass balance across the tank gives:

( ) a system of differential equations with continuous parametrization ( T = R + These look like, respectively:

Unit Root Time Series. Univariate random walk

FITTING EQUATIONS TO DATA

Kriging Models Predicting Atrazine Concentrations in Surface Water Draining Agricultural Watersheds

Wednesday, November 7 Handout: Heteroskedasticity

Financial Econometrics Kalman Filter: some applications to Finance University of Evry - Master 2

Financial Econometrics Jeffrey R. Russell Midterm Winter 2009 SOLUTIONS

ESTIMATION OF DYNAMIC PANEL DATA MODELS WHEN REGRESSION COEFFICIENTS AND INDIVIDUAL EFFECTS ARE TIME-VARYING

0.1 MAXIMUM LIKELIHOOD ESTIMATION EXPLAINED

Modeling Economic Time Series with Stochastic Linear Difference Equations

Module 2 F c i k c s la l w a s o s f dif di fusi s o i n

23.2. Representing Periodic Functions by Fourier Series. Introduction. Prerequisites. Learning Outcomes

Chapter 7: Solving Trig Equations

Lecture 33: November 29

A Specification Test for Linear Dynamic Stochastic General Equilibrium Models

You must fully interpret your results. There is a relationship doesn t cut it. Use the text and, especially, the SPSS Manual for guidance.

Accurate RMS Calculations for Periodic Signals by. Trapezoidal Rule with the Least Data Amount

Simulation-Solving Dynamic Models ABE 5646 Week 2, Spring 2010

Most Probable Phase Portraits of Stochastic Differential Equations and Its Numerical Simulation

System of Linear Differential Equations

Seminar 4: Hotelling 2

Speech and Language Processing

A note to the convergence rates in precise asymptotics

Vehicle Arrival Models : Headway

Energy Storage Benchmark Problems

1 Differential Equation Investigations using Customizable

Demodulation of Digitally Modulated Signals

Excel-Based Solution Method For The Optimal Policy Of The Hadley And Whittin s Exact Model With Arma Demand

Material Resistance and Friction in Cold Rolling

13.3 Term structure models

Modeling House Price Volatility States in the UK by Switching ARCH Models

Linear Response Theory: The connection between QFT and experiments

L07. KALMAN FILTERING FOR NON-LINEAR SYSTEMS. NA568 Mobile Robotics: Methods & Algorithms

Regression with Time Series Data

Let us start with a two dimensional case. We consider a vector ( x,

t is a basis for the solution space to this system, then the matrix having these solutions as columns, t x 1 t, x 2 t,... x n t x 2 t...

ACE 562 Fall Lecture 5: The Simple Linear Regression Model: Sampling Properties of the Least Squares Estimators. by Professor Scott H.

Physics 127b: Statistical Mechanics. Fokker-Planck Equation. Time Evolution

A Bayesian Approach to Spectral Analysis

An EM algorithm for maximum likelihood estimation given corrupted observations. E. E. Holmes, National Marine Fisheries Service

Lecture 5. Time series: ECM. Bernardina Algieri Department Economics, Statistics and Finance

Learning Objectives: Practice designing and simulating digital circuits including flip flops Experience state machine design procedure

Vector autoregression VAR

Exponential Weighted Moving Average (EWMA) Chart Under The Assumption of Moderateness And Its 3 Control Limits

ODEs II, Lecture 1: Homogeneous Linear Systems - I. Mike Raugh 1. March 8, 2004

Transcription:

Descriion of he MS-Regress R ackage (Rmerics) Auhor: Marcelo Perlin PhD Suden / ICMA Reading Universiy Email: marceloerlin@gmail.com / m.erlin@icmacenre.ac.uk The urose of his documen is o show he general srucure of he ackage. The mahemaical noaion behind markov swiching models and Hamilon s filer is no going o be exosed here since i is no he oin. This definiely isn an inroducory documen on he markov swiching filer. My advice o hose who are jus saring ou is o firs read hrough he aers and books a he references and hen come back here o check he alicaion of he algorihm and he general comuaional srucure (inu/ouu) of he ackage. Also, be aware ha his ackage is a direc ranslaion of an exising Malab ackage. I is available a: h://www.mahworks.com/malabcenral/fileexchange/15789 Broadly seaking here are no big differences in boh ackages bu, he Malab one has a coule of exra funcionaliies ha are no available in he R ackage (e.g. choice of mehod for sandard error calculaion, use of C++ version of Hamilon s filer). The Mean Equaion This aricular R ackage is quie flexible when i comes o he secificaion of markov swiching models. The cenral oin of his flexibiliy resides in he inu argumen S, which conrols for where o include markov swiching effec. For insance, if you have 2 exlanaory variables ( x 1, x 2 ) and if he inu argumen S, which is assed o he fiing funcion MS_Regress_Fi.R, is defined as S<-c(1,1), hen he model for he mean equaion is: S S S 1 1 2 2 S - reresen he sae a ime, ha is, S = 1... K, where K is he number of saes S σ - model s sandard deviaion a sae S S β i - bea coefficien for exlanaory variable i a sae S where i goes from 1 o n ε - residue which follows a aricular disribuion (in his case Normal or Suden), wih zero mean and sd=var=1

Now, changing he inu argumen o S<-c(0,1), he model is: S S 1 1 2 2 Noes ha, wih his change in he inu argumen S, only he second coefficien and he model s sandard deviaion are swiching according o he ransiion robabiliies, ha is, he firs coefficien ( β 1) doesn change saes. Also, you should noes ha he order in S is he same order as in he mean equaion. For insance, if S<-c(1 0), hen he mean equaion becomes: S S 1 1 2 2 As an examle for he markov swiching fiing funcion, he following scri: library(fmarkovswiching) # Assuming library is insalled daa(inde) daa(de) # daa from ackage # daa from ackage S=c(1,0,0) # swiching in firs inde variable (firs column) disrib<-"normal" # Assumed disribuion for residue k<-2 # number of saes mymodel<-ms_regress_fi(de,inde,s,k,disrib) # calling Fi funcion reefers o he esimaion, based on Gaussian maximum likelihood, of he equaions: y y S= 1 S= 1 = β1 x1, + β 2x2, + β3x3, + σ ε if S = 1 S= 2 S= 2 = β1 x1, + β2x2, + β3x3, + σ ε if S = 2 wih: P= 11 12 21 22

as he ransiion marix, which conrols he robabiliy of a swich from sae j (column j) o sae i (row i). The sum of each column in P is equal o one, since hey reresen full robabiliies of he rocess for each sae. Noes ha hese oions o he fiing funcion are he same rovided a he examle scri Examle_MS_Regress_Fi.R (or alernaively wih he command examle(ms_regress_fi)). Anoher flexibiliy of he ackage is ha, since I wroe i for dealing wih a generic ye of regression, you can se any kind of exlanaory variable in he model as long as hey are observed (you have i available for he whole ime eriod sudied). This includes auoregressive comonens, consans or jus lain regression on oher variables. This means ha you can se u your own economeric model wihou changing any ar of he original code. Make sure you check he folder advscris in he roo direcory of fmarkovswiching. If you run he scri Examle_MS_Regress_Fi.R, his is he ouu (from rin()) you should be geing if everyhing is working. Noes ha I ve also added some clarificaions for he ouu (in red). ***** Numerical Oimizaion for MS Model Converged ***** Final log Likelihood: 2486.471 Number of arameers: 8 Disribuion Assumion -> Normal (maximum log likelihood found) (number of arameers in he model) (he disribuion assumion. You can change i a advo.disrib) ***** Final Parameers ***** ---> Non Swiching Parameers <--- (he arameers ha don swich (he 0 oions a inu S) Non Swiching Parameer a Inde Column 2 Value: 0.4797 (value of non swiching coefficien for inde column 2) Sd error: 0.0269 (0.00) (sandard error and value for coefficien) Non Swiching Parameer a Inde Column 3 Value: 0.1564 (value of non swiching coefficien for inde column 3) Sd error: 0.0333 (0.00) (sandard error and value for coefficien) ---> Swiching Parameers <--- (he arameers ha do swich (he 1 oions a inu S) Sae 1 Model Sandard Deviaion: 0.0288 (he model s sandard deviaion (he sigma) a sae 1) Sd Error: 0.0014 (0.00) (sandard error and value for corresonding sigma) Sae 2 Model Sandard Deviaion: 0.0163 (he model s sandard deviaion (he sigma) a sae 2) Sd Error: 0.0005 (0.00) (sandard error and value for corresonding sigma) Swiching Parameers for Inde Column 1 Sae 1 Value: 0.0006 (value of he swiching variable Inde column 1 a sae 1) Sd error: 0.0017 (0.74) (associaed sandard error and value) Sae 2 Value: 0.0003 (value of he swiching variable Inde column 1 a sae 2) Sd error: 0.0007 (0.65) (associaed sandard error and value)

---> Transiion Probabiliies Marix <--- (he marix ha conrols he robabiliy of each regime swich, along wih sandard errors and -values) 1 0.98 0.01 0.02 0.99 ---> Execed Duraion of Regimes <--- he execed duraion of each regime, calculaed as 1/(1- _ii) ) Execed duraion of Regime #1: 50.56 ime eriods Execed duraion of Regime #2: 94.08 ime eriods If his isn he ouu you re geing hen somehing is wrong wih your coy of R. Fell free o conac me by email, including he error message you ge and he code (he main scri) you re running. Using i for your own Daa You robably wan o aly he ackage o you own ime series. This oic will se some advices of how you can do his if he model is no converging o a soluion. Try o make your exlained and exlanaory series o behave around zero. For insance, if he model is no converging, hen ry diminishing he mean from he original ime series. This will hel he oimizing funcion o find he soluion. As you robably know, his is a genle ransformaion. Always ry o esimae simle models. For insance, don ry o esimae any model wih k>3 and number of exlanaory variables higher han 4. The model s size (number of arameers) grows exonenially as n and k grows. For insance, if k=5 and n=4 (4 exlanaory variables), hen he model has 55 arameers o be esimaed from daa, which is definiely oo much for Rdonl2. Don ge me wrong, he ackage will ry o esimae i, bu he soluion is robably a local maximum and you can really rus he ouu you ge. 1 You re robably wondering why no sandard errors for he ransiion robabiliies. The reason is ha I coded he esimaion ar of he ackage as a linear inequaliy roblem. This reduces he roblem of finding he higher log likelihood condiional on k*k arameers of he ransiion marix o k*(k-1), ha is, you solve he oimizaion roblem wih less arameers. This means ha he values of he ransiion marix for he las row are no direcly esimaed as hey are jus one minus he sum of he oher robabiliies in he same column. Given ha, hose arameers are no included in he Hessian marix and herefore no sandard errors are available. For he ransiion robabiliies ouside he las row, he sandard errors are available, bu I choose no o rin hem for maer of elegancy

If afer hose ses, you re sill having roblems converging o a soluion, send a message o my email (marceloerlin@gmail.com) wih a nice ersonal inroducion and an aached zi file conaining: 1) he scris you re running (he main.r file 2 ) 2) he error message (if here is one) (could be in.x or jus in he email sace) 3) he full daase (exlained and exlanaory in.xls or.x). Hoefully he daa is already being loaded o R in your main scri and I ll ake a look over i. I ll ry o rely in less han 48 hours if he roblem is simle (usually is). Also, if you have any quesion regarding he ackage, feel free o conac me a my reviously cied email. References ALEXANDER, C. (2008) Marke Risk Analysis: Pracical Financial Economerics Wiley. HAMILTON, J., D. (1994). Time Series Analysis. Princeon Universiy Press. HAMILTON, J., D. (2005) Regime Swiching Models Palgrave Dicionary of Economic. KIM, C., J., NELSON, C., R. (1999) Sae Sace Model wih Regime Swiching: Classical and Gibbs-Samling Aroaches wih Alicaions The MIT ress. 2 The file should run wihou any serious modificaion. (I don mind changing a few hings like he working direcory or anyhing simle as ha)