1

I have a time series starting on January 30th 2018 and ending on June 14th 2020 that I would like to seasonnally adjust with the Indian holidays. To do so, I wanted to use the DSA package and the dsa function, based on the research that I made (It is a model that can deal with daily time series unlike X-13 for instance).

First of all, I import my csv file with 2 columns and 867 rows and I convert it into a xts object (necessary form for the use of the dsa function).

library(dsa)
library(xts)
daily_demand_df = read.table(file = file.path(file_path,"Demand data - daily.csv"),
                             sep = ";", row.names = NULL, header = FALSE,
                             encoding = 'utf-8', skip = 1, 
                             colClasses = c("character", "character"),
                             col.names = c("Date","Demand_Value"))

daily_demand_df$Demand_Value <- as.numeric(gsub(',', '.', daily_demand_df$Demand_Value))
daily_demand_df$Date<-as.Date(daily_demand_df$Date, format = "%d/%m/%Y")

daily_demand_df <- daily_demand_df[order(daily_demand_df$Date),]
rownames(daily_demand_df) <- 1:nrow(daily_demand_df)
head(x = daily_demand_df)
    Date Demand_Value
1 2018-01-29       3242.5
2 2018-01-30       3269.5
3 2018-01-31       3276.9
4 2018-02-01       3274.1
5 2018-02-02       3291.3
6 2018-02-03       3286.1

daily_demand_timeserie <- xts(x = daily_demand_df$Demand_Value,
                          order.by = daily_demand_df$Date,
                          frequency=365.2425)

Then I tried to apply the dsa function (without the holidays effect for now) on the time series, but I got the following error:

adjusted <- dsa(series = daily_demand_timeserie)
Error in xts::xts(s1, order.by = xts::last(times, n = length(s1))) : NROW(x) must match length(order.by)

I tried to explore the DSA function source code in order to understand where the probleme might lie, and I found out that in the function, at some point, February 29th is removed from the time series. Then I modified the source code of the dsa function to print the length of the s1 and the time series used in the dsa function and it returned 869 and 868, hence the length issue.

Does anyone know how to solve this issue ?

Thank you in advance, here is the documentation that I used.

Link for the theoretical paper on DSA

DSA reference manual

DSA function source code

vin100
  • 11
  • 4
  • Welcome to stack overflow. It’s easier to help if you make your question reproducible: include a minimal dataset in the form of an object for example if a data frame as df <- data.frame(…) where … is your variables and values or use dput(head(df)). This link may be helpful: [mre] – Peter Jun 23 '20 at 11:48
  • Sorry, I did not know the proper ways to do this. First, I imported two libraries: `library(dsa) library(xts) head(x = daily_demand_df) Date Demand_Value 1 29/01/2018 3242,5 2 30/01/2018 3269,5 3 31/01/2018 3276,9 4 01/02/2018 3274,1 5 02/02/2018 3291,3 6 03/02/2018 3286,1` By the way, in the original post, I wrote that I used "dsa_bis", yet I meant "dsa" (there's no difference except that I added a line in the source code to return the length of both series) – vin100 Jun 24 '20 at 08:14
  • That's completely fine. Maybe this information is better in the question than as a comment. – Peter Jun 24 '20 at 08:37
  • The post is edited now. – vin100 Jun 24 '20 at 09:15

1 Answers1

0

First of all, you do not need to specify the frequency variable in your xts() definition. But I do not think that this caused the problem.

I changed a few things in the package, so I hope that the problem does not occur anymore.

Generally, check whether you have missing values in the beginning and end of the series, because this can lead to problems in how dsa handels and interpolates missing data.