I'm trying use iteratively reweighted least squares method to estimate the coefficient of equation:
y = a0 + a1 * cos(2*pi/365 * x) + b1 * sin(2*pi/365 * x) + c1 * x
When I use IRLS to fit this equation I get an error:
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')
How can I deal with this problem? Is there any other way use IRLS to estimate the coefficient?