# Cointegration for Time Series Analysis

This post originally appeared in Ro’s Data Team blog.

Stationarity is a crucial property for time series modeling. The problem is, in practice, very few phenomena are actually stationary in their original form. The trick is to employ the right technique for reframing the time series into a stationary form. One such technique leverages a statistical property called cointegration. Cointegration forms a synthetic stationary series from a linear combination of two or more non-stationary series.

We’ll use simulated data to demonstrate the main points behind cointegration in R. The sources Tsay [2005], Pfaff et al. …

# Cointegration for Time Series Analysis

Stationarity is a crucial property for time series modeling. The problem is, in practice, very few phenomena are actually stationary in their original form. The trick is to employ the right technique for reframing the time series into a stationary form. One such technique leverages a statistical property called cointegration. Cointegration forms a synthetic stationary series from a linear combination of two or more non-stationary series.

We’ll use simulated data to demonstrate the main points behind cointegration in R. …

# Looker Time-Series Alerting with Dynamic Thresholds

Looker 6.24 introduced conditional alerting for dashboard content. The new feature fills a much-need gap beyond the standard scope of “scheduled looks”, but at first glance appears limited to static threshold alerting. Here we demonstrate how one can leverage the feature’s underlying flexibility to create advanced alerts with self-adaptive thresholds.

Some examples of how this dynamic alerting can be used include:

• Identify bugs and achieve faster incident response times with dynamic thresholds around hourly volume in different areas of a system (website traffic, order creations, etc.).
• Recognizing demand spikes for resource allocation (call center, order fulfillment, etc.)
• Warning thresholds before breaching critical SLAs (inquiry response times, order fulfillment delay, etc.)

# Measuring Correlation — simple techniques for categorical, discrete, and continuous data

A 5 minute, formula-free refresher on your favorite undervalued tools for data analysis!

## Choosing the right tool for the job

Here are the four main ways to measure correlation, depending on what types of variables you have.

This boils down to just three main tests, so the trick is framing both your question and data in a workable format for either:

• Chi-squared test for independence — Compare proportions in groups
• Analysis of variance (ANOVA) — Analyze differences in group means
• Pearson’s correlation coefficient — Check for a linear relationship

We see that the chi-squared test is suitable whenever both of you explanatory and response variables are categorical, since we are comparing the frequency of some distinct response occurring in each group. Chi-squared is also (usually) suitable with a quantitative explanatory variable, once it is discretized into appropriate categories for your analysis. ANOVA is useful when comparing the average of a quantitative variable across different group categories. Lastly, Pearson’s correlation coefficient quantifies linear relationships between two quantitative variables. …

# Purpose

We’ll implement an end-to-end system that tracks variable costs for different goods sold at a transaction level. The results give a detailed view of variable costs to help with strategic decision making for departments like procurement, supply chain, and inventory management.

The files for this case-study can be found here: GitHub Repository Ro-COGS-Tracking.

Disclaimer: The case study and datasets are completely made up for the sake of demonstrating how to implement a COGS tracking system.

# Motivation

Controlling Cost of Goods Sold (COGS hereafter) is a requirement for running a sustainable business. Many factors play into COGS so they are often measured at a high-level, which consequentially sacrifices any insights into costs that change across products and transactions. Therefore, it is advantageous for companies to manage their costs at a granular level to continue delivering superior services in a sustainable manner. …