Dear R Users,
I have a CO2 time series. I want to fit this series seasonal cycle and trend
with fourth harmonic function,
and then compute residuals.
I am doing something like:
file<-read.csv("co2data.csv")
names(file)
attach(file)
fit<-lm(co2~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)
fit$residuals
# variable 'co2' is in ppmv and variable 'time' is in the form
of decimal
time.
The problem is: when I plot above residuals vs. time, it still shows some
seasonal cycle with time.
SO, I doubt that I am doing something wrong.
Kindly help, how to fit correctly, a fourth harmonic function on CO2 which
is varying with variable 'time'.
Great thanks,
Regards,
Yogesh
--
Yogesh K. Tiwari (Dr.rer.nat),
Scientist,
Indian Institute of Tropical Meteorology,
Homi Bhabha Road,
Pashan,
Pune-411008
INDIA
Phone: 0091-99 2273 9513 (Cell)
: 0091-20-258 93 600 (O) (Ext.250)
Fax : 0091-20-258 93 825
[[alternative HTML version deleted]]
dear Yogesh It appears that your model based on parametric terms is too inflexible.. A better alternative to parametric harmonic terms is a spline-based approach, may be cyclic splines.. Have a look to the mgcv package.. vito Yogesh Tiwari ha scritto:> Dear R Users, > I have a CO2 time series. I want to fit this series seasonal cycle and trend > with fourth harmonic function, > and then compute residuals. > > I am doing something like: > > file<-read.csv("co2data.csv") > names(file) > attach(file) > fit<-lm(co2~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) > > fit$residuals > > # variable 'co2' is in ppmv and variable 'time' is in the form of decimal > time. > > The problem is: when I plot above residuals vs. time, it still shows some > seasonal cycle with time. > SO, I doubt that I am doing something wrong. > > Kindly help, how to fit correctly, a fourth harmonic function on CO2 which > is varying with variable 'time'. > > Great thanks, > > Regards, > Yogesh >-- ===================================Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' Universit? di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 6626240 fax: 091 485726/485612 http://dssm.unipa.it/vmuggeo