Reputation: 83
I have an issue when I try to adjust my quarterly time series dataset for seasonality in R. I have loaded in the dataset 'ASPUS' to R and specified it's date by using the following code:
ASPUS <- read.csv(file = "ASPUS.csv", header=TRUE, sep=",")
ASPUS$DATE <- as.Date(ASPUS$DATE, "%Y-%m-%d")
The head of the dataset looks like this:
DATE ASPUS
1 1963-01-01 100.00000
2 1963-04-01 100.51813
3 1963-07-01 99.48187
4 1963-10-01 101.55440
5 1964-01-01 101.55440
The purpose of the dataset is to analyze it as a Time Series. Therefore, I use the ts function to create a time series object:
ASPUSts <- ts(ASPUS, frequency = 4, start = 1963)
However, this function returns negative numbers within the date column like this:
DATE ASPUS
1963 Q1 -2557 100.00000
1963 Q2 -2467 100.51813
1963 Q3 -2376 99.48187
1963 Q4 -2284 101.55440
1964 Q1 -2192 101.55440
1964 Q2 -2101 104.66321
My problem then occurs in the next step, where I try to adjust for seasonality with the function seas:
ASPUS1 <- seas(ASPUSts)
Because I get this error:
Error: X-13 run failed
Errors:
- Seasonal MA polynomial with initial parameters is
noninvertible with root(s) inside the unit circle. RESPECIFY
model with different initial parameters.
Warnings:
- Automatic transformation selection cannot be done on a series
with zero or negative values.
- The covariance matrix of the ARMA parameters is singular, so
the standard errors and the correlation matrix of the ARMA
parameters will not be printed out.
- The covariance matrix of the ARMA parameters is singular, so
the standard errors and the correlation matrix of the ARMA
parameters will not be printed out.
Does anyone have any suggestions on how I can deal with these negative values or otherwise solve the problem so that I can seasonally adjust my dataset?
Upvotes: 1
Views: 1222
Reputation: 3083
According to ?ts
:
Description:
The function ‘ts’ is used to create time-series objects. ‘as.ts’ and ‘is.ts’ coerce an object to a time-series and test whether an object is a time series.
Usage:
ts(data = NA, start = 1, end = numeric(), frequency = 1, deltat = 1, ts.eps = getOption("ts.eps"), class = , names = ) as.ts(x, ...) is.ts(x)
Arguments:
data: a vector or matrix of the observed time-series values. A data frame will be coerced to a numeric matrix via ‘data.matrix’. (See also ‘Details’.)
Here, the key thing to note is: "data: a vector or matrix of the observed time-series values". I.e. you are not expected to enter the date vector as an input to ts
.
This is the correct syntax for ts
.
ASPUSts <- ts(ASPUS$ASPUS, frequency = 4, start = 1963)
In your example, seas
is actually trying to seasonally adjust the time series of dates that get transformed to -2557, -2467, ... (side note: internally R counts dates as differences from 1970-01-01; that's why dates in the '60s appear as negative numbers).
Upvotes: 2