Methane input into gas furnace: cu. ft/min. Sampling interval 9 seconds. Carbon dioxide output from gas furnace: percent of output gas. Sampling interval 9 seconds
# load data and turn them into ts object.
D = read.csv("https://nmimoto.github.io/datasets/methane.csv")
head(D)
CO2 = ts(D[,2], start=c(1, 1), freq=1)
Met = ts(D[,3], start=c(1, 1), freq=1)
plot(CO2)
plot(Met)
library(forecast) # load forecast package
source("https://nmimoto.github.io/R/TS-00.txt") # load custom functions
Y = CO2
acf(Y)
pacf(Y)
#--- Fit AR(p) model ---
Fit1 = auto.arima(Y, d=0, max.q=0) # Fit AR(p). Uses AIC to look for best p
Fit1
Fit2 = Arima(Y, order=c(5,0,0))
Fit2
# Residual Analysis
Randomness.tests(Fit1$resid)
forecast(Fit1)
plot(forecast(Fit1))
abline(h=mean(Y))
##--------------------------------------
## Observation = Y_t, and Y_t is AR(4) with mean
##
## Y_t = mu + X_t
## X_t is AR(4) with zero-mean
## X_t = (phi_1) X_{t-1} + (phi_2) X_{t-2} + (phi_3) X_{t-3} + (phi_4) X_{t-4} + epxilon_t
##
## hat_mu 53.6880 +-(2)*0.8679
## hat_(phi_1) 2.0976 +-(2)*0.0565
## hat_(phi_2) -1.3243 +-(2)*0.1344
## hat_(phi_3) -0.0071 +-(2)*0.1345
## hat_(phi_4) 0.2124 +-(2)*0.0566
## hat_sigma^2 0.1124
# Chemical concentration readings
D <- read.csv("https://nmimoto.github.io/datasets/concentration.csv")
D1 <- ts(D[,2], start=c(1,1), freq=1)
plot(D1, type='o')
library(forecast) # load forecast package
source("https://nmimoto.github.io/R/TS-00.txt") # load custom functions
Y = D1
acf(Y)
pacf(Y)
#--- Fit AR(p) model ---
Fit1 = auto.arima(Y, d=0, max.q=0) # Fit AR(p). Uses AIC to look for best p
Fit1
Fit2 = Arima(Y, order=c(4,0,0))
Fit2
Fit3 = Arima(Y, order=c(3,0,0))
Fit3
Fit4 = Arima(Y, order=c(2,0,0))
Fit4
# ?auto.arima # open help page
auto.arima(Y, d=0, max.q=0, stepwise=FALSE, trace=TRUE)
auto.arima(Y, d=0, max.q=0, stepwise=FALSE, trace=TRUE, approximation = FALSE)
# Always use approximation=FALSE unless it takes long time
# Residual Analysis
Randomness.tests(Fit4$resid)