You are on page 1of 4

INTERVENTION ANALYSIS

Simulasi dan Aplikasinya dengan R

Suhartono
R & SAS: Intervention Analysis

#in SAS
proc arima data=data1;
identify var=y crosscorr=s;
estimate p=1 input=( 0$ (1,2) / (1) s );
run;

# in R
library(TSA)
model <- arimax(data1$y1, order=c(1,0,0), xtransf=data1$s,
transfer=list(c(1,3)))

2 ©Shtn, Departemen Statistika, Institut Teknologi Sepuluh Nopember


R : Intervention Analysis

library(tseries) par(mfrow=c(1,2))
library(TSA) #arimax plot(y1)
library(lmtest) #coeftest plot(y2)

set.seed(12) par(mfrow=c(1,2))
acf(y1, lag.max = 12)
y <- arima.sim(n = 200, list(ar = c(0.5, 0.3), pacf(y1, lag.max = 12, ylim=c(-1,1))
ma = 0), sd = sqrt(0.25))
par(mfrow=c(1,2))
par(mfrow=c(1,1)) acf(y2, lag.max = 12)
plot(y) pacf(y2, lag.max = 12, ylim=c(-1,1))

par(mfrow=c(1,2)) data <- cbind(y,ystar.p,p,y1,ystar.s,s,y2)


acf(y, lag.max = 12) write.table(data,"C:/intervention_data_2020.txt",
pacf(y, lag.max = 12, ylim=c(-1,1)) dec=",",sep="\t",col.names=TRUE)

# T=151 for Pulse and Step function model.p <- arimax(y1, order=c(2,0,0), xtransf=p,
transfer=list(c(0,2)),
p <- c(rep(0, 150), 1, rep(0, 49)) include.mean = FALSE)
s <- c(rep(0, 150), rep(1, 50)) model.p
p <- as.ts(p)
s <- as.ts(s) coeftest(model.p)
resi.p=as.ts(model.p$residuals)
ystar.p <- c(rep(0, 150), 15, 10, 5, rep(0, 47)) fits.p=as.ts(fitted(model.p))
y1 <- y + ystar.p
par(mfrow=c(1,1))
ystar.s <- c(rep(0, 150), 15, 25, rep(30, 48)) plot(y1)
y2 <- y + ystar.s lines(fits.p, col="red")

3 ©Shtn, Departemen Statistika, Institut Teknologi Sepuluh Nopember


R : Intervention Analysis

# Pulse Function
model.p <- arimax(y1, order=c(2,0,0), xtransf=p, transfer=list(c(0,2)), include.mean = FALSE)
model.p
coeftest(model.p)
resi.p=as.ts(model.p$residuals) #define the residual value
fits.p=as.ts(fitted(model.p))

par(mfrow=c(1,2))
plot(resi.p)
acf(resi.p[3:200])
par(mfrow=c(1,1))
plot(y1)
lines(fits.p, col="red")

# Step Function
model.s <- arimax(y2, order=c(2,0,0), xtransf=s, method = 'CSS-ML', transfer=list(c(0,2)),
include.mean = FALSE)
model.s
coeftest(model.s)
resi.s=as.ts(model.s$residuals) #define the residual value
fits.s=as.ts(fitted(model.s))

par(mfrow=c(1,2))
plot(resi.s)
acf(resi.s[3:200])
par(mfrow=c(1,1))
plot(y2)
lines(fits.s, col="red")

4 ©Shtn, Departemen Statistika, Institut Teknologi Sepuluh Nopember

You might also like