R/pred1.R

Defines functions pred1

Documented in pred1

pred1 <- function(x, n = 10){
  if(n >= length(x))
    stop("n should be < length(x)")
  ns<-length(x)
  res<-c(1:ns)
  k <- min(c(n, length(x)))
  res[1:n]<-x[1:n]
  for(i in (n+1):ns){
    xs<-x[1:i]
    ak<-acf(xs,k,plot=F)
    a<-ak$acf[1:(k-1)]
    R<-toeplitz(a)
    r<-ak$acf[2:k]
    b<-solve(R)%*%r
    res[i]<-sum(x[(i-1):(i-(k-1))]*b)
  }
  return(res)
}

Try the mistat package in your browser

Any scripts or data that you put into this service are public.

mistat documentation built on March 7, 2023, 6:43 p.m.