Two possible solutions:

(this comes from
http://www.stat.pitt.edu/stoffer/tsa2/R_time_series_quick_fix.htm as
suggested by Peter)

Using GLS:

library(nlme)            #* load the package*
fit.lm = lm(mort~trend + part)  #* ols*
acf(resid(fit.lm))       #* check acf and pacf of the resids *
pacf(resid(fit.lm))      #* or use acf2(resid(fit.lm)) if you have acf2*
#* resids appear to be AR(2) ... now use gls() from nlme:*
fit.gls = gls(mort~trend + part, correlation=corARMA(p=2), method="ML")
summary(fit.gls)


Using ARIMA:

fit2.gls = arima(mort, order=c(2,0,0), xreg=cbind(trend, part))


To obtain an F-statistic from the gls to indicate how significant the
overall modelled result is:

 "use anova(), comparing your model with a model estimating only the
intercept" - Mat

Cheers
Karl



On Mon, Dec 14, 2009 at 9:47 PM, Brecknock, Peter <Peter.Brecknock@bp.com>wrote:

> Karl
>
> Check out
> http://www.stat.pitt.edu/stoffer/tsa2/R_time_series_quick_fix.htm
>
> Search for "regression with autocorrelated errors"
>
> This offers two approaches ... using gls from the nlme package (as
> suggested by Matthieu) or using arima with the xreg parameter
>
> Best regards
>
> Pete
>
> -----Original Message-----
> From: Matthieu Stigler [mailto:matthieu.stigler@gmail.com]
> Sent: Monday, December 14, 2009 4:21 AM
> To: Karl Schriek
> Cc: r-sig-finance@stat.math.ethz.ch
> Subject: Re: [R-SIG-Finance] GLM correcting for serial correlation
>
> ?gls from package nlme?
>
> 2009/12/14 Karl Schriek <kschriek@gmail.com>
>
> > Hi
> >
> > I have a stationary time series to which I want to fit a linear model
> with
> > an autoregressive term to correct for serial correlation, i.e. using
> the
> > formula At = c1*Bt + c2*Ct + ut, where ut = r*ut-1 + et
> >
> > (i.e. ut is an AR(1) term to correct for serial correlation in the
> error
> > terms)
> >
> >
> > Does anyone know what to use in R to model this?
> >
> >
> > Thanks
> > Karl
> >
> >        [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-SIG-Finance@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> > -- Subscriber-posting only.
> > -- If you want to post, subscribe first.
> >
>
>         [[alternative HTML version deleted]]
>
>
>

	[[alternative HTML version deleted]]

