0

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?

Roland
  • 127,288
  • 10
  • 191
  • 288
user3689959
  • 9
  • 1
  • 5
  • 1
    Which package are you using? – Roland Mar 16 '15 at 16:47
  • Hi, your formula seems a bit strange, are you sure that you have to add the coefficients in the formula ? because they should be estimated and the formula with `fit <- irls(y ~ cos(2*pi/365 * x) + sin(2*pi/365 * x) + x, data= heart) ` seems more natural, don't you think so? – Mamoun Benghezal Mar 17 '15 at 11:13
  • Hi Mamoun, thanks for advice, but my purpose is to use robust iteratively reweighted least squares(RIRLS) to estimate the value of coefficients of formula y = a0 + a1 * cos(2*pi/365 * x) + b1 * sin(2*pi/365 * x) + c1 * x, do you have any idea how to do it using irls? or Maybe use other functions? – user3689959 Mar 17 '15 at 15:28

0 Answers0