Question

I have these two model in r. can i get an explanation for why i have different results when i use lm function and arma function on my time series data

fit1=arma(z,order=c(1,0))  
summary(fit1)

#Coefficient(s):  
#             Estimate    Std. Error    t value     Pr(>|t|)      
#  ar1        1.0001557      0.0001761   5678.00     <2e-16 ***  
#  intercept  1.8491535      0.1469061   12.59       <2e-16 ***  


fit2=lm(z~lag(z,1))  
summary(fit2)  

#Call:      
#lm(formula = z ~ lag(z, 1))       
#Coefficients:   
#            Estimate Std. Error   t value Pr(>|t|)          
#(Intercept) 8.699e-14  6.772e-15 1.285e+01   <2e-16 ***   
#lag(z, 1)   1.000e+00  8.109e-18 1.233e+17   <2e-16 ***
Was it helpful?

Solution

lag does not do what you think it does. It converts the object to ts and changes the index, not the actual vector values. The sign of the value for k is also opposite of what you'd expect.

set.seed(21)
z <- rnorm(6)
as.ts(z)
# Time Series:
# Start = 1 
# End = 8 
# Frequency = 1 
# [1]  0.7930132  0.5222513  1.7462222 -1.2713361  2.1973895  0.4331308
lag(as.ts(z),1)
# Time Series:
# Start = 0 
# End = 7 
# Frequency = 1 
# [1]  0.7930132  0.5222513  1.7462222 -1.2713361  2.1973895  0.4331308

xts::lag.xts provides the behavior you expect:

library(xts)
x <- .xts(z, 1:6)
xData <- merge(x=x, x1=lag(x,1))
fit3 <- lm(x ~ x1, data=xData)
summary(fit3)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top