<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/what-can-we-learn-from-the-statistics-of-the-euro-2016-application-of-factor-analysis/"></div></div><div><a data-url="http://www.r-bloggers.com/what-can-we-learn-from-the-statistics-of-the-euro-2016-application-of-factor-analysis/" data-counturl="http://www.r-bloggers.com/what-can-we-learn-from-the-statistics-of-the-euro-2016-application-of-factor-analysis/" data-count="horizontal" data-text="What can we learn from the statistics of the EURO 2016 – Application of factor analysis" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://datascienceplus.com/what-can-we-learn-from-the-statistics-of-the-euro-2016-application-of-factor-analysis/"> DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In this post I will try to explain how to perform a factor analysis (FA) on the statistics of the teams in the first round of Euro cup 2016. Meanwhile, I assume that you have enough background on the theory of FA and so I will just stick with the application of this technique.</p>
<p>Wikipedia defines the factor analysis as “A statistical method used to describe variability among observed, correlated variables in terms of a potentially lower number of unobserved variables called factors.” So according to this definition I can say, I will try to define some new latent variables that would compress all our information into one or two factors (I call them here as a score) and help to make better predictions for the next round.</p>
<p>So here is the dataset I obtained from the <a target="_blank" rel="nofollow" href="http://www.uefa.com/uefaeuro/season=2016/statistics/">EUFA website</a>. You can download the dataset <a target="_blank" href="http://datascienceplus.com/wp-content/uploads/2016/07/dataset_HD_euro2016.csv">here</a>.</p>
<p>Load the data and packages</p>
<pre>
library(ggplot2)
library(dplyr)
library(corrplot)
library(psych)
library(MASS)

dataset&lt;-read.csv(&quot;Dataset_16.csv&quot;)
dataset$Standing&lt;-as.factor(dataset$Standing)
d_stan = as.matrix(scale(dataset[,3:25]))
</pre>
<p>All I do is just, first, I scale my variables (because they have different units) and then simply using <code>psych</code> package, I perform a FA with 3 factors and ‘quartimax' rotation (one of the main advantages of FA over PCA is the fact that you can rotate your factors and make the weightings of some variables zero or close to zero in order to create more meaningful factors). It turns out that the third factor is basically containing the same information as the second factor and it doesn't explain as much extra variability as it is supposed to. Therefore, I just repeat the same FA with two factors and compute the scores using 'factor.scores' function.</p>
<pre>
# Factor Analysis
FA&lt;-fac(cor(d_stan),2, rotate = &quot;promax&quot;, fm = &quot;minres&quot;)
scor&lt;-factor.scores((dataset[,3:25]), FA)
FA.dat&lt;-dataset%>%mutate(score1=scor$scores[,1],score2=scor$scores[,2])
</pre>
<p>Interestingly, by plotting the scores found from the first and the second factor we can find a meaningful pattern. Almost all the teams which they were knocked out in the group stage are all located in the SW part of the plot.</p>
<pre>
FA.dat%>%ggplot(aes(x=score1,y=score2))+
  theme_classic(base_size = 15)+
  geom_point(aes(color=Standing),size=4)+
  geom_text(aes(label = Team,y=score2-0.1),size=6)+
  labs(x=&quot;FA1- (Score on attempts and passes)&quot;,y=&quot;FA2-(Goal Score)&quot;)+
  geom_vline(xintercept = 0,color=&quot;red&quot;,size=1.2)+
  geom_hline(yintercept = 0,color=&quot;red&quot;,size=1.2)
</pre>
<p>Here are the plot:<br>
<a title="" data-rel="lightbox-0" target="_blank" href="http://i2.wp.com/datascienceplus.com/wp-content/uploads/2016/07/ffd99e_396eba69acda44ea97e7bb4aa73aa25d-mv2.png"><img sizes="(max-width: 490px) 100vw, 490px" srcset="http://i0.wp.com/datascienceplus.com/wp-content/uploads/2016/07/ffd99e_396eba69acda44ea97e7bb4aa73aa25d-mv2-490x263.png?resize=456%2C245 490w, http://datascienceplus.com/wp-content/uploads/2016/07/ffd99e_396eba69acda44ea97e7bb4aa73aa25d-mv2-600x323.png 600w, http://datascienceplus.com/wp-content/uploads/2016/07/ffd99e_396eba69acda44ea97e7bb4aa73aa25d-mv2-300x161.png 300w, http://datascienceplus.com/wp-content/uploads/2016/07/ffd99e_396eba69acda44ea97e7bb4aa73aa25d-mv2.png 636w" alt="ffd99e_396eba69acda44ea97e7bb4aa73aa25d-mv2" class="wp-image-4400" src="http://i0.wp.com/datascienceplus.com/wp-content/uploads/2016/07/ffd99e_396eba69acda44ea97e7bb4aa73aa25d-mv2-490x263.png?resize=456%2C245" data-recalc-dims="1"></a></p>
<p>In the next step I ploted the correlation between the scores (score1 and score2) found from the first two factors and the rest of the variables. It shows that the first score is highly correlated with the variables that shows the ability of the teams on making the opportunities and dominating the game. While, the second score is highly correlated with the ability of the teams on goal score. Therefor, each point in the above plot is representing a team and basically the farther right means the higher ability to dominating the game and so on.</p>
<pre>
corrplot(cor(FA.dat[,3:ncol(FA.dat)]), mar = c(1,0, 0, 0),tl.cex=0.9,method=&quot;square&quot;,type=&quot;lower&quot;, tl.col = &quot;black&quot;)
</pre>
<p>Here are the plot:<br>
<a title="" data-rel="lightbox-1" target="_blank" href="http://i2.wp.com/datascienceplus.com/wp-content/uploads/2016/07/ffd99e_0fdd1c06db9241acb4d76c592832cab2-mv2.png"><img sizes="(max-width: 490px) 100vw, 490px" srcset="http://i2.wp.com/datascienceplus.com/wp-content/uploads/2016/07/ffd99e_0fdd1c06db9241acb4d76c592832cab2-mv2-490x477.png?resize=456%2C444 490w, http://datascienceplus.com/wp-content/uploads/2016/07/ffd99e_0fdd1c06db9241acb4d76c592832cab2-mv2-600x584.png 600w, http://datascienceplus.com/wp-content/uploads/2016/07/ffd99e_0fdd1c06db9241acb4d76c592832cab2-mv2-300x292.png 300w, http://datascienceplus.com/wp-content/uploads/2016/07/ffd99e_0fdd1c06db9241acb4d76c592832cab2-mv2.png 636w" alt="ffd99e_0fdd1c06db9241acb4d76c592832cab2-mv2" class="wp-image-4399" src="http://i2.wp.com/datascienceplus.com/wp-content/uploads/2016/07/ffd99e_0fdd1c06db9241acb4d76c592832cab2-mv2-490x477.png?resize=456%2C444" data-recalc-dims="1"></a></p>
<p>Even though this simple analysis is not enough to answer all the questions you have, but this should give you a really good idea of who should for example win the Wales VS Northern Ireland game.</p>
<p>On my <a target="_blank" rel="nofollow" href="https://github.com/para2x/EURO2016FA">Github</a> you can find the data and R code.</p>
<p>Post a comment below if you have any suggestion or comment.</p>
<ul></ul>
<p><strong>
<p>Related Post</p>
<p>
<ol>
<li><a title="Permanent Link toVisualizing obesity across United States by using data from Wikipedia" target="_blank" rel="bookmark" href="http://datascienceplus.com/visualizing-obesity-across-united-states-by-using-data-from-wikipedia/">Visualizing obesity across United States by using data from Wikipedia</a></li>
<li><a title="Permanent Link toPlotting App for ggplot2 – Part 2" target="_blank" rel="bookmark" href="http://datascienceplus.com/plotting-app-for-ggplot2-part-2/">Plotting App for ggplot2 – Part 2</a></li>
<li><a title="Permanent Link toMastering R plot – Part 3: Outer margins" target="_blank" rel="bookmark" href="http://datascienceplus.com/mastering-r-plot-part-3-outer-margins/">Mastering R plot – Part 3: Outer margins</a></li>
<li><a title="Permanent Link toInteractive plotting with rbokeh" target="_blank" rel="bookmark" href="http://datascienceplus.com/interactive-plotting-with-rbokeh/">Interactive plotting with rbokeh</a></li>
<li><a title="Permanent Link toMastering R plot – Part 2: Axis" target="_blank" rel="bookmark" href="http://datascienceplus.com/mastering-r-plot-part-2-axis/">Mastering R plot – Part 2: Axis</a></li>
</ol></strong>
<div>
<a target="_blank" href="http://feeds.feedburner.com/~ff/datascienceplus?a=juNLek1OLP8:lInP9X6Lay8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/datascienceplus?i=juNLek1OLP8:lInP9X6Lay8:D7DqB2pKExk" border="0"></a> <a target="_blank" href="http://feeds.feedburner.com/~ff/datascienceplus?a=juNLek1OLP8:lInP9X6Lay8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/datascienceplus?d=qj6IDK7rITs" border="0"></a> <a target="_blank" href="http://feeds.feedburner.com/~ff/datascienceplus?a=juNLek1OLP8:lInP9X6Lay8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/datascienceplus?d=yIl2AUoC8zA" border="0"></a>
</div>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/what-can-we-learn-from-the-statistics-of-the-euro-2016-application-of-factor-analysis/"></div></div><div><a data-url="http://www.r-bloggers.com/what-can-we-learn-from-the-statistics-of-the-euro-2016-application-of-factor-analysis/" data-counturl="http://www.r-bloggers.com/what-can-we-learn-from-the-statistics-of-the-euro-2016-application-of-factor-analysis/" data-count="vertical" data-text="What can we learn from the statistics of the EURO 2016 – Application of factor analysis" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://datascienceplus.com/what-can-we-learn-from-the-statistics-of-the-euro-2016-application-of-factor-analysis/"> DataScience+</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/uzSU1yDKrPo"></a></div>