Dear 'R' Users, I have CO2 timeseries which I want to fit with fourth harmonic function and then would like to compute residuals. I tried with two option but not sure which one is correct, kindly any one can help correcting me:
# #I would like to fit a model with Fourth harmonic function as: #m(t)=a+bt+ct^2+c1sin(omega1*t)+d1cos(omega1.t)+c2sin(omega2.t)+d2cos(omega2.t)+c3sin(omega3.t)+d3cos(omega3.t)+c4sin(omega4.t)+d4cos(omega4.t) # In my data 'file' I have two variable 'co2obs' and 'time' # SO above function in R will look like EITHER as: testfit<-lm(co2obs~1+time+(time^2)+sin(2*pi*time)+cos(2*pi*time)+sin(4*pi*time)+cos(4*pi*time)+sin(6*pi*time)+cos(6*pi*time)+sin(8*pi*time)+cos(8*pi*time),data=file) #RESIDUALS COMPUTING for above data fit testfit$residuals OR as: testfit<-lm(co2obs~1+time+I(time^2)+sin(2*pi*time)+cos(2*pi*time)+sin(4*pi*time)+cos(4*pi*time)+sin(6*pi*time)+cos(6*pi*time)+sin(8*pi*time)+cos(8*pi*time),data=file) #RESIDUALS COMPUTING for above data fit testfit$residuals NOTE: The 'third' term (ct^2) in both above is wrriten differently, rest terms are same. Kindly advise which one in above is correct, OR both are wrong ? Great Thanks, Regards, Yogesh [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.