Learn R Programming

synlik (version 0.1.6)

nlar: Estimate non-linear autoregressive coefficients

Description

Function that, give time series data, transforms them into summary statistics using polynomial autoregression.

Usage

nlar(x, lag, power)

Value

a matrix where each column contains the coefficients for a different replicate.

Arguments

x

a matrix. Each column contains a replicate series.

lag

vector of lags, for rhs terms.

power

vector of powers, for rhs terms.

Author

Simon N. Wood, maintainer Matteo Fasiolo <matteo.fasiolo@gmail.com>.

Examples

Run this code
  library(synlik)
  set.seed(10)
  x <- matrix(runif(200),100,2)
  beta <- nlar(x,lag=c(1,1),power=c(1,2))
  y <- x[,1]
  y <- y - mean(y)
  z <- y[1:99];y <- y[2:100]
  lm(y~z+I(z^2)-1)
  beta
  
  ## NA testing
  x[5,1] <- x[45,2] <- NA
  beta <- nlar(x,lag=c(1,1),power=c(1,2))
  y <- x[,1]
  y <- y - mean(y,na.rm=TRUE)
  z <- y[1:99];y <- y[2:100]
  lm(y~z+I(z^2)-1)
  beta
  
  ## higher order...
  set.seed(10)
  x <- matrix(runif(100),100,2)
  beta <- nlar(x,lag=c(6,6,6,1,1),power=c(1,2,3,1,2))
  k <- 2
  y <- x[,k]
  y <- y - mean(y)
  ind <- (1+6):100
  y6 <- y[ind-6];y1 <- y[ind-1];y <- y[ind]
  beta0 <- coef(lm(y~y6+I(y6^2)+I(y6^3)+y1+I(y1^2)-1))
  as.numeric(beta[,k]);beta0;beta0-as.numeric(beta[,k])

Run the code above in your browser using DataLab