【问题标题】:Impose constraints on the coefficient matrix of a var model in R对 R 中 var 模型的系数矩阵施加约束
【发布时间】:2020-01-26 23:42:05
【问题描述】:

如何对 r 中 var 模型的系数矩阵施加约束。 遵循我的一些代码

library(readxl)
dat_pc_log_d <- read_excel("C:/Users/Desktop/dat_pc_log_d.xlsx")
attach(dat_pc_log_d)
dat_pc_log_d$itcrm = NULL
dat_pc_log_d$...1 = NULL

data = ts(dat_pc_log_d,start = c(2004,1),end = c(2019,1),frequency = 4)
VAR_modelo = VAR(data,p=2) 

VAR_modelo_restriccion = restrict(VAR_modelo,method = "ser",thresh = 2.0)
ir_pib = irf(VAR_modelo_restriccion, impulse = "pbipc_log_d", response = c("pbipc_log_d", "expopc_log_d", "pbiagr_log_d"), 
             boot = TRUE, ci = 0.95)

我需要确保变量的外生性,因为我必须在自变量的一些滞后系数中强制为零。我该怎么做 ? 谢谢

【问题讨论】:

    标签: r machine-learning


    【解决方案1】:
    library(readxl)
    dat_pc_log_d <- read_excel("C:/Users//dat_pc_log_d.xlsx")
    attach(dat_pc_log_d)
    
    
    dat_pc_log_d$...1 = NULL
    
    data = ts(dat_pc_log_d,start = c(2004,1),end = c(2019,1),frequency = 4)
    VAR_modelo = VAR(data,p=2) 
    
    restriccion = matrix(c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                           1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
                           0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1),
                           nrow=8, ncol=17, byrow = TRUE)
    
    VAR_modelo_restriccion = restrict(VAR_modelo,method = "man", resmat = restriccion)
    ir_pib = irf(VAR_modelo_restriccion, impulse = "itcrm", response = c("pbipc_log_d", "expopc_log_d", "inverpc_log_d" , "pbiagr_log_d"), 
                 boot = TRUE, nhead=20 ,ci = 0.68)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      • 2015-03-07
      • 1970-01-01
      相关资源
      最近更新 更多