1 year ago

#372379

test-img

Cook04

msmFit: Fitting Markov Switching Models - Results differ almost every time

I am very new here and am writing my first post. I hope you will bear with me. I am currently using the msmFit(object, k, sw, p, data, family, control) command in R studio to set up a markov regime switching process.

I am not an econometrician, but the results of this command should be at least approximately similar, even though it is a stochastic process. However, in my case, both the transition probabilties and the coefficients change drastically when I run the command over and over again. Does anyone have any idea why this is the case? My command looks like this: msmFit(object, k, sw).

Do I need to change my command?

Thank you very much in advance!

installed.packages("reprex")
library(mSwM)
library(reprex)

stack_data <- read.csv("C:/Users/jm/Desktop/stackoverflow/stack_test_data.txt", sep=";")
head(stack_data)
#>         Time      ir_us     r_us     p_us   cpi_us    ip_us    m0_us    m2_us
#> 1 01.01.1990 0.02594126 9.040349 26.48077 64.36143 63.02983 36.57493 47.40648
#> 2 01.02.1990 0.02807363 8.487518 24.86121 64.61383 63.60197 36.65252 47.59210
#> 3 01.03.1990 0.03041778 8.444839 24.66913 64.91671 63.90794 36.94754 47.75527
#> 4 01.04.1990 0.03297896 8.513526 24.56466 65.06815 63.79125 37.41003 47.92743
#> 5 01.05.1990 0.03573270 8.218772 23.71389 65.16911 63.95692 37.56997 47.91246
#> 6 01.06.1990 0.03867350 8.494520 24.44051 65.57294 64.17380 37.85508 48.10856
#>      m1_us    m3_us   gdp_us    ei_us    ui_us r_us_silver r_us_platinum
#> 1 57.87674 47.40648 61.98087 89.79908 72.73218    58.69324      49.62649
#> 2 58.07320 47.59210 62.01272 89.34765 73.38249    58.25028      50.67231
#> 3 58.32060 47.75527 62.07644 89.03414 73.98315    56.36766      50.46813
#> 4 58.65532 47.92743 62.17202 88.93136 74.24094    56.47841      47.44024
#> 5 58.51706 47.91246 62.25323 88.98279 74.31311    55.92470      47.70916
#> 6 58.85178 48.10856 62.32005 89.06012 74.70761    55.26024      48.28187
#>   r_us_palladium r_us_gold r_us_stocks
#> 1       45.98305  78.42055    19.60036
#> 2       46.05085  79.06755    18.76965
#> 3       44.64407  75.98478    19.08397
#> 4       43.55932  71.26546    19.21868
#> 5       40.08475  70.12369    19.69017
#> 6       39.83051  67.50714    20.38617


linear_model <-
  lm(
    ir_us ~  r_us + p_us + cpi_us + ip_us + m3_us + gdp_us + ei_us +
      ui_us + r_us_silver + r_us_palladium+r_us_gold+ r_us_stocks,
    data = stack_data
  )
summary(linear_model)
#> 
#> Call:
#> lm(formula = ir_us ~ r_us + p_us + cpi_us + ip_us + m3_us + gdp_us + 
#>     ei_us + ui_us + r_us_silver + r_us_palladium + r_us_gold + 
#>     r_us_stocks, data = stack_data)
#> 
#> Residuals:
#>      Min       1Q   Median       3Q      Max 
#> -132.040  -22.572    3.879   23.025  108.042 
#> 
#> Coefficients:
#>                  Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)    -1.296e+03  3.218e+02  -4.028 6.82e-05 ***
#> r_us            2.982e-01  3.826e-01   0.779  0.43620    
#> p_us           -1.363e+00  4.978e-01  -2.739  0.00647 ** 
#> cpi_us          6.207e+00  3.606e+00   1.722  0.08598 .  
#> ip_us          -1.537e+01  1.021e+00 -15.057  < 2e-16 ***
#> m3_us          -1.773e+00  4.059e-01  -4.367 1.64e-05 ***
#> gdp_us          7.302e+00  1.757e+00   4.155 4.04e-05 ***
#> ei_us           1.008e+01  3.537e+00   2.850  0.00462 ** 
#> ui_us           6.478e+00  3.229e+00   2.006  0.04559 *  
#> r_us_silver    -8.770e-01  1.094e-01  -8.019 1.41e-14 ***
#> r_us_palladium  4.054e-01  4.138e-02   9.799  < 2e-16 ***
#> r_us_gold       1.929e+00  1.999e-01   9.650  < 2e-16 ***
#> r_us_stocks     9.762e-01  1.867e-01   5.230 2.84e-07 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 39.52 on 371 degrees of freedom
#> Multiple R-squared:  0.9907, Adjusted R-squared:  0.9904 
#> F-statistic:  3304 on 12 and 371 DF,  p-value: < 2.2e-16


markov_stack= msmFit(linear_model, k = 2, sw = rep(TRUE,14))
summary(markov_stack)
#>Markov Switching Model

#>Call: msmFit(object = linear_model, k = 2, sw = rep(TRUE, 14))

#>       AIC      BIC    logLik
#>  3100.603 3358.036 -1524.301

#>Coefficients:

#>Regime 1 
#>---------
#>                    Estimate Std. Error  t value  Pr(>|t|)    
#>(Intercept)(S)    -1781.0160   193.3639  -9.2107 < 2.2e-16 ***
#>r_us(S)               7.0689     0.6361  11.1129 < 2.2e-16 ***
#>p_us(S)              -9.3406     0.7354 -12.7014 < 2.2e-16 ***
#>cpi_us(S)             4.2407     2.0484   2.0702  0.038434 *  
#>ip_us(S)            -12.8299     1.0475 -12.2481 < 2.2e-16 ***
#>m3_us(S)             -3.9402     0.3883 -10.1473 < 2.2e-16 ***
#>gdp_us(S)            -6.7454     2.0428  -3.3020  0.000960 ***
#>ei_us(S)             22.5973     1.3841  16.3263 < 2.2e-16 ***
#>ui_us(S)             16.4904     1.2427  13.2698 < 2.2e-16 ***
#>r_us_silver(S)       -0.4286     0.0806  -5.3176 1.051e-07 ***
#>r_us_palladium(S)     0.4086     0.0324  12.6111 < 2.2e-16 ***
#>r_us_gold(S)          0.9030     0.1607   5.6192 1.918e-08 ***
#>r_us_stocks(S)        0.5458     0.1784   3.0594  0.002218 ** 
#>---
#>Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

#>Residual standard error: 21.1034
#>Multiple R-squared: 0.9958

#>Standardized Residuals:
#>          Min            Q1           Med            Q3           Max 
#>-4.936796e+01 -4.499687e-01 -9.253977e-05 -4.761520e-22  5.441522e+01 

#>Regime 2 
#>---------
#>                  Estimate Std. Error  t value  Pr(>|t|)    
#>(Intercept)(S)    353.0536    36.0750   9.7867 < 2.2e-16 ***
#>r_us(S)            -1.5104     0.2347  -6.4354 1.231e-10 ***
#>p_us(S)             1.2404     0.2016   6.1528 7.613e-10 ***
#>cpi_us(S)           7.7954     0.5055  15.4212 < 2.2e-16 ***
#>ip_us(S)            2.5948     1.1376   2.2809  0.022554 *  
#>m3_us(S)            5.2752     0.3180  16.5887 < 2.2e-16 ***
#>gdp_us(S)          -9.1814     2.1197  -4.3315 1.481e-05 ***
#>ei_us(S)           -5.2377     0.4792 -10.9301 < 2.2e-16 ***
#>ui_us(S)           -5.1023     0.3819 -13.3603 < 2.2e-16 ***
#>r_us_silver(S)     -0.5832     0.0845  -6.9018 5.135e-12 ***
#>r_us_palladium(S)   0.1364     0.0181   7.5359 4.841e-14 ***
#>r_us_gold(S)        1.8174     0.1417  12.8257 < 2.2e-16 ***
#>r_us_stocks(S)      0.3491     0.1063   3.2841  0.001023 ** 
#>---
#>Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

#>Residual standard error: 8.797613
#>Multiple R-squared: 0.9994

#>Standardized Residuals:
#>          Min            Q1           Med            Q3           Max 
#>-3.137047e+01 -3.511491e+00  1.954733e-28  3.090820e+00  3.767483e+01 

#>Transition probabilities:
#>           Regime 1   Regime 2
#>Regime 1 0.96021599 0.01554482
#>Regime 2 0.03978401 0.98445518

Data is available via https://syncandshare.lrz.de/getlink/fiGPrgkau1NdH8YKDfe9gBK9/

r

markov

0 Answers

Your Answer

Accepted video resources