time series object - is this right

noetsi

Fortran must die
#1
I think I got this right, but then I have been wrong before to quote Lt Gordan. :)

mydata<-read.csv("S:\\CIU\\Testfolder\\turnover.csv") # import the data
> str(mydata)
'data.frame':60 obs. of 4 variables:
$ Month : chr "7/1/2015" "8/1/2015" "9/1/2015" "10/1/2015" ...
$ Turnover : num 0.04 0.03 0.02 0.03 0.05 0.02 0.03 0.02 0.08 0.02 ...
$ Rehab.Rate : num 0.33 0.42 0.35 0.38 0.36 0.45 0.42 0.4 0.38 0.37 ...
$ Unemployment.Rate: num 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 ...

mydata2$Month<-as.Date(mydata$Month, format="%m/%d/%Y") # change my data to have month be a date
> str(mydata2)
'data.frame':60 obs. of 4 variables:
$ Month : Date, format: "2015-07-01" "2015-08-01" "2015-09-01" ...
$ Turnover : num 0.04 0.03 0.02 0.03 0.05 0.02 0.03 0.02 0.08 0.02 ...
$ Rehab.Rate : num 0.33 0.42 0.35 0.38 0.36 0.45 0.42 0.4 0.38 0.37 ...
$ Unemployment.Rate: num 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 ...

> tsdata=ts(mydata2,start=c(2015,7),frequency=12) # convert it to time series. It is monthly and starts July 2015
> str(tsdata)

Time-Series [1:60, 1:4] from 2016 to 2020: 16617 16648 16679 16709 16740 ... #I don't understand any of this
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:4] "Month" "Turnover" "Rehab.Rate" "Unemployment.Rate"

> tsdata
Month Turnover Rehab.Rate Unemployment.Rate # this looks right.
Jul 2015 16617 0.04 0.33 0.05
Aug 2015 16648 0.03 0.42 0.05
Sep 2015 16679 0.02 0.35 0.05
Oct 2015 16709 0.03 0.38 0.05
 

noetsi

Fortran must die
#3
I am not sure how to add the data here beyond what I did but what I want is very basic which is why I can't find it I am sure. I want to know how I tell the auto.arima to run one of the fields in tsdata as the xreg and which is the dependent variable. That is how you define columns for time series data that won't take commands mydata$spending.
 

noetsi

Fortran must die
#4
I thought this would work but it did not.
Code:
> dat

Tover RRate

1 .04 .33

2 .03 .42

3 .02 .35

4 .03 .38

5 .05 .36

6 .02 .45

7 .08 .42

8 .02 .4

9 .03 .38

10 .02 .4

> dput(dat)

structure(list(x = 1:10, y = c(.33, .42,

.35, .38, .36, .45,

.42, .4, ,38, .4

)), .Names = c("Tover", "RRate"), class = "data.frame")

dat <- structure(list(x = 1:10, y = c(.33, .42,

.35, .38, .36, .45,

.42, .4, ,38, .4

)), .Names = c("Tover", "RRate"), class = "data.frame")
tsdata=ts(dat,start=c(2015,7),frequency=12)
fit<-auto.arima(tsdata [,"RRate"],xreg=tsdata[,"Tover"])
I think that fixes it. I get no error, of course I still am not sure if I understand auto.arima correctly and so did any of it right. But that is a methods not coding issue.
 
Last edited:

noetsi

Fortran must die
#5
Out put for real data. I don't see differencing order here.

Series: tsdata[, "RehabRate"]
Regression with ARIMA(1,0,0) errors

Coefficients:
ar1 intercept xreg
0.3751 0.3777 0.0659
s.e. 0.1202 0.0127 0.2288

sigma^2 estimated as 0.001754: log likelihood=106.7
AIC=-205.41 AICc=-204.68 BIC=-197.03