Re: [R] GLS models - bootstrapping

From: Christian Kamenik <>
Date: Wed 21 Feb 2007 - 11:16:32 GMT

Dear Lillian,

I tried to estimate parameters for time series regression using time series bootstrapping as described on page 434 in Davison & Hinkley (1997) - bootstrap methods and their application. This approach is based on an AR process (ARIMA model) with a regression term (compare also with page 414 in Venable & Ripley (2002) - modern applied statistics with S) I rewrote the code for R (this comes without any warranty):

fit <- function( data )
{ X <- cbind(rep(1,100),data$activ)

   para <- list( X=X,data=data)
   d <- arima(x=para$data$temp,order=c(1,0,0),xreg=para$X)    res <- d$residuals
   res <- res[!]

        res=res-mean(res),fit=X %*% d$reg.coef) }
beaver.args <- fit( beaver )
white.noise <- function( n.sim, ts) sample(ts,size=n.sim,replace=T) beaver.gen <- function( ts, n.sim, ran.args ) { tsb <- ran.args$res

   fit <- ran.args$fit
   coeff <- ran.args$paras
   ts$temp <- fit + coeff[4]*arima.sim( model=list(ar=coeff[1]),

                             n=n.sim,rand.gen=white.noise,ts=tsb )
   ts }
new.beaver <- beaver.gen( beaver, 100, beaver.args ) <- function(ts) fit(ts)$paras beaver.boot <- tsboot( beaver,, R=99,sim="model",


Maybe there is a more elegant way for doing this. Anyway, should give you confidence intervals.

Let me know how you are doing.

Best, Christian

> From: Lillian Sandeman <l.sandeman>
> Date: Mon, 2 Oct 2006 13:59:09 +0100 (BST)
> Hello,
> I am have fitted GLS models to time series data. Now I wish to bootstrap
> this data to produce confidence intervals for the model.
> However, because this is time series data, normal bootstrapping is not
> applicable. Secondly, 'tsboot' appears to only be useful for ar models -
> and does not seem to be applicable to GLS models.
> I have written code in R to randomly sample blocks of the data (as in
> Davison & Hinkley's book - bootstrap methods and their application) and
> use this resampling to re-run the model, but this does not seem to be the
> correct approach since Confidence Intervals produced do not show the
> underlying pattern (cycles) in the data [even when block length is
> increased, it only picks up a little of this variation].
> Any help as to how to proceed with this would be greatly appreciated, as I
> cannot find anything applicable on the R pages. Alternatively, if there
> is another method to proceed with this (other than bootstrapping), I would
> also be happy to try it.
> Thankyou,
> Lillian. mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed Feb 21 22:42:36 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 21 Feb 2007 - 12:30:33 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.