MARS | R Documentation |
This function groups prodIDs into strata (‘products’) by balancing two measures: an explained variance (R squared) measure for the ‘homogeneity’ of prodIDs within products, while the second expresses the degree to which products can be ‘matched’ over time with respect to a comparison period.
MARS(
data = data.frame(),
start,
end,
attributes = c(),
n = 3,
strategy = "two_months"
)
data |
The user's data frame with information about products. It must contain attributes: |
start |
The base period |
end |
The research period |
attributes |
A character vector with column names specifying the product attributes. |
n |
Parameter needed only if |
strategy |
A variable that determines how to calculate the degree of product match, the degree of homogeneity (the weighted R squared measure) and the final MARS score. Available options are: |
This function groups prodIDs into strata (‘products’) by balancing two measures: an explained variance (R squared) measure for the ‘homogeneity’ of prodIDs within products, while the second expresses the degree to which products can be ‘matched’ over time with respect to a comparison period. The resulting product ‘match adjusted R squared’ (MARS) combines explained variance in product prices with product match over time, so that different stratification schemes can be ranked according to the combined measure. Any combination of attributes is taken into account when creating stratas. For example, for a set of attributes A, B, C, the stratas created by the following attribute combinations are considered: A, B, C, A-B, A-C, B-C, A-B-C.The function returns a list with the following elements: scores
(with scores for degrees of product match and product homogeneity, as well as for MARS measure), best_partition
(with the name of the partition for which the highest indication of the MARS measure was obtained), and data_MARS
(with a data frame obtained by replacing the original prodIDs with identifiers created based on the selected best partition).
Chessa, A.G. (2022). A Product Match Adjusted R Squared Method for Defining Products with Transaction Data. Journal of Official Statistics, 37(2), 411–432.
df<-MARS(data=dataMARS,
start="2025-05", end="2025-09",
attributes=c("brand","size","fabric"),
strategy="two_months")
#Results:
df$scores
df$best_partition
df$data_MARS
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.