Dear all,
Good morning all. I'm trying to us the Zelig::zelig function to estimate an
ARIMA model after I have removed the seasonal and trend components of a time
series data (CHPH.ts) that I have imported from a CV file. Please see
syntax below.
All seems to be ok apart from when I run: z.out <-
zelig(Diff(dtrdseas.log.CHPK.ts, 0) ~ lag.y(3) + lag.eps(3), model = "arima"
, ,)
I get the following error message:
Error in inherits(x, "factor") : element 1 is empty;
the part of the args list of 'class' being evaluated was:
(data)
I've tried changing the syntax to include: data = Data and data =
dtrdseas.log.CHPK.ts plus many alternatives. Nothing seems to work. I'd be
very grateful for advice on the error message and how force the zelig
function to read dtrdseas.log.CHPK.ts in the zelig function.
I've read material on the zelig website (
http://gking.harvard.edu/zelig) but
I'm still lost
Syntax
#Import Data from csv file
Data
<-read.csv("C:/Users/Zebedee/Documents/Dissertation/Data/Germany.csv",header
=T)
#Name the first column of csv file as Data and format the Data
Datecol<-Data[,1]
as.Date(as.character(Datecol),format="%Y%m%d")
#Report the dimensions of Data and list
dim(Data)
names (Data)
## DESCRIPTIVE STATISTICS
# Plots in levels
CH.ts <- ts(Data[,2], start = c(2002, 1), end = c(2008, 22), freq = 52)
PK.ts <- ts(Data[,3], start = c(2002, 1), end = c(2008, 22), freq = 52)
BF.ts <- ts(Data[,4], start = c(2002, 1), end = c(2008, 22), freq = 52)
CHPK.ts<- ts(Data[,5], start = c(2002, 1), end = c(2008, 22), freq = 52)
CHBF.ts<- ts(Data[,6], start = c(2002, 1), end = c(2008, 22), freq = 52)
#Deseasonalise and detrend data
t<-1: length(log(CHPK.ts))
t2<-t^2
t3<-t^3
sin.t<-sin(2*pi*t/52)
cos.t<-cos(2*pi*t/52)
par(mfrow=c(2,1))
plot(log(CHPK.ts))
trd.log.CHPK.ts<-lm(log(CHPK.ts)~t+t2+t3+sin.t+cos.t)
lines(lm(log(CHPK.ts)~t+t2+t3+sin.t+cos.t)$fit,col=2,lwd=2)
summary(lm(log(CHPK.ts)~t+t2+t3+sin.t+cos.t))
AIC(trd.log.CHPK.ts)
tsDyn::BIC(trd.log.CHPK.ts)
lmtest::bptest(trd.log.CHPK.ts)
lmtest::resettest(trd.log.CHPK.ts)
lmtest::bgtest(trd.log.CHPK.ts, order = 52)
lmtest::dwtest(trd.log.CHPK.ts)
dtrdseas.log.CHPK.ts<- log(CHPK.ts) -
(lm(log(CHPK.ts)~t+t2+t3+t3+sin.t+cos.t)$fit)
plot(dtrdseas.log.CHPK.ts)
#Estimate ARIMA model
library(Zelig)
z.out <- zelig(Diff(dtrdseas.log.CHPK.ts, 0) ~ lag.y(3) + lag.eps(3), model
= "arima" , ,)
summary(z.out)
x.out <- setx(z.out)
s.out <- sim(z.out)
s.out <- sim(z.out, x = x.out)
Kind regards,
Zebedee