The following is a continuation of concepts that were originally discussed in the How to make a rolling average (moving average) help article, which describes in detail how market research professionals traditionally use this approach for time-series smoothing. It then walks you through how to use the web app by showing you a few common scenarios.
This article continues this discussion by showing you how to use R to automatically create a multiple response variable that has overlapping time periods. Using R code is preferable if you have many overlapping time periods to create and you don't want to have to create each sub-variable one-by-one in the web app, which is tedious and time-consuming.
Using R code to create a multiple response variable
- log in and access your dataset using R.
- If you are starting with a date/time variable (as most users will be in this situation), use the following code to roll it up into a categorical variable:
library(crunch) x <- rollup(ds$date, resolution = "M")
ds$period <- as.Categorical(x, format = "%Y-%m-%d")
- the alias of the variable that you're storing it as
- date/time variable
- Use the following code:
Changing the first line to be the name of the resultant variable.
name <- "Overlapping time periods" width <- 3 step <- 2 ds$time_bands <- deriveArray(slideCategories(ds$period, step = step, width = width, name = function(x) paste(x, "-", x[length(x)])), name = name)
- The alias of the variable you're going to be storing the result in
- The name you want to give the resultant multiple response variable.
- The number of periods within the band, as defined by the period variable above. For example: if the rollup is monthly, then the period is a monthly category, and thus a width of 3 is three months (Jan-Mar, Feb-Apr, and so on).
- How far apart each new band starts in terms of periods (The lower the step, the greater the overlap). For example: if the step is 2 (and the period was monthly, with bands of width=3), then we'd have Jan-Mar, Mar-May, May-Jul, and so on).
- If you want to hide the period variable (in situations where you had to create one from a date/time variable exclusively for this purpose), add the following line to the code (optional):