我正在尝试使用迭代重新加权最小二乘法来估计方程的系数:
y = a0 + a1 * cos(2*pi/365 * x) + b1 * sin(2*pi/365 * x) + c1 * x
当我使用 IRLS 来拟合这个方程时,我得到一个错误:
x <- c(69,77,117,149,165,197,213,221,229,237,261,269,301,309,40,104,128,144,168,176,192,208,224,240,256,352)
y <- c(1812,1603,1689,1901,1858,1834,2138,1830,1819,1944,1895,1775,1700,1712,1876,1657,2094,2116,2121,2276,2198,2211,2003,1944,1795,1698)
a0=1
a1=2
b1=3
c1=4
fit <- irls(y ~ a0 + a1 * cos(2*pi/365 * x) + b1 * sin(2*pi/365 * x) + c1 * x, data= heart)
Error in model.frame.default(formula, data) :
variable lengths differ (found for 'a0')
我该如何处理这个问题?有没有其他方法使用 IRLS 来估计系数?