简体   繁体   English

Python 动态因素建模

[英]Python Dynamic Factor Modelling

I want to estimate Turkish gdp growth using the monthly train data below.我想使用下面的月度火车数据来估算土耳其国内生产总值的增长。

`       elcyoy  sanayiüretim sanayi tüketicigüven sanayikullanım
2022-08 -4.26   2.40    4.151   6.06    -0.2
2022-09 -3.03   -1.66   0.452   0.26    -0.5
2022-10 -5.14   2.82    3.05    5.26    -0.9
2022-11 -7.80   -1.13   2.08    0.62    -1.7
2022-12  2.00   NaN     2.00  -1.28     -2.0`

And below is my train gdp data, it is in quarter index.下面是我的火车 gdp 数据,它是季度指数。 2022Q4 does not exist and it is what I want to forecast. 2022Q4不存在,这是我想预测的。

    `  gdpyoy   gdpqq   eurozone
2021Q3  7.89    2.71    3.94339
2021Q4  9.60    1.58    4.77457
2022Q1  7.52    0.59    5.48059
2022Q2  7.74    1.87    4.24867
2022Q3  3.85    -0.12   2.27869`

However, when I implement the code, it gives me outcome this and forecast is below.但是,当我实施代码时,它会给我结果,预测如下。 It does not forecast 2022Q4 but it does forecast 2023 Q1.它没有预测 2022 年第四季度,但确实预测了 2023 年第一季度。 What am I missing?我错过了什么?

Dep. Variable:  "elcyoy", and 5 more    No. Observations:   180
Model:  Dynamic Factor Model    Log Likelihood  -941.547
+ 2 factors in 2 blocks AIC 1943.095
+ Mixed frequency (M/Q) BIC 2038.884
+ AR(1) idiosyncratic   HQIC    1981.933
Date:   Sun, 22 Jan 2023    EM Iterations   264
Time:   23:46:27        
Sample: 01-31-2008      
- 12-31-2022        
Covariance Type:    Not computed



 mod.forecast(10).resample('Q').last()['gdpyoy']

    2023Q1    3.957968
    2023Q2    4.964555
    2023Q3    5.016538
    2023Q4    5.023323
    Freq: Q-DEC, Name: gdpyoy, dtype: float64

I tried converting quarterly gdp data into monthly data, added it to the "trainaylık" series where every 2 month is blank and third month is the growth rate.我尝试将季度 gdp 数据转换为月度数据,并将其添加到“trainaylık”系列中,其中每 2 个月为空白,第三个月为增长率。 I tried to model again using "DynamicFactor" but it gave me a terrible results.我再次使用“DynamicFactor”尝试 model,但结果很糟糕。

Your data ends in 2022Q4, so it is part of the sample.您的数据在 2022Q4 结束,因此它是样本的一部分。 This is why it is not part of the forecast (which only provides out-of-sample predictions).这就是为什么它不是forecast的一部分(它只提供样本外预测)。 Instead you can use the predict method (which provides both in-sample and out-of-sample predictions):相反,您可以使用predict方法(它提供样本内和样本外预测):

mod.predict(start='2022-12', end='2023-12').resample('Q').last()['gdpyoy']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM