<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Archives Analytics - Open Forecasting</title>
	<atom:link href="https://openforecast.org/category/analytics/feed/" rel="self" type="application/rss+xml" />
	<link>https://openforecast.org/category/analytics/</link>
	<description>How to look into the future</description>
	<lastBuildDate>Wed, 07 Jan 2026 17:32:28 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2015/08/cropped-usd-05-32x32.png&amp;nocache=1</url>
	<title>Archives Analytics - Open Forecasting</title>
	<link>https://openforecast.org/category/analytics/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Teaching Statistics and Descriptive Analytics in the world of AI</title>
		<link>https://openforecast.org/2026/01/07/teaching-statistics-and-descriptive-analytics-in-the-world-of-ai/</link>
					<comments>https://openforecast.org/2026/01/07/teaching-statistics-and-descriptive-analytics-in-the-world-of-ai/#respond</comments>
		
		<dc:creator><![CDATA[Ivan Svetunkov]]></dc:creator>
		<pubDate>Wed, 07 Jan 2026 17:32:28 +0000</pubDate>
				<category><![CDATA[Analytics]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[statistics]]></category>
		<category><![CDATA[teaching]]></category>
		<guid isPermaLink="false">https://openforecast.org/?p=3946</guid>

					<description><![CDATA[<p>Teaching statistics as a flipped classroom with the help of AI? You heard that right! That’s exactly what I tried this year &#8211; and here are the results. Attached to this post is the student evaluation score for the module. Yes, the number of responses is quite low (only 50% of the cohort), but it [&#8230;]</p>
<p>Message <a href="https://openforecast.org/2026/01/07/teaching-statistics-and-descriptive-analytics-in-the-world-of-ai/">Teaching Statistics and Descriptive Analytics in the world of AI</a> first appeared on <a href="https://openforecast.org">Open Forecasting</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Teaching statistics as a flipped classroom with the help of AI? You heard that right! That’s exactly what I tried this year &#8211; and here are the results.</p>
<p>Attached to this post is the student evaluation score for the module. Yes, the number of responses is quite low (only 50% of the cohort), but it should still give a sense of how students perceived Statistics and Descriptive Analytics. Of course, this reflects only their impression &#8211; coursework submissions are yet to come &#8211; but it’s still an encouraging sign that some things worked well.</p>
<p>I’ve taught this module since 2018, first with Dave Worthington and later with Alisa Yusupova. Normally, I focused on the second half, covering regression through lectures and workshops. But this year, I took on the full module and realised I didn’t want to teach probability theory and statistics in the traditional way &#8211; long monologues in lectures followed by awkward silence in workshops. That format, I believe, no longer works. After all, students can always ask their favourite LLM to explain concepts they don&#8217;t understand. And some don&#8217;t even do that &#8211; they just ask to solve problems without understanding them. So, what can be done in this brave new world?</p>
<p>I don’t yet have a definitive answer &#8211; only the results of an experiment.</p>
<p>Lectures. This year, I used Google Notebook ML to prepare lecture materials. I provided my existing notes, slides, and relevant texts, then asked it to produce podcasts on specific topics. This took more time than expected, as I had to review the generated content, adjust prompts, and refine focus areas, listening to the podcasts over and over again. Once ready, I uploaded the materials on Moodle and asked students to listen beforehand. In class, we skipped formal lectures and instead had whiteboard &#038; marker discussions. I asked questions, showed derivations, and encouraged debate. With a class of 26 students, it was possible to create much more interaction than in previous years.</p>
<p>Workshops. We still had problem-solving sessions, but I allowed (actually encouraged) students to use LLMs to solve tasks and explain why the solutions were correct. The aim was to emphasise reasoning and assumptions over simply obtaining the right number. This worked with mixed success, and I still need to think how it can be improved further.</p>
<p>Did it work overall?</p>
<p>I&#8217;m not entirely sure. Not all students engaged with the materials in advance, but those who did seemed to benefit and appreciated the approach. What I do know is that the &#8220;two-hour monologue while everyone tries not to fall asleep&#8221; format does not work any more. For universities, and for the (very!) expensive UK education, to remain relevant, we must innovate and rethink how we teach.</p>
<p>What would you change if you were teaching a technical subject at university in the era of AI? I’d love to hear your ideas.</p>
<p>Message <a href="https://openforecast.org/2026/01/07/teaching-statistics-and-descriptive-analytics-in-the-world-of-ai/">Teaching Statistics and Descriptive Analytics in the world of AI</a> first appeared on <a href="https://openforecast.org">Open Forecasting</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://openforecast.org/2026/01/07/teaching-statistics-and-descriptive-analytics-in-the-world-of-ai/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Forecasting method vs forecasting model: what&#8217;s difference?</title>
		<link>https://openforecast.org/2020/06/08/forecasting-method-vs-forecasting-model-what-s-difference/</link>
					<comments>https://openforecast.org/2020/06/08/forecasting-method-vs-forecasting-model-what-s-difference/#respond</comments>
		
		<dc:creator><![CDATA[Ivan Svetunkov]]></dc:creator>
		<pubDate>Mon, 08 Jun 2020 18:24:43 +0000</pubDate>
				<category><![CDATA[Analytics]]></category>
		<category><![CDATA[Theory of forecasting]]></category>
		<category><![CDATA[extrapolation methods]]></category>
		<category><![CDATA[theory]]></category>
		<guid isPermaLink="false">https://openforecast.org/?p=2403</guid>

					<description><![CDATA[<p>If you work in the field of statistics, analytics, data science or forecasting, then you probably have already noticed that some of the instruments that are used in your field are called &#8220;methods&#8221;, while the others are called &#8220;models&#8221;. The issue here is that the people, using these terms, usually know the distinction between them, [&#8230;]</p>
<p>Message <a href="https://openforecast.org/2020/06/08/forecasting-method-vs-forecasting-model-what-s-difference/">Forecasting method vs forecasting model: what&#8217;s difference?</a> first appeared on <a href="https://openforecast.org">Open Forecasting</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you work in the field of statistics, analytics, data science or forecasting, then you probably have already noticed that some of the instruments that are used in your field are called &#8220;methods&#8221;, while the others are called &#8220;models&#8221;. The issue here is that the people, using these terms, usually know the distinction between them, but rarely explain it to the others, implying that this is obvious. Well, it is, when you have worked in the field for several years. But it isn&#8217;t if you are a novice, who has only started the introduction to the statistical topics. So, I&#8217;ve decided to write this post in order to propose my understanding of the two terms, specifically focusing on the context of forecasting.</p>
<p>Cambridge dictionary <a href="https://dictionary.cambridge.org/dictionary/english/method" rel="noopener noreferrer" target="_blank">defines method</a> as a particular way of doing something, which is actually also quite a good definition for the &#8220;forecasting method&#8221;. For example, Simple Exponential Smoothing (SES) is a method, because it is a way of getting point forecasts. It does not have any specific assumptions and is based on a simple principle of filtering / smoothing the available data. See for yourself, here is the formula for SES:<br />
\begin{equation} \label{eq:SES}<br />
	\hat{y}_{t+1} = \alpha y_{t} + (1-\alpha) \hat{y}_{t},<br />
\end{equation}<br />
where \(y_{t}\) is the actual value, \(\hat{y}_{t}\) is the predicted value on observation \(t\) and \(\alpha\) is the smoothing parameter (which is traditionally selected from the range (0, 1)). SES is very simple, it produces fast and quite accurate forecasts for the level data, but it does not explain, where the randomness in the data comes from. No wonder, because this is just a particular way of getting point forecasts.</p>
<p>Now, what about the model? I like the definition from the <a href="https://doi.org/10.1057/jors.2009.141" rel="noopener noreferrer" target="_blank">paper of Pidd (2010)</a>, which actually comes from his book &#8220;<a href="https://www.wiley.com/en-gb/Tools+for+Thinking%3A+Modelling+in+Management+Science%2C+3rd+Edition-p-9780470721421" rel="noopener noreferrer" target="_blank">Tools for Thinking: Modelling in Management Science</a>&#8220;: &#8220;<em>model is an external and explicit representation of part of reality as seen by the people who wish to use that model to understand, to change, to manage and to control that part of reality</em>&#8220;. There are several important elements in this definition:</p>
<ul>
<li>&#8220;<em>representation of part of reality</em>&#8221; &#8211; we cannot create a model of everything, we need to focus on something. Inevitably, the model is a simplification and it is needed in order to get some insights about a specific aspect of a real phenomenon;</li>
<li>&#8220;<em>an external and explicit representation</em>&#8221; &#8211; model is something that is clearly defined. Your thoughts are just thoughts until you formalise them;</li>
<li>&#8220;<em>use that model to understand, to change, to manage and to control</em>&#8221; &#8211; models need to have a purpose. Yes, there are those that <a href="/en/2020/03/23/forecasting-for-the-sake-of-forecasting/" rel="noopener">are not useful</a>, created just for the sake of themselves, but arguably they are at least created for fun / hype, which is already a purpose;</li>
<li>Finally, &#8220;<em>as seen by the people who wish to use that model</em>&#8221; &#8211; models are subjective and depend on who creates them. Model created by my friend <a href="http://kourentzes.com/forecasting/" rel="noopener noreferrer" target="_blank">Nikos</a> might differ substantially from a model created by me, just because we have different points of view.</li>
</ul>
<p>There are different ways of classifying models, I like the following one, based on the model complexity / level of formalisation (from simpler to more complicated):</p>
<ol>
<li>Textual &#8211; those that are only described using words;</li>
<li>Visual &#8211; those that are expressed via visual elements (images, figures, graphs);</li>
<li>Mathematical &#8211; the ones, represented with mathematical formulae;</li>
<li>Imitation &#8211; small, simplified copies of a real object / phenomenon;</li>
</ol>
<p>For example, the classification of models above is a <strong>textual model</strong> on its own. It is a simplified representation of reality created for a specific purpose (in order to better understand what model is).</p>
<p>Here is an example of a <strong>visual model</strong>:<br />
<div id="attachment_1914" style="width: 310px" class="wp-caption aligncenter"><a href="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpread.png&amp;nocache=1"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-1914" src="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpread-300x300.png&amp;nocache=1" alt="" width="300" height="300" class="size-medium wp-image-1914" srcset="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpread-300x300.png&amp;nocache=1 300w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpread-150x150.png&amp;nocache=1 150w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpread.png&amp;nocache=1 700w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-1914" class="wp-caption-text">Spread matrix</p></div>
This is a model that shows the relations between different variables using such visual instruments (models) as <a href="/en/2019/01/07/marketing-analytics-with-greybox/" rel="noopener noreferrer" target="_blank">scatterplot, boxplot and tableplot</a>.</p>
<p>Examples of <strong>imitation models</strong> include models of buildings, cities, cars (<a href="https://www.google.com/search?q=model+cars&#038;tbm=isch&#038;ved=2ahUKEwjzm8_SqPLpAhUSNBQKHeEXAvYQ2-cCegQIABAA&#038;oq=model+cars&#038;gs_lcp=CgNpbWcQAzICCAAyAggAMgIIADICCAAyAggAMgIIADICCAAyAggAMgIIADICCAA6BQgAELEDUN2OAViAoAFg3aEBaAFwAHgAgAFriAHrA5IBAzUuMZgBAKABAaoBC2d3cy13aXotaW1n&#038;sclient=img&#038;ei=NzzeXrOkFpLoUOGviLAP&#038;bih=764&#038;biw=1536&#038;client=ubuntu" rel="noopener noreferrer" target="_blank">like this</a>) etc, simulation models, focus groups and other. They are not exact copies of the real objects, but they imitate some of their aspects (the most important ones for specific purposes). For instance, a model of a car might be needed in order to understand, how the final product will look without constructing the proper vehicle. This way we simplify the process and get an understanding about some aspects of a phenomenon of interest.</p>
<p>And here is a simple <strong>mathematical model</strong> (in our case, this is a statistical one):<br />
\begin{equation} \label{eq:Model}<br />
	{y}_{t} = \mu_t + \epsilon_{t},<br />
\end{equation}<br />
where \(\mu_t\) is the structure of the data, and \(\epsilon_{t}\) is the noise. This model represents a real data in a simplified form (e.g. the sales of a product can be explained using some structure and some unpredictable random fluctuations). It represents specific aspects of reality, it is created for purposes of analysis / forecasting, it is explicit, and it is created by me.</p>
<p>If we compare the model \eqref{eq:Model} with the method \eqref{eq:SES}, we might notice the important difference between them: the method does not explain what happens in the data, it just has a way of producing forecasts, while the model does a decomposition into structure and noise that allows looking into the process. This is the main difference between the two terms.</p>
<p>Now, moving this discussion to the forecasting domain, there are not many papers that acknowledge the difference between these terms explicitly. <a href="https://www.jstor.org/stable/2681090" rel="noopener noreferrer" target="_blank">Chatfield et al. (2001)</a> is one of the few sources that I know of that defines them properly: &#8220;<em>&#8230;[forecasting] method, meaning a computational procedure for producing forecasts, and a [forecasting] model, meaning a mathematical representation of reality</em>&#8220;. When John Boylan and I discussed these definitions, we have agreed that we were not satisfied with the one for the model, because it is too loose and might lead to confusion. For example, according to it, the following forecasting method might be erroneously considered as a model:<br />
\begin{equation}<br />
\begin{aligned}<br />
	{y}_{t} = &#038; \eta_{t}, \text{where } \eta_{t} \sim \mathcal{Poisson}(\hat{y}_{t-1}-1)+1 \\<br />
	\hat{y}_{t} = &#038; \alpha {y}_{t-1} + (1-\alpha) \hat{y}_{t-1}<br />
\end{aligned} \label{eq:NotAModel}<br />
\end{equation}<br />
This is not a model, because it does not represent the reality, it uses the fitted values from previous observations in order to generate new ones. It does not explain, what the components in the data are and how they interact with each other, it is just a computational procedure for producing a distribution of values for forecasting purposes. Thus \eqref{eq:NotAModel} is a forecasting method, not a model. So, in our <a href="https://openforecast.org/en/2020/01/25/multiplicative-state-space-models-for-intermittent-time-series-2019/">paper on iETS model</a>, John and I have come up with the following two definitions:</p>
<ul>
<li>&#8220;&#8230;we define a <strong>forecasting model</strong> as a mathematical representation of a real phenomenon with a complete specification of distribution and parameters&#8221;;</li>
<li>&#8220;A <strong>forecasting method</strong> is a mathematical procedure that generates point and / or interval forecasts, with or without a forecasting model&#8221;.</li>
</ul>
<p>Note the difference between &#8220;mathematical representation&#8221; and &#8220;mathematical procedure&#8221; in the two definitions, and also note the stress on &#8220;complete specification of distribution and parameters&#8221; in the first one. This way we can distinguish forecasting model \eqref{eq:Model} from the forecasting method \eqref{eq:NotAModel}. And according to this definition, the following (based on \eqref{eq:NotAModel}) can be considered as a forecasting model:<br />
\begin{equation}<br />
\begin{aligned}<br />
	{y}_{t} = &#038; \eta_{t}, \text{where } \eta_{t} \sim \mathcal{Poisson}(\mu_{t}) \\<br />
	\mu_{t} = &#038; \mu_{t-1}(1 + \alpha \epsilon_t) ,<br />
\end{aligned} \label{eq:AProperModel}<br />
\end{equation}<br />
where \(\mu_{t}\) is the structure and \(\epsilon_t\) is the random variable that follows some distribution.</p>
<p><!-- As a side note, there is also a difference between the <strong>true</strong> and the <strong>applied</strong> models. This <a href="/en/2016/06/25/true-model/">was covered in one of the earlier posts</a> on this website, so long story short, the "true model" is a statistical model that represents reality for the "population data" (imagine the situation, when we know all the data in the universe), while the applied one is the model that we use for the specific sample of data. --></p>
<p>I hope that we now understand the difference between the two terms, but I am sure that some of the readers of my blog are wondering: why bother to distinguish the two terms? This is because the forecasting methods either don&#8217;t make assumptions or make very few of them about the data, while the proper statistical models are based on some specific ones and can be quite restrictive. This can be strength and / or weakness for both of them. For example, SES can be applied to a wide variety of data, and will produce point forecasts, no matter what. But on its own, it won&#8217;t give you information about the uncertainty in the data, or how to properly estimate the model, or how to include some explanatory variables, or how to select between SES and Holt&#8217;s methods. At the same time, <a href="/en/2016/11/02/smooth-package-for-r-es-function-part-ii-pure-additive-models/">ETS(A,N,N)</a> being a model underlying SES, can do all those things, but relies on the assumption of normality of the error term, along with several other typical for statistical models (such as homoscedastic and uncorrelated residuals, correct model specification, no influential outliers etc).</p>
<p>As you probably have already realised, there is no point in arguing, which of the two is better &#8211; both instruments are useful for different purposes. We should use whatever is suitable for each separate situation, but it might be important to understand the difference between the terms, if we want to make the world a better place.</p>
<p>Message <a href="https://openforecast.org/2020/06/08/forecasting-method-vs-forecasting-model-what-s-difference/">Forecasting method vs forecasting model: what&#8217;s difference?</a> first appeared on <a href="https://openforecast.org">Open Forecasting</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://openforecast.org/2020/06/08/forecasting-method-vs-forecasting-model-what-s-difference/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Analytics with greybox</title>
		<link>https://openforecast.org/2019/01/07/marketing-analytics-with-greybox/</link>
					<comments>https://openforecast.org/2019/01/07/marketing-analytics-with-greybox/#comments</comments>
		
		<dc:creator><![CDATA[Ivan Svetunkov]]></dc:creator>
		<pubDate>Mon, 07 Jan 2019 16:40:17 +0000</pubDate>
				<category><![CDATA[Analytics]]></category>
		<category><![CDATA[Package greybox for R]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[greybox]]></category>
		<category><![CDATA[regression]]></category>
		<guid isPermaLink="false">https://openforecast.org/?p=1893</guid>

					<description><![CDATA[<p>One of the reasons why I have started the greybox package is to use it for marketing research and marketing analytics. The common problem that I face, when working with these courses is analysing the data measured in different scales. While R handles numeric scales natively, the work with categorical is not satisfactory. Yes, I [&#8230;]</p>
<p>Message <a href="https://openforecast.org/2019/01/07/marketing-analytics-with-greybox/">Analytics with greybox</a> first appeared on <a href="https://openforecast.org">Open Forecasting</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>One of the reasons why I have started the <span class="lang:r decode:true crayon-inline">greybox</span> package is to use it for marketing research and marketing analytics. The common problem that I face, when working with these courses is analysing the data measured in different scales. While R handles numeric scales natively, the work with categorical is not satisfactory. Yes, I know that there are packages that implement some of the functions, but I wanted to have them in one place without the need to install a lot of packages and satisfy the dependencies. After all, what&#8217;s the point in installing a package for Cramer&#8217;s V, when it can be calculated with two lines of code? So, here&#8217;s a brief explanation of the functions for marketing analytics in <span class="lang:r decode:true crayon-inline">greybox</span>.</p>
<p>I will use `mtcars` dataset for the examples, but we will transform some of the variables into factors:</p>
<pre class="decode">mtcarsData &lt;- as.data.frame(mtcars)
mtcarsData$vs &lt;- factor(mtcarsData$vs, levels=c(0,1), labels=c("v","s"))
mtcarsData$am &lt;- factor(mtcarsData$am, levels=c(0,1), labels=c("a","m"))</pre>
<p><em>All the functions discussed in this post are available in <span class="lang:r decode:true crayon-inline">greybox</span> starting from v0.4.0. However, I&#8217;ve found several bugs since the submission to CRAN, and the most recent version with bugfixes is now <a href="https://github.com/config-i1/greybox" rel="noopener noreferrer" target="_blank">available on github</a>.</em></p>
<h2>Analysing the relation between the two variables in categorical scales</h2>
<h3>Cramer&#8217;s V</h3>
<p>Cramer&#8217;s V measures the relation between two variables in categorical scale. It is implemented in the <span class="lang:r decode:true crayon-inline">cramer()</span> function. It returns the value in a range of 0 to 1 (1 &#8211; when the two categorical variables are linearly associated with each other, 0 &#8211; otherwise), Chi-Squared statistics from the <span class="lang:r decode:true crayon-inline">chisq.test()</span>, the respective p-value and the number of degrees of freedom. The tested hypothesis in this case is formulated as:<br />
\begin{matrix}<br />
H_0: V = 0 \text{ (the variables don&#8217;t have association);} \\<br />
H_1: V \neq 0 \text{ (there is an association between the variables).}<br />
\end{matrix}</p>
<p>Here&#8217;s what we get when trying to find the association between the engine and transmission in the `mtcars` data:</p>
<pre class="decode">cramer(mtcarsData$vs, mtcarsData$am)</pre>
<pre>Cramer's V: 0.1042
Chi^2 statistics = 0.3475, df: 1, p-value: 0.5555</pre>
<p>Judging by this output, the association between these two variables is very low (close to zero) and is not statistically significant.</p>
<p>Cramer&#8217;s V can also be used for the data in numerical scales. In general, this might be not the most suitable solution, but this might be useful when you have a small number of values in the data. For example, the variable `gear` in `mtcars` is numerical, but it has only three options (3, 4 and 5). Here&#8217;s what Cramer&#8217;s V tells us in the case of `gear` and `am`:</p>
<pre class="decode">cramer(mtcarsData$am, mtcarsData$gear)</pre>
<pre>Cramer's V: 0.809
Chi^2 statistics = 20.9447, df: 2, p-value: 0</pre>
<p>As we see, the value is high in this case (0.809), and the null hypothesis is rejected on 5% level. So we can conclude that there is a relation between the two variables. This does not mean that one variable causes the other one, but they both might be driven by something else (do more expensive cars have less gears but the automatic transmission?).</p>
<h3>Plotting categorical variables</h3>
<p>While R allows plotting two categorical variables against each other, the plot is hard to read and is not very helpful (in my opinion):</p>
<pre class="decode">plot(table(mtcarsData$am,mtcarsData$gear))</pre>
<div id="attachment_1912" style="width: 310px" class="wp-caption alignnone"><a href="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsPlot.png&amp;nocache=1"><img decoding="async" aria-describedby="caption-attachment-1912" src="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsPlot-300x300.png&amp;nocache=1" alt="" width="300" height="300" class="size-medium wp-image-1912" srcset="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsPlot-300x300.png&amp;nocache=1 300w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsPlot-150x150.png&amp;nocache=1 150w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsPlot.png&amp;nocache=1 700w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-1912" class="wp-caption-text">Default plot of a table</p></div>
<p>So I have created a function that produces a heat map for two categorical variables. It is called <span class="lang:r decode:true crayon-inline">tableplot()</span>:</p>
<pre class="decode">tableplot(mtcarsData$am,mtcarsData$gear)</pre>
<div id="attachment_1915" style="width: 310px" class="wp-caption alignnone"><a href="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsTableplot.png&amp;nocache=1"><img decoding="async" aria-describedby="caption-attachment-1915" src="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsTableplot-300x300.png&amp;nocache=1" alt="" width="300" height="300" class="size-medium wp-image-1915" srcset="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsTableplot-300x300.png&amp;nocache=1 300w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsTableplot-150x150.png&amp;nocache=1 150w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsTableplot.png&amp;nocache=1 700w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-1915" class="wp-caption-text">Tableplot for the two categorical variables</p></div>
<p>It is based on <span class="lang:r decode:true crayon-inline">table()</span> function and uses the frequencies inside the table for the colours:</p>
<pre class="decode">table(mtcarsData$am,mtcarsData$gear) / length(mtcarsData$am)</pre>
<pre>        3       4       5
a 0.46875 0.12500 0.00000
m 0.00000 0.25000 0.15625</pre>
<p>The darker sectors mean that there is a higher concentration of values, while the white ones correspond to zeroes. So, in our example, we see that the majority of cars have automatic transmissions with three gears. Furthermore, the plot shows that there is some sort of relation between the two variables: the cars with automatic transmissions have the lower number of gears, while the ones with the manual have the higher number of gears (something we&#8217;ve already noticed in the previous subsection).</p>
<h2>Association between the categorical and numerical variables</h2>
<p>While Cramer&#8217;s V can also be used for the measurement of association between the variables in different scales, there are better instruments. For example, some analysts recommend using intraclass correlation coefficient when measuring the relation between the numerical and categorical variables. But there is a simpler option, which involves calculating the coefficient of multiple correlation between the variables. This is implemented in <span class="lang:r decode:true crayon-inline">mcor()</span> function of <span class="lang:r decode:true crayon-inline">greybox</span>. The `y` variable should be numerical, while `x` can be of any type. What the function then does is expands all the factors and runs a regression via <span class="lang:r decode:true crayon-inline">.lm.fit()</span> function, returning the square root of the coefficient of determination. If the variables are linearly related, then the returned value will be close to one. Otherwise it will be closet to zero. The function also returns the F statistics from the regression, the associated p-value and the number of degrees of freedom (the hypothesis is formulated similarly to <span class="lang:r decode:true crayon-inline">cramer()</span> function).</p>
<p>Here&#8217;s how it works:</p>
<pre class="decode">mcor(mtcarsData$am,mtcarsData$mpg)</pre>
<pre>Multiple correlations value: 0.5998
F-statistics = 16.8603, df: 1, df resid: 30, p-value: 3e-04</pre>
<p>In this example, the simple linear regression of mpg from the set of dummies is constructed, and we can conclude that there is a linear relation between the variables, and that this relation is statistically significant.</p>
<h2>Association between several variables</h2>
<h3>Measures of association</h3>
<p>When you deal with datasets (i.e. data frames or matrices), then you can use <span class="lang:r decode:true crayon-inline">cor()</span> function in order to calculate the correlation coefficients between the variables in the data. But when you have a mixture of numerical and categorical variables, the situation becomes more difficult, as the correlation does not make sense for the latter. This motivated me to create a function that uses either <span class="lang:r decode:true crayon-inline">cor()</span>, or <span class="lang:r decode:true crayon-inline">cramer()</span>, or <span class="lang:r decode:true crayon-inline">mcor()</span> functions depending on the types of data (see discussions of <span class="lang:r decode:true crayon-inline">cramer()</span> and <span class="lang:r decode:true crayon-inline">mcor()</span> above). The function is called <span class="lang:r decode:true crayon-inline">association()</span> or <span class="lang:r decode:true crayon-inline">assoc()</span> and returns three matrices: the values of the measures of association, their p-values and the types of the functions used between the variables. Here&#8217;s an example:</p>
<pre class="decode">assocValues &lt;- assoc(mtcarsData)
print(assocValues,digits=2)</pre>
<pre> Associations: 
 values:
        mpg  cyl  disp    hp  drat    wt  qsec   vs   am gear carb
 mpg   1.00 0.86 -0.85 -0.78  0.68 -0.87  0.42 0.66 0.60 0.66 0.67
 cyl   0.86 1.00  0.92  0.84  0.70  0.78  0.59 0.82 0.52 0.53 0.62
 disp -0.85 0.92  1.00  0.79 -0.71  0.89 -0.43 0.71 0.59 0.77 0.56
 hp   -0.78 0.84  0.79  1.00 -0.45  0.66 -0.71 0.72 0.24 0.66 0.79
 drat  0.68 0.70 -0.71 -0.45  1.00 -0.71  0.09 0.44 0.71 0.83 0.33
 wt   -0.87 0.78  0.89  0.66 -0.71  1.00 -0.17 0.55 0.69 0.66 0.61
 qsec  0.42 0.59 -0.43 -0.71  0.09 -0.17  1.00 0.74 0.23 0.63 0.67
 vs    0.66 0.82  0.71  0.72  0.44  0.55  0.74 1.00 0.10 0.62 0.69
 am    0.60 0.52  0.59  0.24  0.71  0.69  0.23 0.10 1.00 0.81 0.44
 gear  0.66 0.53  0.77  0.66  0.83  0.66  0.63 0.62 0.81 1.00 0.51
 carb  0.67 0.62  0.56  0.79  0.33  0.61  0.67 0.69 0.44 0.51 1.00
 
 p-values:
       mpg  cyl disp   hp drat   wt qsec   vs   am gear carb
 mpg  1.00 0.00 0.00 0.00 0.00 0.00 0.02 0.00 0.00 0.00 0.01
 cyl  0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.01 0.00 0.01
 disp 0.00 0.00 1.00 0.00 0.00 0.00 0.01 0.00 0.00 0.00 0.07
 hp   0.00 0.00 0.00 1.00 0.01 0.00 0.00 0.00 0.18 0.00 0.00
 drat 0.00 0.00 0.00 0.01 1.00 0.00 0.62 0.01 0.00 0.00 0.66
 wt   0.00 0.00 0.00 0.00 0.00 1.00 0.34 0.00 0.00 0.00 0.02
 qsec 0.02 0.00 0.01 0.00 0.62 0.34 1.00 0.00 0.21 0.00 0.01
 vs   0.00 0.00 0.00 0.00 0.01 0.00 0.00 1.00 0.56 0.00 0.01
 am   0.00 0.01 0.00 0.18 0.00 0.00 0.21 0.56 1.00 0.00 0.28
 gear 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.09
 carb 0.01 0.01 0.07 0.00 0.66 0.02 0.01 0.01 0.28 0.09 1.00
 
 types:
      mpg    cyl      disp   hp     drat   wt     qsec   vs       am      
 mpg  "none" "mcor"   "cor"  "cor"  "cor"  "cor"  "cor"  "mcor"   "mcor"  
 cyl  "mcor" "none"   "mcor" "mcor" "mcor" "mcor" "mcor" "cramer" "cramer"
 disp "cor"  "mcor"   "none" "cor"  "cor"  "cor"  "cor"  "mcor"   "mcor"  
 hp   "cor"  "mcor"   "cor"  "none" "cor"  "cor"  "cor"  "mcor"   "mcor"  
 drat "cor"  "mcor"   "cor"  "cor"  "none" "cor"  "cor"  "mcor"   "mcor"  
 wt   "cor"  "mcor"   "cor"  "cor"  "cor"  "none" "cor"  "mcor"   "mcor"  
 qsec "cor"  "mcor"   "cor"  "cor"  "cor"  "cor"  "none" "mcor"   "mcor"  
 vs   "mcor" "cramer" "mcor" "mcor" "mcor" "mcor" "mcor" "none"   "cramer"
 am   "mcor" "cramer" "mcor" "mcor" "mcor" "mcor" "mcor" "cramer" "none"  
 gear "mcor" "cramer" "mcor" "mcor" "mcor" "mcor" "mcor" "cramer" "cramer"
 carb "mcor" "cramer" "mcor" "mcor" "mcor" "mcor" "mcor" "cramer" "cramer"
      gear     carb    
 mpg  "mcor"   "mcor"  
 cyl  "cramer" "cramer"
 disp "mcor"   "mcor"  
 hp   "mcor"   "mcor"  
 drat "mcor"   "mcor"  
 wt   "mcor"   "mcor"  
 qsec "mcor"   "mcor"  
 vs   "cramer" "cramer"
 am   "cramer" "cramer"
 gear "none"   "cramer"
 carb "cramer" "none"</pre>
<p>One thing to note is that the function considers numerical variables as categorical, when they only have up to 10 unique values. This is useful, for example, in case of number of `gears` in the dataset.</p>
<h2>Plots of association between several variables</h2>
<p>Similarly to the problem with <span class="lang:r decode:true crayon-inline">cor()</span>, scatterplot matrix (produced using <span class="lang:r decode:true crayon-inline">plot()</span>) is not meaningful in case of a mixture of variables:</p>
<pre class="decode">plot(mtcarsData)</pre>
<div id="attachment_1913" style="width: 310px" class="wp-caption alignnone"><a href="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsScatter.png&amp;nocache=1"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-1913" src="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsScatter-300x300.png&amp;nocache=1" alt="" width="300" height="300" class="size-medium wp-image-1913" srcset="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsScatter-300x300.png&amp;nocache=1 300w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsScatter-150x150.png&amp;nocache=1 150w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsScatter.png&amp;nocache=1 700w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-1913" class="wp-caption-text">Default scatter plot matrix</p></div>
<p>It makes sense to use scatterplot in case of numeric variables, <span class="lang:r decode:true crayon-inline">tableplot()</span> in case of categorical and <span class="lang:r decode:true crayon-inline">boxplot()</span> in case of a mixture. So, there is the function <span class="lang:r decode:true crayon-inline">spread()</span> in <span class="lang:r decode:true crayon-inline">greybox</span> that creates something more meaningful. It uses the same algorithm as <span class="lang:r decode:true crayon-inline">assoc()</span> function, but produces plots instead of calculating measures of association. So, `gear` will be considered as categorical and the function will produce either <span class="lang:r decode:true crayon-inline">boxplot()</span> or <span class="lang:r decode:true crayon-inline">tableplot()</span>, when plotting it against other variables.</p>
<p>Here&#8217;s an example:</p>
<pre class="decode">spread(mtcarsData)</pre>
<div id="attachment_1914" style="width: 310px" class="wp-caption alignnone"><a href="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpread.png&amp;nocache=1"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-1914" src="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpread-300x300.png&amp;nocache=1" alt="" width="300" height="300" class="size-medium wp-image-1914" srcset="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpread-300x300.png&amp;nocache=1 300w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpread-150x150.png&amp;nocache=1 150w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpread.png&amp;nocache=1 700w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-1914" class="wp-caption-text">Spread matrix</p></div>
<p>This plot demonstrates, for example, that the number of carburetors influences fuel consumption (something that we could not have spotted in the case of <span class="lang:r decode:true crayon-inline">plot()</span>). Notice also, that the number of gears influences the fuel consumption in a non-linear relation as well. So constructing the model with dummy variables for the number of gears might be a reasonable thing to do.</p>
<p>The function also has the parameter `log`, which will transform all the numerical variables using logarithms, which is handy, when you suspect the non-linear relation between the variables. Finally, there is a parameter `histogram`, which will plot either histograms, or barplots on the diagonal.</p>
<pre class="decode">spread(mtcarsData, histograms=TRUE, log=TRUE)</pre>
<div id="attachment_1921" style="width: 310px" class="wp-caption alignnone"><a href="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpreadLogs.png&amp;nocache=1"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-1921" src="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpreadLogs-300x300.png&amp;nocache=1" alt="" width="300" height="300" class="size-medium wp-image-1921" srcset="https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpreadLogs-300x300.png&amp;nocache=1 300w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpreadLogs-150x150.png&amp;nocache=1 150w, https://openforecast.org/wp-content/webpc-passthru.php?src=https://openforecast.org/wp-content/uploads/2019/01/mtcarsSpreadLogs.png&amp;nocache=1 700w" sizes="auto, (max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-1921" class="wp-caption-text">Spread matrix in logs</p></div>
<p>The plot demonstrates that the `disp` has a strong non-linear relation with `mpg`, and, similarly, `drat` and `hp` also influence `mpg` in a non-linear fashion.</p>
<h2>Regression diagnostics</h2>
<p>One of the problems of linear regression that can be diagnosed prior to the model construction is multicollinearity. The conventional way of doing this diagnostics is via calculating the variance inflation factor (VIF) after constructing the model. However, VIF is not easy to interpret, because it lies in \((1,\infty)\). Coefficients of determination from the linear regression models of explanatory variables are easier to interpret and work with. If such a coefficient is equal to one, then there are some perfectly correlated explanatory variables in the dataset. If it is equal to zero, then they are not linearly related.</p>
<p>There is a function <span class="lang:r decode:true crayon-inline">determination()</span> or <span class="lang:r decode:true crayon-inline">determ()</span> in <span class="lang:r decode:true crayon-inline">greybox</span> that returns the set of coefficients of determination for the explanatory variables. The good thing is that this can be done before constructing any model. In our example, the first column, `mpg` is the response variable, so we can diagnose the multicollinearity the following way:</p>
<pre class="decode">determination(mtcarsData[,-1])</pre>
<pre>       cyl      disp        hp      drat        wt      qsec        vs 
 0.9349544 0.9537470 0.8982917 0.7036703 0.9340582 0.8671619 0.8017720 
        am      gear      carb 
 0.7924392 0.8133441 0.8735577</pre>
<p>As we can see from the output above, `disp` is the most linearly related with the variables, so including it in the model might cause the multicollinearity, which will decrease the efficiency of the estimates of parameters.</p>
<p>Message <a href="https://openforecast.org/2019/01/07/marketing-analytics-with-greybox/">Analytics with greybox</a> first appeared on <a href="https://openforecast.org">Open Forecasting</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://openforecast.org/2019/01/07/marketing-analytics-with-greybox/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
