最小二乘拟合模型 - R.

时间:2018-05-01 11:30:05

标签: r time-series least-squares whitenoise

数据文件(下面的代码线程中的X)包含20年期间每月数据X [t]的记录。

数据可以用X [12j + i] = Mu + s [i] + Y [12j + i]建模,其中(i = 1,...,12; j = 1,...,k )其中Mu,s [1],...,s [12]是模型的参数,Z [t]是白噪声WN(0,sigma ^ 2)和k = 20。给定Mu和Mu + s [i]的最小二乘估计量分别是在第i个时期记录的所有观测值的总平均值和平均值。获得此模型与数据的最小二乘拟合。

map2(c("bhs1_1", "bhs1_4"), c("bhs1_5", "bhs1_8"), ~ 
           bhs1 %>%
              select(!!(rlang::sym(.x)): !!(rlang::sym(.y)))) %>%
              rowMeans(., na.rm = TRUE)) %>%
    bind_cols(bhs1, .)

我找到了Mu的最小二乘估计和(Mu + s [i])

X <- c(20.73,20.51,21.04,21.34,21.60,21.67,21.93,22.18,21.55,21.38,20.78,20.75,20.57,20.09,20.61,21.33,21.72,21.83,21.70,22.62,21.40,21.53,20.71,20.82,20.73,20.65,20.67,21.40,21.21,21.63,21.77,22.20,21.29,21.44,21.01,20.75,20.64,20.24,21.03,21.61,21.46,21.61,22.08,22.66,21.21,20.95,20.88,20.37,20.53,20.30,21.26,21.14,21.99,21.88,22.46,22.31,21.65,21.60,20.62,20.71,20.64,20.94,20.89,21.19,21.57,21.91,21.71,21.95,21.52,21.06,20.77,20.50,20.67,20.77,21.06,21.70,20.73,21.83,21.71,22.99,21.81,20.97,20.72,20.43,20.49,20.33,20.95,21.34,21.61,21.88,22.28,22.33,21.16,21.00,21.07,20.59,20.87,20.59,21.06,21.23,21.59,21.80,21.76,22.48,21.91,20.96,20.83,20.86,20.36,20.48,20.89,21.35,21.80,21.87,22.13,22.54,21.91,21.33,21.18,20.67,20.98,20.77,21.22,21.09,21.37,21.71,22.45,22.25,21.70,21.67,20.59,21.12,20.35,20.86,20.87,21.29,21.96,21.85,21.90,22.10,21.64,21.56,20.46,20.43,20.87,20.38,21.05,20.78,21.99,21.59,22.29,22.23,21.70,21.12,20.69,20.47,20.42,20.51,21.10,21.39,21.98,21.86,22.40,22.04,21.69,21.32,20.74,20.51,20.21,20.29,20.64,21.29,22.03,21.90,22.22,22.07,21.95,21.57,21.01,20.27,20.97,20.64,20.95,21.19,22.02,21.73,22.35,22.45,21.50,21.15,21.04,20.28,20.27,20.48,20.83,21.78,22.11,22.31,21.80,22.52,21.41,21.13,20.61,20.81,20.82,20.42,21.20,21.19,21.39,22.33,21.91,22.36,21.53,21.53,21.12,20.37,21.01,20.23,20.71,21.17,21.63,21.89,22.34,22.23,21.45,21.32,21.05,20.90,20.80,20.69,20.49,21.28,21.68,21.98,21.67,22.63,21.77,21.36,20.61,20.83)

这是我感到困惑的地方。我不知道接下来要做什么来找到模型的最小二乘拟合。我试着找到Y的估算器:

lse.Mu <- mean(X)
IndicatorVar <- rep(1:12,20)
lse.Mu.si <- c(1:12)
for(i in 1:12){lse.Mu.si[i] <- mean(X[IndicatorVar==i])

但我仍然不知道如何使用它来找到最小二乘拟合或Z [t]白噪声进入它的位置。

请帮助我指出正确的方向或让我知道使用什么代码?我在谷歌上花了三天时间,我仍然无法解决这个问题!

接下来,我需要通过对数据与模型进行图形比较来检查模型的有效性,并采用任何被认为合适的统计检验。关于哪些图表和统计测试最好使用的任何建议将不胜感激。

0 个答案:

没有答案