{"id":18708,"date":"2023-03-16T13:52:00","date_gmt":"2023-03-16T20:52:00","guid":{"rendered":"https:\/\/portasftpserver.com\/?p=18708"},"modified":"2024-09-11T13:00:21","modified_gmt":"2024-09-11T20:00:21","slug":"how-to-calculate-cumulative-time-series","status":"publish","type":"post","link":"https:\/\/portasftpserver.com\/how-to-calculate-cumulative-time-series\/","title":{"rendered":"Calculate Cumulative Sum Time Series (CUSUM Change Detection)"},"content":{"rendered":"\n<p class=\"sera-block-paragraph\">A cumulative sum is a way of calculating how a number grows over time. A use case of this is to show how well your company performs based on the distribution metrics, the difference between previous and current values, et cetera. For example, if you want to monitor if the\u00a0<em>free shipping<\/em>\u00a0has an impact on the sales performance between the current point in time A-to-B and compare it to the previous sales without the free shipping offering. This can be a big advantage in helping you execute the right strategic decision based on the results. However, in real-life situations, data grows over time, and doing this manually by hand is very time-consuming as you may have to split different ranges of your data during calculations.<\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Although we can see the downside, we can calculate this easily using statistical software or even just from an excel spreadsheet. But first, let&#8217;s understand the concept of the cumulative sum equation in detecting <strong>increased <\/strong>change.<\/p>\n\n\n\n<p class=\"sera-block-paragraph\">\\(S_t=max\\{0,S_{t-1} + (X_t-{\\mu}-C)\\} \\)<\/p>\n\n\n\n<h5 class=\"sera-block-heading\">Equation Breakdown<\/h5>\n\n\n\n<p class=\"sera-block-paragraph\"><sub><em>Xt<\/em><\/sub> = is the sales at the current time (Current value on that day)<\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><em>\u00b5<\/em> = is the mean average of the range e.g data points from 1-9<\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><em>S<sub>t<\/sub> <\/em>= the difference from current data (<em>X<sub>t<\/sub><\/em>) &#8211; Average (<em>\u00b5<\/em>)&nbsp; + the previous <em>S<sub>t<\/sub><\/em><\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><em>C <\/em>= the critical value that controls the offset (sensitivity) of the detection<\/p>\n\n\n\n<p class=\"sera-block-paragraph\">As mentioned, the&nbsp;<em>C<\/em>&nbsp;value is to control how aggressively you want to detect any increase based on the threshold settings. The threshold&nbsp;<em>T<\/em>&nbsp;is just a value limit against&nbsp;<em>S<sub>t<\/sub><\/em>&nbsp;to indicate if there is an increase happening e.g sales.<\/p>\n\n\n\n<h5 class=\"sera-block-heading\">Sample Data Table<\/h5>\n\n\n\n<p class=\"sera-block-paragraph\">Supposed a company wants to strategize product delivery or offering. That said, the company set a&nbsp;<strong>T<\/strong>arget value (goal) and wants to see if such a strategy increases sales performance. In this scenario, we can use the cumulative sum of different days (running total). Let&nbsp;<em>Xt<\/em>&nbsp;= Sales of the day, 1-9 is the range we want to calculate to determine the&nbsp;<em>St<\/em>&nbsp;of the highlighted in yellow. The mean or average of 1-9 rows from the Xt column is 116, and the critical value chosen is 0 to control its sensitivity. Note that the lower the C the fastest the St to get large, and the larger the harder. So in this example, 0 is viable as we want to detect a sales increase as soon as possible.&nbsp;<\/p>\n\n\n\n<p class=\"sera-block-paragraph\">So if we plugin these number to get the S<sub>t<\/sub> for the row 11 we will get \\(S_t=170 + (250-116-0)\\ \\). Now, since the chosen threshold(T) from this example is 300 and if you do the math for the row number 9, its S<sub>t<\/sub> = 304 and it is greater than 300. As a result, our model detect an increase in sales.<\/p>\n\n\n\n<figure class=\"sera-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1150\" height=\"589\" src=\"https:\/\/portasftpserver.com\/sera-uploads\/2022\/09\/sample-excel-e1663383479847.png\" alt=\"\" class=\"sera-image-18805\" srcset=\"https:\/\/portasftpserver.com\/sera-uploads\/2022\/09\/sample-excel-e1663383479847.png 1150w, https:\/\/portasftpserver.com\/sera-uploads\/2022\/09\/sample-excel-e1663383479847-585x300.png 585w, https:\/\/portasftpserver.com\/sera-uploads\/2022\/09\/sample-excel-e1663383479847-768x393.png 768w, https:\/\/portasftpserver.com\/sera-uploads\/2022\/09\/sample-excel-e1663383479847-100x51.png 100w\" sizes=\"auto, (max-width: 1150px) 100vw, 1150px\" \/><\/figure>\n\n\n\n<p class=\"sera-block-paragraph\"><em>Note.<\/em>&nbsp;Of course, C and T values all depend on the situation as you do not want to falsely make a conclusion too early in a critical situation such as detecting blood sugar or blood pressure changes or alerting everyone in lockdown due to COVID rate, et cetera.<\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Also, do not be confused if some of the S<sub>t<\/sub> is set 0, this is because we only concerns of detecting increase changes. This means that if S<sub>t<\/sub> &lt; 0 , it is no longer relevant to the calculation so it reset to 0. Now, you may be wondering if there is a way to detect decrease, the answer is yes, and all you have to do is to switch the <em>X<sub>t<\/sub><\/em> and  <em>\u00b5<\/em> in the equation.<\/p>\n\n\n\n<p class=\"sera-block-paragraph\">\\(S_t=max\\{0,S_{t-1} + ({\\mu}-X_t-C)\\} \\)<\/p>\n\n\n\n<h5 class=\"sera-block-heading\">Conclusion<\/h5>\n\n\n\n<p class=\"sera-block-paragraph\">In this post, the basic concept of the cumulative sum (CUSUM) has been tackled which should give you a good foundation of how it works based on the use case provided. Also, we familiarize the equation and break down the different parameters, and reflect it in the table example. As a caveat, in critical situation, you should know how to balance the tradeoffs between critical value and threshold and analyze what it means against the baseline to make decisions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A cumulative sum is a way of calculating how a number grows over time. A use case of this is to show how well your company performs based on the distribution metrics, the difference between previous and current values, et cetera. For example, if you want to monitor if the\u00a0free shipping\u00a0has an impact on the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":18710,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[142,206,1],"tags":[249,250,247,248,245,246],"class_list":["post-18708","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science-analytics","category-learning-educations","category-programming-software","tag-cusum-change-detection","tag-cusum-equation","tag-cusum-machine-learning","tag-cusum-time-series","tag-how-to-calculate-cumulative-sum-time-series","tag-how-to-use-cusum"],"_links":{"self":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts\/18708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/comments?post=18708"}],"version-history":[{"count":6,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts\/18708\/revisions"}],"predecessor-version":[{"id":23520,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts\/18708\/revisions\/23520"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/media\/18710"}],"wp:attachment":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/media?parent=18708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/categories?post=18708"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/tags?post=18708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}