简体   繁体   English

不同阶次求和的动态线性回归循环

[英]Dynamic linear regression loop for different order summation

I've been trying hard to recreate this model in R: Model (FARHANI 2012)我一直在努力在 R 中重新创建这个模型:模型(FARHANI 2012)

I've tried many things, such as a cumsum paste - however that would not work as I could not assign strings the correct variable as it kept thinking that L was a function.我尝试了很多东西,例如 cumsum paste - 但是这不起作用,因为我无法为字符串分配正确的变量,因为它一直认为 L 是一个函数。 I tried to do it manually, I'm only looking for p,q = 1,2,3,4,5 however after starting I realized how inefficient this is.我试图手动完成,我只是在寻找 p,q = 1,2,3,4,5 但是在开始后我意识到这是多么低效。 This is essentially what I am trying to do这基本上就是我想要做的

model5 <- vector("list",20)
#p=1-5, q=0
model5[[1]] <- dynlm(DLUSGDP~L(DLUSGDP,1))
model5[[2]] <- dynlm(DLUSGDP~L(DLUSGDP,1)+L(DLUSGDP,2))
model5[[3]] <- dynlm(DLUSGDP~L(DLUSGDP,1)+L(DLUSGDP,2)+L(DLUSGDP,3))
model5[[4]] <- dynlm(DLUSGDP~L(DLUSGDP,1)+L(DLUSGDP,2)+L(DLUSGDP,3)+L(DLUSGDP,4))
model5[[5]] <- dynlm(DLUSGDP~L(DLUSGDP,1)+L(DLUSGDP,2)+L(DLUSGDP,3)+L(DLUSGDP,4)+L(DLUSGDP,5))

I'm also trying to do this for regressing DLUSGDP on DLWTI (my oil variable's name) for when p=0, q=1-5 and also p=1-5, q=1-5 cumsum would not work as it would sum the variables rather than treating them as independent regresses.我也在尝试这样做以在 DLWTI(我的石油变量的名称)上回归 DLUSGDP,因为当 p=0、q=1-5 以及 p=1-5、q=1-5 cumsum 将无法正常工作时对变量求和而不是将它们视为独立的回归。 My goal is to run these models and then use IC to determine which should be analyzed further.我的目标是运行这些模型,然后使用 IC 来确定应该进一步分析哪些模型。 I hope you understand my problem and any help would be greatly appreciated.我希望你理解我的问题,任何帮助将不胜感激。

I think this is what you are looking for:我认为这就是你要找的:

reformulate(paste0("L(DLUSGDP,", 1:n,")"), "DLUSGDP")

where n is some order you want to try.其中n是您想尝试的某个顺序。 For example,例如,

n <- 3
reformulate(paste0("L(DLUSGDP,", 1:n,")"), "DLUSGDP")
# DLUSGDP ~ L(DLUSGDP, 1) + L(DLUSGDP, 2) + L(DLUSGDP, 3)

Then you can construct your model fitting by然后你可以构建你的模型拟合

model5 <- vector("list",20)
for (i in 1:20) {
  form <- reformulate(paste0("L(DLUSGDP,", 1:i,")"), "DLUSGDP")
  model5[[i]] <- dynlm(form)
  }

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

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