【问题标题】:Mixed data sampling in R (midas_r)R中的混合数据采样(midas_r)
【发布时间】:2021-02-05 03:43:08
【问题描述】:

我有以下代码,其中我有一个每周时间序列(变量 x),我想使用它来预测我的每月时间序列(变量 y)。

所以基本上我想用当前月份的 1、2、3 或所有 4 周(变量 New_value)来预测当前月份的数据(变量 y)。

但是,我不确定我是否使用了正确的滞后(我想我是这样),而且我不确定如何解释 midas_r 函数中的起始值(start = list())。

任何帮助将不胜感激。

######################
# MIDAS REGRESSION
####################
x <- structure(c(1.19, 1.24 , 1.67 , 1.67 , 1.55 , 1.67 , 1.39 , 2.01 , 2.14 , 1.71 , 1.59 , 1.49 , 1.68 , -0.37 , -0.44 , -7.87 , -7.79 , -31.22 , -31.05 , -30.47 , -35.53 , -25.48 , -25.9 , -19.03 , -16.33 , 
                 10.09 , 13.19 , 13.31 , 16.85 , 14.58 , 14.78 , 14.62 , 15.27 , 15.58 , 15.63 , 14.27 , 14.09 , 4.82 , 3.55 , 3.46 , 3.24 , 2.86 , 2.86 , 2.86 , 2.82),
               .Tsp = c(2020, 2020.846154, 52), class = "ts")
x <- diff(x)

y <- structure(c(2.30, 2.64 , 2.77 , 2.83 , -43.91 , 12.32 , 26.68 , 12.06 , 10.08 , 12.01 , 4.71 , 3.85),
               .Tsp = c(2020, 2020.91667, 12), class = "ts")
y <- diff(y)

trend <- c(1:length(y))

#RUNNING THE MIDAS REGRESSION
reg <- midas_r(y ~ mls(y, 1, 1) + mls(x, 4:7, m = 4, nealmon), start = list(x = c(1, 1, -1, -1)))
summary(reg)
hAh_test(reg)

#forecast(reg, newdata = list(y = c(NA), x =c(rep(NA, 4))))

#FORECAST WITH WEEKLY VALUES
reg <- midas_r(y ~ mls(y, 1, 1) + mls(x, 3:7, m = 4, nealmon), start = list(x = c(1, 1, -1, -1)))
new_value <- 2.52
#new_value <- c(2.52, 3.12)
forecast(reg, newdata = list(x = c(new_value, rep(NA, 4-length(new_value)))))

【问题讨论】:

    标签: regression midasr


    【解决方案1】:

    看起来你有缩进的问题,加上一些不必要的复杂性。

    试试这样的方法,看看它是否有效:

    for i in range(1, 20):
        url = 'https://www.boliga.dk/salg/resultater?propertyType=4&street=&municipality=326&salesDateMin=2020&page=' + str(i)
        page = requests.get(url)
        soup = BeautifulSoup(page.text, 'html.parser')    
        table = soup.find('table', {'class': 'table generic-table m-0 mb-3'})
        df = pd.read_html(str(table))[0]
        df = pd.DataFrame(df) #if it all works otherwise, try running the code w/out this line; it may be unnecessary
        df
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-03
      • 1970-01-01
      • 2019-09-22
      • 2016-04-12
      • 1970-01-01
      • 2011-09-27
      • 1970-01-01
      相关资源
      最近更新 更多