Below analysis has been conducted within the course Unsupervised Learning. The database is from https://www.kaggle.com/datasets/nirmalprasad/world-energy-consumption
The purpose of the following analysis is to find and show the patterns in energy consumption from different sources. Countries will be treated as observations which require filtering, cleansing and interpreting (1st part - data cleaning). I will try to capture their differences and similarities in approach to the energy consumption using different clustering methods (2nd part - clustering). The data can be differentiated using multiple variables, however, clustering plot will not be as clear as it could be. For this purpose I have provided a proposition of dimension reduction, which helped to cluster the observations in more interpretable way. Eventually, some inventive insights were extracted using association rules. Still, the purpose of the analysis in not to provide comprehensive conclusions about historical energy consumption data, rather the background for external factors and field concepts inclusion.
WEC<-read.csv("world_energy_consumption.csv")
colnames(WEC)[5]<-"EnCons"
which(is.na(WEC))
## integer(0)
head(WEC)
## Country Year Region Type EnCons
## 1 Canada 1990 North America Biofuel 0.00000000
## 2 Mexico 1990 North America Biofuel 0.00000000
## 3 US 1990 North America Biofuel 0.06023786
## 4 Argentina 1990 S. & Cent. America Biofuel 0.00000000
## 5 Brazil 1990 S. & Cent. America Biofuel 0.24514010
## 6 Colombia 1990 S. & Cent. America Biofuel 0.00000000
I am not removing the “0” values, because they are indicating that specific type of energy source was not used in a given country, year.
summary(WEC$EnCons)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.0000 0.0037 0.4908 0.1759 86.1698
For this purpose it would be helpful to firstly go through the sample for single year.
WEC2021<-WEC[WEC$Year=="2021",]
RegionsNames<-unique(WEC2021$Region)
EnergySources<-unique(WEC2021$Type)
Countries<-unique(WEC2021$Country)
#We can see that Europe is presented either with space in name and without
#space, we should standardize this to avoid future problems
WEC[which(WEC$Region=="Europe "),3]<-"Europe"
which(WEC$Region=="Europe ")
## integer(0)
#check
WEC2021<-WEC[WEC$Year=="2021",]
TypeRegion2021<-data.frame("Region"=WEC2021$Region,"Type"=WEC2021$Type)
TypeRegion2021<-unique(TypeRegion2021[order(TypeRegion2021$Region),])
RegionsNames<-unique(TypeRegion2021$Region)
#Let's create a dataframe of energy consumption for specific energy sources
#by Region.
regionByTypeCons2021<-data.frame(matrix(NA,1,3))
colnames(regionByTypeCons2021)[c(1,2,3)]<-c("Region","Source","EnCons")
for(j in 1:9){
for(i in 1:7){
regionByTypeCons2021[7*j+i-7,3]<-sum(WEC2021[which
(WEC2021$Region==RegionsNames[i]
& WEC2021$Type==EnergySources[j]),5])
regionByTypeCons2021[7*j+i-7,2]<-EnergySources[j]
regionByTypeCons2021[7*j+i-7,1]<-RegionsNames[i]
}
}
#Let's create a dataframe of energy consumption by Region
regionByCons2021<-data.frame(matrix(NA,1,2))
for(i in 1:7){
regionByCons2021[i,2]<-sum(regionByTypeCons2021
[which(regionByTypeCons2021$Region==RegionsNames[i]),3])
regionByCons2021[i,1]<-RegionsNames[i]
}
colnames(regionByCons2021)[2]<-"EnCons"
colnames(regionByCons2021)[1]<-"Region"
#For better visualization
regionByCons2021[which(regionByCons2021$Region==
"S. & Cent. America"),1]<-"South America"
Either the Asia Pacific in Energy consumption by region in 2021 and North America in Energy consumption per capita by region in 2021 seem to be outliers.
Example of Europe
par(mfrow = c(3, 3))
for(i in 1:9){
plot(EuropeWEC[[i]][,2],EuropeWEC[[i]][,3],
ylab="EnCons in Exajoules",xlab="Year", main=EnergySources[i],
cex=0.1, cex.main=2, cex.axis=1, cex.lab=1.1)
}
Data about biofuel is incomplete, we can inspect, which values are empty.
BiofuelInspection<-WEC2021[which(WEC2021$Type=="Biofuel"),3]
BiofuelInspection
## [1] "North America" "North America" "North America"
## [4] "S. & Cent. America" "S. & Cent. America" "S. & Cent. America"
## [7] "S. & Cent. America" "Europe" "Europe"
## [10] "Europe" "Europe" "Europe"
## [13] "Europe" "Europe" "Europe"
## [16] "Europe" "Europe" "Europe"
## [19] "Europe" "Europe" "CIS"
## [22] "Middle East" "Africa" "Asia Pacific"
## [25] "Asia Pacific" "Asia Pacific" "Asia Pacific"
## [28] "Asia Pacific" "Asia Pacific" "Asia Pacific"
It shouldn’t be assumed that no data about biofuel consumption means no consumption, as it might bias our clustering model. The data should be dropped.
This quick overview is an introduction to comparison Energy consumption by source over the decades, namely divided into following 3 equal (19 years) ranges, representing 3 different stages of world’s energy development: 1965-1983, 1984-2002 and 2003-2021.
#Whole database without Biofuel variable
WECv2<-WEC[which(WEC$Type %in% EnergySourcesv2),]
#We can see out dataset didn't worsen a lot, it lost only 960 out of 42912
#variables.
## [1] 123.4214
## [1] 123.4214
## [1] "Africa" "Asia Pacific" "CIS"
## [4] "Europe" "Middle East" "North America"
## [7] "S. & Cent. America"
install.packages("stats")
install.packages("factoextra")
install.packages("flexclust")
install.packages("fpc")
install.packages("clustertend")
install.packages("cluster")
install.packages("ClusterR")
library(stats)
library(factoextra)
## Loading required package: ggplot2
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(flexclust)
## Loading required package: grid
## Loading required package: lattice
## Loading required package: modeltools
## Loading required package: stats4
library(fpc)
library(clustertend)
## Package `clustertend` is deprecated. Use package `hopkins` instead.
library(cluster)
library(ClusterR)
clusters_CBSP_c2<-eclust(consBySourcePeriods, "clara", k=2)
clusters_CBSP_c3<-eclust(consBySourcePeriods, "clara", k=3)
clusters_CBSP_c4<-eclust(consBySourcePeriods, "clara", k=4)
In this method, using labels, for 2 clusters we can see that US has been assigned to the main cluster and China belongs to the single cluster.
For 3 clusters US and China are separated from the main cluster as single clusters.
For 4 clusters US and China are spearated and main group of clusters has been divided into two clusters.
PAM’s behavior is similar to clara.
The conclusion of this part is US and China significantly differ from other countries in terms of arbitral energy usage and sources over the periods.
Further analysis will focus on finding common patterns, thus it will drop the outliers.
consBySourcePeriods2<-as.data.frame(consBySourcePeriods[which
(rownames(consBySourcePeriods)!='US'
&rownames(consBySourcePeriods)!='China'),])
New case is with USSR, which in 90’ collapsed and Russian Federarion which in 90’ has arised - we can either sum them or drop both. However the resources, energy policy and energy infrastructure haven’t change much, I decided to drop them to not bias the data.
consBySourcePeriods2<-consBySourcePeriods2[-c
(which(rownames(consBySourcePeriods2)=='USSR'),
which(rownames(consBySourcePeriods2)=='Russian Federation')),]
optCBSP_e<-Optimal_Clusters_KMeans(consBySourcePeriods2, max_clusters=10,
plot_clusters = TRUE)
Based on elbow method, one can say 4 clusters will be optimal.
optCBSP_S<-Optimal_Clusters_KMeans(consBySourcePeriods2, max_clusters=10,
plot_clusters=TRUE, criterion="silhouette")
For silhuette index rather 2 clusters seems to be a good quality.
Clara doesn’t allow to use vector with zero values, they need to be dropped.
consBySourcePeriods2nc<-consBySourcePeriods2[,c(1:6,8:24)]
clusters_CBSP2nc_c2<-eclust(consBySourcePeriods2nc, "clara", k=2)
clusters_CBSP2nc_c3<-eclust(consBySourcePeriods2nc, "clara", k=3)
clusters_CBSP2nc_c4<-eclust(consBySourcePeriods2nc, "clara", k=4)
For easier interpreation, the periods are going to be considered separately (PAM).
clusters_CBSP3nc_p2<-eclust(consBySourceP3nc, "pam", k= 2)
clusters_CBSP3nc_p3<-eclust(consBySourceP3nc, "pam", k= 3)
clusters_CBSP3nc_p4<-eclust(consBySourceP3nc, "pam", k= 4)
clusters_CBSP2nc_p2<-eclust(consBySourceP2nc, "pam", k= 2)
clusters_CBSP2nc_p3<-eclust(consBySourceP2nc, "pam", k= 3)
clusters_CBSP2nc_p4<-eclust(consBySourceP2nc, "pam", k= 4)
clusters_CBSP1nc_p2<-eclust(consBySourceP1nc, "pam", k= 2)
clusters_CBSP1nc_p3<-eclust(consBySourceP1nc, "pam", k= 3)
clusters_CBSP1nc_p4<-eclust(consBySourceP1nc, "pam", k= 4)
PCA can be used to identify the most important features (or principal components) that explain the majority of the variation in the energy consumption data. These features can then be used to represent the data in a lower-dimensional space, making it easier to visualize and understand the patterns and trends in the energy consumption data over time. Additionally, PCA can also be used to identify the relationships between different energy sources, countries, and time periods, and to highlight the most important factors that influence energy consumption patterns.
Each component is a linear combination of the original variables (in this case, the energy sources), and the loadings indicate the contribution of each variable to the component.
In our case, the model aggregated (not divided for periods) data should be concerned. The logic behind this approach is since we are trying to find the different paths of developing the different energy sources consumption among the countries. However, not aggregated data will also be analyzed aiming to supplement the analysis of useful insights.
It would be neccessary to normalize the data, because we are looking for development paths/trends,
install.packages("caret")
library(caret)
consBySourcePrePCA <- preProcess(consBySource, method=c("center", "scale"))
consBySource.s <- predict(consBySourcePrePCA, consBySource)
summary(consBySource.s)
## Coal Natural gas Hydro-electric Nuclear energy
## Min. :-0.45055 Min. :-0.7623 Min. :-0.43608 Min. :-0.3269
## 1st Qu.:-0.43952 1st Qu.:-0.6655 1st Qu.:-0.42172 1st Qu.:-0.3269
## Median :-0.35911 Median :-0.3794 Median :-0.33000 Median :-0.3269
## Mean : 0.00000 Mean : 0.0000 Mean : 0.00000 Mean : 0.0000
## 3rd Qu.:-0.09002 3rd Qu.: 0.3189 3rd Qu.: 0.01121 3rd Qu.:-0.1840
## Max. : 6.17326 Max. : 3.4840 Max. : 6.59395 Max. : 7.1425
## Oil Other renewables Solar Wind
## Min. :-0.69423 Min. :-0.52850 Min. :-0.3874 Min. :-0.4091
## 1st Qu.:-0.51788 1st Qu.:-0.52341 1st Qu.:-0.3780 1st Qu.:-0.4068
## Median :-0.36825 Median :-0.47215 Median :-0.3286 Median :-0.3670
## Mean : 0.00000 Mean : 0.00000 Mean : 0.0000 Mean : 0.0000
## 3rd Qu.: 0.04453 3rd Qu.: 0.06525 3rd Qu.:-0.1281 3rd Qu.:-0.1398
## Max. : 5.96592 Max. : 4.36430 Max. : 5.7203 Max. : 6.4875
#eigenvalues on the basis of covariance
consBySource.cov<-cov(consBySource.s)
consBySource.eigen<-eigen(consBySource.cov)
consBySource.eigen$values
## [1] 4.82149864 0.96063438 0.71627755 0.53685087 0.40125615 0.35441246 0.15673472
## [8] 0.05233524
head(consBySource.eigen$vectors)
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] -0.3419784 0.41869645 0.2736494 -0.00986976 -0.29855455 0.6861657
## [2,] -0.3339324 -0.16913501 -0.4045911 -0.71639378 0.26363442 0.1404334
## [3,] -0.2289263 -0.79056379 0.3610947 0.11427954 -0.04645432 0.3094779
## [4,] -0.3108282 -0.07791530 -0.6170686 0.66492364 0.12841222 0.1466802
## [5,] -0.4259205 -0.06272955 -0.2162891 -0.13042885 -0.29571426 -0.1335031
## [6,] -0.3913218 -0.14082013 0.2835056 0.06165384 -0.19498159 -0.5499543
## [,7] [,8]
## [1,] -0.2696642 -0.009250405
## [2,] -0.1488431 -0.267562300
## [3,] 0.2673758 -0.098630885
## [4,] -0.1418807 -0.127604816
## [5,] 0.1889323 0.780960080
## [6,] -0.6151297 -0.154945838
We can observe the data are highly correlated with each other.
consBySource.s.pca1<-prcomp(consBySource.s, center=FALSE, scale.=FALSE)
# stats::
consBySource.s.pca1
## Standard deviations (1, .., p=8):
## [1] 2.1957911 0.9801196 0.8463318 0.7327011 0.6334478 0.5953255 0.3958974
## [8] 0.2287690
##
## Rotation (n x k) = (8 x 8):
## PC1 PC2 PC3 PC4 PC5
## Coal -0.3419784 -0.41869645 0.27364943 -0.00986976 0.29855455
## Natural gas -0.3339324 0.16913501 -0.40459110 -0.71639378 -0.26363442
## Hydro-electric -0.2289263 0.79056379 0.36109473 0.11427954 0.04645432
## Nuclear energy -0.3108282 0.07791530 -0.61706861 0.66492364 -0.12841222
## Oil -0.4259205 0.06272955 -0.21628911 -0.13042885 0.29571426
## Other renewables -0.3913218 0.14082013 0.28350563 0.06165384 0.19498159
## Solar -0.4041398 -0.30993635 0.02022848 0.01224681 0.23673847
## Wind -0.3530559 -0.21260030 0.35027609 0.10264700 -0.80075247
## PC6 PC7 PC8
## Coal -0.68616573 0.26966424 0.009250405
## Natural gas -0.14043338 0.14884307 0.267562300
## Hydro-electric -0.30947786 -0.26737581 0.098630885
## Nuclear energy -0.14668020 0.14188070 0.127604816
## Oil 0.13350311 -0.18893229 -0.780960080
## Other renewables 0.54995432 0.61512970 0.154945838
## Solar 0.26206787 -0.62533046 0.473591001
## Wind 0.05666596 -0.09159063 -0.210044067
summary(consBySource.s.pca1)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 2.1958 0.9801 0.84633 0.73270 0.63345 0.5953 0.39590
## Proportion of Variance 0.6027 0.1201 0.08953 0.06711 0.05016 0.0443 0.01959
## Cumulative Proportion 0.6027 0.7228 0.81230 0.87941 0.92956 0.9739 0.99346
## PC8
## Standard deviation 0.22877
## Proportion of Variance 0.00654
## Cumulative Proportion 1.00000
First two PC’s explain pretty decent proportion of the variance (0.7246 jointly). First three, however, explain even 0.81360.
consBySource.s.pca2<-princomp(consBySource.s) # stats::princomp()
loadings(consBySource.s.pca2)
##
## Loadings:
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8
## Coal 0.342 0.419 0.274 0.299 0.686 0.270
## Natural gas 0.334 -0.169 -0.405 0.716 -0.264 0.140 0.149 0.268
## Hydro-electric 0.229 -0.791 0.361 -0.114 0.309 -0.267
## Nuclear energy 0.311 -0.617 -0.665 -0.128 0.147 0.142 0.128
## Oil 0.426 -0.216 0.130 0.296 -0.134 -0.189 -0.781
## Other renewables 0.391 -0.141 0.284 0.195 -0.550 0.615 0.155
## Solar 0.404 0.310 0.237 -0.262 -0.625 0.474
## Wind 0.353 0.213 0.350 -0.103 -0.801 -0.210
##
## Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8
## SS loadings 1.000 1.000 1.000 1.000 1.000 1.000 1.000 1.000
## Proportion Var 0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125
## Cumulative Var 0.125 0.250 0.375 0.500 0.625 0.750 0.875 1.000
fviz_eig(consBySource.s.pca2, choice='eigenvalue') # eigenvalues on y-axis
fviz_eig(consBySource.s.pca2) # percentage of explained variance on y-axis
## eigenvalue variance.percent cumulative.variance.percent
## Dim.1 4.7673245 60.2687330 60.26873
## Dim.2 0.9498407 12.0079297 72.27666
## Dim.3 0.7082295 8.9534694 81.23013
## Dim.4 0.5308188 6.7106358 87.94077
## Dim.5 0.3967477 5.0157019 92.95647
## Dim.6 0.3504303 4.4301558 97.38663
## Dim.7 0.1549737 1.9591839 99.34581
## Dim.8 0.0517472 0.6541905 100.00000
loading_scores_PC_1<-consBySource.s.pca1$rotation[,1]
fac_scores_PC_1<-abs(loading_scores_PC_1)
fac_scores_PC_1_ranked<-names(sort(fac_scores_PC_1, decreasing=T))
consBySource.s.pca1$rotation[fac_scores_PC_1_ranked, 1]
## Oil Solar Other renewables Wind
## -0.4259205 -0.4041398 -0.3913218 -0.3530559
## Coal Natural gas Nuclear energy Hydro-electric
## -0.3419784 -0.3339324 -0.3108282 -0.2289263
#and PC2
loading_scores_PC_2<-consBySource.s.pca1$rotation[,2]
fac_scores_PC_2<-abs(loading_scores_PC_2)
## Hydro-electric Coal Solar Wind
## 0.79056379 -0.41869645 -0.30993635 -0.21260030
## Natural gas Other renewables Nuclear energy Oil
## 0.16913501 0.14082013 0.07791530 0.06272955
## Principal Component Analysis Results for individuals
## ===================================================
## Name Description
## 1 "$coord" "Coordinates for the individuals"
## 2 "$cos2" "Cos2 for the individuals"
## 3 "$contrib" "contributions of the individuals"
## Dim.1 Dim.2 Dim.3 Dim.4
## Canada -5.0963586 5.7805345 0.54469298 -0.8211394
## Mexico -1.3552237 0.5779841 -0.48824370 -1.3008751
## Argentina 0.2713435 0.4244476 -0.48660794 -0.7032187
## Brazil -3.9183691 4.2464915 3.33457382 0.7210157
## Colombia 0.8974849 0.3414124 0.21681589 0.1137611
## Other S. & Cent. America 1.4135998 -0.2214408 0.07860104 0.2945829
## Dim.5 Dim.6 Dim.7 Dim.8
## Canada -0.75859120 -1.97931937 -0.59720702 0.17780687
## Mexico -0.07658587 0.54654374 0.32629093 -0.48978443
## Argentina -0.23677469 -0.08798847 -0.02423568 -0.01753722
## Brazil 0.33122424 1.24620972 0.86640795 -0.25652694
## Colombia 0.12764564 -0.07444913 -0.09872401 0.02397394
## Other S. & Cent. America 0.01569719 0.09106823 -0.07894349 0.06984442
## Dim.1 Dim.2 Dim.3 Dim.4
## Canada 6.0526825 39.08299792 0.465406247 1.41120509
## Mexico 0.4280061 0.39073620 0.373940030 3.54182854
## Argentina 0.0171580 0.21071722 0.371438602 1.03499243
## Brazil 3.5779859 21.09173870 17.442523941 1.08804224
## Colombia 0.1877078 0.13633599 0.073741316 0.02708592
## Other S. & Cent. America 0.4656728 0.05735446 0.009691372 0.18162318
## Dim.5 Dim.6 Dim.7 Dim.8
## Canada 1.6114019886 12.42031926 2.55678728 0.678754732
## Mexico 0.0164242516 0.94700191 0.76322888 5.150219310
## Argentina 0.1569852545 0.02454441 0.00421071 0.006602942
## Brazil 0.3072079960 4.92360579 5.38133027 1.412803355
## Colombia 0.0456247244 0.01757196 0.06986994 0.012339419
## Other S. & Cent. America 0.0006899732 0.02629267 0.04467632 0.104731953
library(gridExtra)
var<-get_pca_var(consBySource.s.pca1)
a<-fviz_contrib(consBySource.s.pca1, "var", axes=1, xtickslab.rt=90) # default angle=45°
b<-fviz_contrib(consBySource.s.pca1, "var", axes=2, xtickslab.rt=90)
grid.arrange(a,b,top='Contribution to the first two Principal Components')
install.packages("psych")
library(psych)
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
consBySource.s.pca4_2<-principal(consBySource.s, nfactors=2, rotate="varimax")
consBySource.s.pca4_2
## Principal Components Analysis
## Call: principal(r = consBySource.s, nfactors = 2, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC2 h2 u2 com
## Coal 0.86 0.03 0.73 0.27 1.0
## Natural gas 0.55 0.52 0.57 0.43 2.0
## Hydro-electric 0.04 0.92 0.85 0.15 1.0
## Nuclear energy 0.55 0.41 0.47 0.53 1.9
## Oil 0.77 0.53 0.88 0.12 1.8
## Other renewables 0.67 0.56 0.76 0.24 1.9
## Solar 0.92 0.19 0.88 0.12 1.1
## Wind 0.77 0.22 0.64 0.36 1.2
##
## RC1 RC2
## SS loadings 3.82 1.97
## Proportion Var 0.48 0.25
## Cumulative Var 0.48 0.72
## Proportion Explained 0.66 0.34
## Cumulative Proportion 0.66 1.00
##
## Mean item complexity = 1.5
## Test of the hypothesis that 2 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.08
## with the empirical chi square 30.18 with prob < 0.0044
##
## Fit based upon off diagonal values = 0.98
consBySource.s.pca4_3<-principal(consBySource.s, nfactors=3, rotate="varimax")
consBySource.s.pca4_3
## Principal Components Analysis
## Call: principal(r = consBySource.s, nfactors = 3, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC3 RC2 h2 u2 com
## Coal 0.86 0.22 0.01 0.79 0.214 1.1
## Natural gas 0.28 0.74 0.25 0.68 0.318 1.5
## Hydro-electric 0.09 0.18 0.95 0.95 0.054 1.1
## Nuclear energy 0.21 0.83 0.08 0.74 0.256 1.1
## Oil 0.55 0.72 0.29 0.91 0.088 2.2
## Other renewables 0.65 0.36 0.51 0.81 0.185 2.5
## Solar 0.80 0.48 0.06 0.88 0.120 1.7
## Wind 0.80 0.21 0.22 0.73 0.268 1.3
##
## RC1 RC3 RC2
## SS loadings 2.88 2.24 1.37
## Proportion Var 0.36 0.28 0.17
## Cumulative Var 0.36 0.64 0.81
## Proportion Explained 0.44 0.35 0.21
## Cumulative Proportion 0.44 0.79 1.00
##
## Mean item complexity = 1.6
## Test of the hypothesis that 3 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.07
## with the empirical chi square 23.07 with prob < 0.0017
##
## Fit based upon off diagonal values = 0.99
The first principal component (RC1) represents a linear combination of the energy sources that explains the largest portion of the variation in the data. The other principal components (RC2 and RC3) are also linear combinations of the energy sources that capture the next highest portions of the variation in the data. h2 values represent the proportion of the total variance in the data that is explained by each component, and the u2 values are the proportion of the residual variance not explained by the components. The larger the h2 value, the more important the component is in explaining the variance in the data.
We can observe now that in case of two PC nuclear energy is irrelevant (u2=0.53) let’s check the consumption over the years by region of this energy source
We can observe that there were a patterns of nuclear energy usage for 3 regions (Europe, North America and Asia Pacific), that is why we do not want to exclude this variable from the model. Consequently, we can consider output from 3 PCs, which concern the nuclear energy as significant and fit to our goal of the analysis.
Moving on to the qualitative analysis of the dimension reduction process, we can check the complexity. High complexity not desired as lead to more potential uncertainties in interpretation.
The interpretation of PCs and RCs is similar in terms of their mathematical representation, as they both represent linear combinations of the original variables.
The obtained RCs can be interpreted in terms of the underlying patterns in the data. In our case, RC1 has high loadings for Coal, Solar, and Wind, this suggests that these three energy sources tend to be consumed together. RC2 has high loadings for Hydro-electric, which informs us about high representation of this variable in the factor’s variation. Lastly, the RC3 has high loadings for Natural Gas, Nuclear Energy and Oil. We can observe that the kind of restival varible, “Other renewables” is hard to assign to any of these components. However, it still contributes as statisticaly significant variable (assuming h2 threshold=0.65, here: h2=0.82).
## Coal P1 Natural gas P1 Hydro-electric P1 Nuclear energy P1
## Min. :-0.3752 Min. :-0.4532 Min. :-0.3983 Min. :-0.3125
## 1st Qu.:-0.3752 1st Qu.:-0.4532 1st Qu.:-0.3983 1st Qu.:-0.3125
## Median :-0.3646 Median :-0.3989 Median :-0.3373 Median :-0.3125
## Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 Mean : 0.0000
## 3rd Qu.:-0.1768 3rd Qu.:-0.1665 3rd Qu.:-0.1433 3rd Qu.:-0.3117
## Max. : 6.4565 Max. : 4.8336 Max. : 7.2346 Max. : 4.7891
## Oil P1 Other renewables P1 Wind P1 Coal P2
## Min. :-0.5012 Min. :-0.3545 Min. :-0.1084 Min. :-0.4755
## 1st Qu.:-0.4636 1st Qu.:-0.3545 1st Qu.:-0.1084 1st Qu.:-0.4704
## Median :-0.3077 Median :-0.3545 Median :-0.1084 Median :-0.4005
## Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 Mean : 0.0000
## 3rd Qu.:-0.1016 3rd Qu.:-0.2040 3rd Qu.:-0.1084 3rd Qu.:-0.1269
## Max. : 6.2647 Max. : 7.0745 Max. : 9.4799 Max. : 4.9336
## Natural gas P2 Hydro-electric P2 Nuclear energy P2 Oil P2
## Min. :-0.66048 Min. :-0.41661 Min. :-0.3105 Min. :-0.65253
## 1st Qu.:-0.62622 1st Qu.:-0.40963 1st Qu.:-0.3105 1st Qu.:-0.51332
## Median :-0.36637 Median :-0.31018 Median :-0.3105 Median :-0.33644
## Mean : 0.00000 Mean : 0.00000 Mean : 0.0000 Mean : 0.00000
## 3rd Qu.:-0.00069 3rd Qu.: 0.01052 3rd Qu.:-0.2386 3rd Qu.: 0.03109
## Max. : 3.93463 Max. : 6.85139 Max. : 6.7395 Max. : 6.50316
## Other renewables P2 Solar P2 Wind P2 Coal P3
## Min. :-0.41121 Min. :-0.1827 Min. :-0.2398 Min. :-0.36496
## 1st Qu.:-0.41121 1st Qu.:-0.1827 1st Qu.:-0.2398 1st Qu.:-0.35897
## Median :-0.39611 Median :-0.1827 Median :-0.2395 Median :-0.30956
## Mean : 0.00000 Mean : 0.0000 Mean : 0.0000 Mean : 0.00000
## 3rd Qu.:-0.08383 3rd Qu.:-0.1676 3rd Qu.:-0.2105 3rd Qu.:-0.06406
## Max. : 6.84865 Max. : 9.1514 Max. : 7.4809 Max. : 8.08798
## Natural gas P3 Hydro-electric P3 Nuclear energy P3 Oil P3
## Min. :-0.7563 Min. :-0.42974 Min. :-0.3165 Min. :-0.75425
## 1st Qu.:-0.6468 1st Qu.:-0.42467 1st Qu.:-0.3165 1st Qu.:-0.57518
## Median :-0.4369 Median :-0.33230 Median :-0.3165 Median :-0.39073
## Mean : 0.0000 Mean : 0.00000 Mean : 0.0000 Mean : 0.00000
## 3rd Qu.: 0.3858 3rd Qu.: 0.01347 3rd Qu.:-0.1968 3rd Qu.: 0.08658
## Max. : 4.7749 Max. : 6.01731 Max. : 7.8182 Max. : 4.66789
## Other renewables P3 Solar P3 Wind P3
## Min. :-0.50653 Min. :-0.3805 Min. :-0.4058
## 1st Qu.:-0.50216 1st Qu.:-0.3721 1st Qu.:-0.4047
## Median :-0.44887 Median :-0.3234 Median :-0.3642
## Mean : 0.00000 Mean : 0.0000 Mean : 0.0000
## 3rd Qu.: 0.09933 3rd Qu.:-0.1384 3rd Qu.:-0.1570
## Max. : 4.90907 Max. : 5.8002 Max. : 6.5129
# eigenvalues on the basis of covariance
consBySourcePeriods2nc.cov<-cov(consBySourcePeriods2nc.s)
consBySourcePeriods2nc.eigen<-eigen(consBySourcePeriods2nc.cov)
consBySourcePeriods2nc.eigen$values
## [1] 11.307051194 2.689820459 1.831474504 1.551732527 1.304844377
## [6] 1.166638301 0.910811185 0.592738420 0.474870598 0.351179055
## [11] 0.215290423 0.185826485 0.122793970 0.111524384 0.063822590
## [16] 0.042147625 0.025096709 0.016047673 0.015169981 0.008822584
## [21] 0.006434115 0.003382408 0.002480432
head(consBySourcePeriods2nc.eigen$vectors)
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] -0.2171094 0.29474083 0.11795537 0.05404078 0.09373111 -0.10837297
## [2,] -0.2041666 -0.03476779 0.08916184 0.35314088 0.25045109 0.21273104
## [3,] -0.1885740 -0.40222758 0.16539755 0.05059287 -0.03328112 -0.13522350
## [4,] -0.2495561 0.02871798 -0.19810312 0.23621762 -0.02154702 -0.19077672
## [5,] -0.2821561 0.00120071 -0.16609068 0.04597085 -0.08719933 0.08223819
## [6,] -0.1711972 -0.13121769 -0.11188171 0.01288117 -0.23721554 0.27821188
## [,7] [,8] [,9] [,10] [,11] [,12]
## [1,] -0.19540554 -0.2891918 0.16040104 -0.22619996 0.05178274 0.52820438
## [2,] -0.10486463 -0.2527772 0.26819740 0.07799192 -0.61143115 -0.21101332
## [3,] 0.05798822 -0.1279409 0.06176186 0.33404735 -0.01857588 0.08833515
## [4,] -0.02299346 -0.1990299 -0.06125096 -0.16458021 -0.08477715 0.09753278
## [5,] -0.04208944 -0.1037563 -0.01785583 0.02847559 -0.12768609 0.16820108
## [6,] -0.41535968 0.5151168 0.45246757 0.19035084 0.06100983 0.21046699
## [,13] [,14] [,15] [,16] [,17] [,18]
## [1,] 0.04748513 0.24319259 0.01426144 -0.12575153 0.05767966 0.301750904
## [2,] -0.16161823 0.14068916 0.23993133 0.07412774 -0.04926323 -0.011338208
## [3,] 0.38103258 -0.01387702 -0.15239698 -0.41270776 -0.37939402 0.004018228
## [4,] 0.26701974 -0.60254286 -0.14323939 0.01167912 0.20265738 -0.054312592
## [5,] -0.08951908 -0.16423120 -0.10463855 0.10747935 0.12489414 -0.281885496
## [6,] 0.05251614 -0.04279366 -0.04761177 0.06003068 0.13801818 0.127198279
## [,19] [,20] [,21] [,22] [,23]
## [1,] -0.32497320 0.18145772 -0.180181196 -0.07361703 -0.004664282
## [2,] 0.13761287 -0.09075326 -0.006429102 -0.07851019 0.016689853
## [3,] 0.03793555 0.12559369 0.102732854 -0.05227544 0.310926735
## [4,] 0.06177728 -0.42304848 -0.186169444 0.02513941 0.014315129
## [5,] -0.08811722 0.47137843 0.449072809 0.47735675 -0.077560181
## [6,] 0.14596371 -0.06086090 -0.095047418 -0.02099140 0.009835476
One can observe the data are less correlated with each other than in approach 1.
consBySourcePeriods2nc.s.pca1<-prcomp(consBySourcePeriods2nc.s, center=FALSE, scale.=FALSE)
# stats::
To obtain as high Cumulative Proportion (CP) of variance explanation, we need as much as 5 PCs (Approach1 PC3 CP=0.8136, Approach2 PC5 CP=0.81239). However, raising the argument that this approach is mainly for the supplementation of first approach, PC3 (CP=0.68819) is sufficient.
## Oil P1 Oil P2 Solar P3 Nuclear energy P1
## -0.282156140 -0.279634014 -0.257222495 -0.249556077
## Oil P3 Other renewables P3 Nuclear energy P2 Natural gas P2
## -0.247380008 -0.243820982 -0.226176982 -0.218153299
## Coal P1 Wind P3 Other renewables P2 Coal P2
## -0.217109374 -0.213846897 -0.213464154 -0.211419261
## Natural gas P1 Natural gas P3 Solar P2 Nuclear energy P3
## -0.204166553 -0.200195993 -0.197262014 -0.188822693
## Hydro-electric P1 Other renewables P1 Hydro-electric P2 Coal P3
## -0.188574012 -0.171197222 -0.156535721 -0.153965823
## Wind P2 Hydro-electric P3 Wind P1
## -0.149151765 -0.139832188 0.004588863
## Hydro-electric P2 Hydro-electric P3 Hydro-electric P1 Wind P2
## 0.4470654434 0.4325851153 0.4022275818 -0.3347723229
## Coal P1 Coal P2 Other renewables P2 Wind P3
## -0.2947408261 -0.2558586222 0.2141753744 -0.2056069474
## Solar P3 Coal P3 Other renewables P1 Wind P1
## -0.1818931758 -0.1772658529 0.1312176901 -0.1129704563
## Natural gas P1 Natural gas P3 Nuclear energy P1 Oil P3
## 0.0347677938 0.0311502621 -0.0287179789 0.0221361917
## Nuclear energy P3 Natural gas P2 Oil P2 Nuclear energy P2
## 0.0163052293 -0.0112326195 0.0110755144 -0.0102896071
## Other renewables P3 Oil P1 Solar P2
## -0.0075229776 -0.0012007100 0.0008802003
## Principal Component Analysis Results for individuals
## ===================================================
## Name Description
## 1 "$coord" "Coordinates for the individuals"
## 2 "$cos2" "Cos2 for the individuals"
## 3 "$contrib" "contributions of the individuals"
## Dim.1 Dim.2 Dim.3 Dim.4
## Canada -9.8202802 8.8151123 -3.8364978 -2.62631166
## Mexico -2.2930682 1.0402352 0.4850613 0.28809620
## Argentina 0.1995738 0.4326052 0.1305126 -0.62318423
## Brazil -5.1377750 6.3728963 -4.5129560 1.60791724
## Colombia 1.1896295 0.6085494 -0.2154875 0.05718161
## Other S. & Cent. America 2.0729992 -0.1693668 0.2518699 -0.04845851
## Dim.5 Dim.6 Dim.7 Dim.8
## Canada -2.0480303 0.2089492 1.3846797 1.8273218
## Mexico -0.7673542 -2.2069261 0.5201362 -0.4047033
## Argentina -0.9093821 -0.8223299 0.4013249 0.1071252
## Brazil 1.8820981 0.1731994 -1.3162484 -1.2203787
## Colombia 0.1244036 0.1339704 -0.1717232 0.2086246
## Other S. & Cent. America 0.2901611 0.2890112 -0.3018400 0.2246195
## Dim.9 Dim.10 Dim.11 Dim.12
## Canada -0.82103267 -1.26293406 0.39714999 -0.08594376
## Mexico 0.25884326 0.69020175 0.86056501 -0.71734901
## Argentina 0.07121404 -0.05386525 0.07665048 -0.05831232
## Brazil 1.43041893 2.40265967 -0.81041745 0.27527012
## Colombia -0.00245161 -0.06959026 -0.02483757 0.11556473
## Other S. & Cent. America 0.04676999 -0.12731177 0.03317489 -0.03792755
## Dim.13 Dim.14 Dim.15 Dim.16
## Canada -0.6615976199 0.279767109 -0.12012068 0.25780445
## Mexico -0.4804190261 0.980137797 -0.20514593 -0.33804157
## Argentina 0.2062618200 -0.143635905 0.17501660 -0.14231061
## Brazil 1.3234555092 0.097470074 0.14567442 -0.38545630
## Colombia 0.1922342258 -0.003429885 0.07496547 -0.03494553
## Other S. & Cent. America -0.0001237056 -0.088196449 0.05666587 0.02022676
## Dim.17 Dim.18 Dim.19 Dim.20
## Canada -0.04793208 -0.006301655 0.040364880 0.1407688831
## Mexico 0.10404193 -0.211049192 0.222141868 -0.1374358719
## Argentina -0.13646969 -0.070130721 0.002343725 -0.2126005195
## Brazil 0.05387775 -0.002216781 -0.125399132 -0.0099352052
## Colombia -0.19169701 -0.023841730 0.007775717 -0.0103014791
## Other S. & Cent. America 0.01131955 0.012469276 -0.013808323 -0.0005613786
## Dim.21 Dim.22 Dim.23
## Canada 0.01911555 -0.016058334 0.030748576
## Mexico 0.15274508 0.146209007 -0.028292034
## Argentina -0.13371858 -0.173761261 0.074138498
## Brazil -0.02317045 -0.001756376 -0.003637453
## Colombia 0.05417404 -0.023313365 -0.027588941
## Other S. & Cent. America 0.01060806 -0.007274811 0.004370309
## Dim.1 Dim.2 Dim.3 Dim.4
## Canada 9.270658266 31.40107977 8.73536805 4.831565062
## Mexico 0.505471578 0.43727231 0.13963832 0.058139375
## Argentina 0.003828862 0.07562622 0.01010918 0.272037147
## Brazil 2.537540481 16.41204039 12.08741671 1.811017682
## Colombia 0.136046155 0.14965133 0.02755849 0.002290382
## Other S. & Cent. America 0.413105605 0.01159165 0.03764991 0.001644885
## Dim.5 Dim.6 Dim.7 Dim.8
## Canada 3.49402663 0.04067781 2.28813922 6.12321025
## Mexico 0.49050696 4.53786442 0.32286280 0.30034649
## Argentina 0.68888425 0.63003994 0.19221007 0.02104418
## Brazil 2.95078758 0.02794917 2.06756681 2.73110464
## Colombia 0.01289197 0.01672220 0.03519183 0.07981417
## Other S. & Cent. America 0.07013454 0.07782251 0.10872703 0.09252181
## Dim.9 Dim.10 Dim.11 Dim.12
## Canada 1.542971e+00 4.936792985 0.796336412 0.043204923
## Mexico 1.533595e-01 1.474469104 3.738994510 3.009993568
## Argentina 1.160829e-02 0.008980509 0.029663148 0.019889561
## Brazil 4.683423e+00 17.867676672 3.315927501 0.443223419
## Colombia 1.375751e-05 0.014989269 0.003114625 0.078118733
## Other S. & Cent. America 5.006929e-03 0.050167297 0.005556564 0.008414224
## Dim.13 Dim.14 Dim.15 Dim.16
## Canada 3.874565e+00 0.7628438500 0.24573856 1.71403571
## Mexico 2.043034e+00 9.3630342775 0.71674315 2.94699416
## Argentina 3.765935e-01 0.2010797651 0.52167047 0.52229229
## Brazil 1.550436e+01 0.0925944451 0.36141348 3.83168119
## Colombia 3.271121e-01 0.0001146573 0.09571066 0.03149360
## Other S. & Cent. America 1.354608e-07 0.0758131500 0.05468659 0.01055095
## Dim.17 Dim.18 Dim.19 Dim.20
## Canada 0.099505689 0.0026897338 0.1167439694 2.441348e+00
## Mexico 0.468826582 3.0169457432 3.5358022348 2.327108e+00
## Argentina 0.806617856 0.3331322820 0.0003935868 5.568587e+00
## Brazil 0.125722895 0.0003328477 1.1267204696 1.216102e-02
## Colombia 1.591571176 0.0385013227 0.0043321947 1.307421e-02
## Other S. & Cent. America 0.005549495 0.0105313144 0.0136618335 3.882648e-05
## Dim.21 Dim.22 Dim.23
## Canada 0.06173008 0.0828680433 0.414319066
## Mexico 3.94146643 6.8696462491 0.350762562
## Argentina 3.02069528 9.7026873715 2.408643201
## Brazil 0.09069689 0.0009913365 0.005798020
## Colombia 0.49579924 0.1746610344 0.333545403
## Other S. & Cent. America 0.01901059 0.0170070711 0.008369688
consBySourcePeriods2nc.s.pca4_2<-principal(consBySourcePeriods2nc.s,
nfactors=2, rotate="varimax")
consBySourcePeriods2nc.s.pca4_2
## Principal Components Analysis
## Call: principal(r = consBySourcePeriods2nc.s, nfactors = 2, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC2 h2 u2 com
## Coal P1 0.87 -0.09 0.767 0.23 1.0
## Natural gas P1 0.58 0.37 0.475 0.53 1.7
## Hydro-electric P1 0.26 0.88 0.837 0.16 1.2
## Nuclear energy P1 0.77 0.35 0.706 0.29 1.4
## Oil P1 0.84 0.44 0.900 0.10 1.5
## Other renewables P1 0.41 0.46 0.378 0.62 2.0
## Wind P1 0.07 -0.17 0.035 0.97 1.3
## Coal P2 0.82 -0.04 0.681 0.32 1.0
## Natural gas P2 0.66 0.32 0.538 0.46 1.5
## Hydro-electric P2 0.13 0.89 0.815 0.19 1.0
## Nuclear energy P2 0.68 0.34 0.579 0.42 1.5
## Oil P2 0.83 0.45 0.884 0.12 1.5
## Other renewables P2 0.47 0.64 0.639 0.36 1.8
## Solar P2 0.59 0.31 0.440 0.56 1.5
## Wind P2 0.70 -0.26 0.553 0.45 1.3
## Coal P3 0.59 -0.02 0.353 0.65 1.0
## Natural gas P3 0.57 0.36 0.456 0.54 1.7
## Hydro-electric P3 0.09 0.85 0.724 0.28 1.0
## Nuclear energy P3 0.55 0.32 0.404 0.60 1.6
## Oil P3 0.72 0.42 0.693 0.31 1.6
## Other renewables P3 0.73 0.37 0.672 0.33 1.5
## Solar P3 0.90 0.14 0.837 0.16 1.0
## Wind P3 0.79 0.03 0.631 0.37 1.0
##
## RC1 RC2
## SS loadings 9.47 4.53
## Proportion Var 0.41 0.20
## Cumulative Var 0.41 0.61
## Proportion Explained 0.68 0.32
## Cumulative Proportion 0.68 1.00
##
## Mean item complexity = 1.4
## Test of the hypothesis that 2 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.11
## with the empirical chi square 552.36 with prob < 5.1e-33
##
## Fit based upon off diagonal values = 0.95
consBySourcePeriods2nc.s.pca4_3<-principal(consBySourcePeriods2nc.s,
nfactors=3, rotate="varimax")
consBySourcePeriods2nc.s.pca4_3
## Principal Components Analysis
## Call: principal(r = consBySourcePeriods2nc.s, nfactors = 3, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC3 RC2 h2 u2 com
## Coal P1 0.44 0.77 -0.02 0.792 0.208 1.6
## Natural gas P1 0.45 0.39 0.36 0.489 0.511 2.9
## Hydro-electric P1 0.37 0.05 0.87 0.887 0.113 1.4
## Nuclear energy P1 0.82 0.30 0.15 0.778 0.222 1.3
## Oil P1 0.87 0.36 0.24 0.951 0.049 1.5
## Other renewables P1 0.55 0.07 0.31 0.401 0.599 1.6
## Wind P1 -0.17 0.25 -0.03 0.095 0.905 1.8
## Coal P2 0.38 0.77 0.06 0.738 0.262 1.5
## Natural gas P2 0.59 0.36 0.24 0.541 0.459 2.0
## Hydro-electric P2 0.18 0.04 0.97 0.968 0.032 1.1
## Nuclear energy P2 0.84 0.16 0.07 0.745 0.255 1.1
## Oil P2 0.85 0.35 0.27 0.925 0.075 1.6
## Other renewables P2 0.71 0.01 0.43 0.694 0.306 1.6
## Solar P2 0.80 0.08 0.03 0.641 0.359 1.0
## Wind P2 0.10 0.85 -0.03 0.726 0.274 1.0
## Coal P3 0.21 0.61 0.11 0.432 0.568 1.3
## Natural gas P3 0.56 0.28 0.26 0.459 0.541 2.0
## Hydro-electric P3 0.08 0.08 0.97 0.949 0.051 1.0
## Nuclear energy P3 0.70 0.12 0.10 0.512 0.488 1.1
## Oil P3 0.63 0.41 0.35 0.693 0.307 2.4
## Other renewables P3 0.47 0.58 0.43 0.738 0.262 2.8
## Solar P3 0.70 0.59 0.06 0.841 0.159 2.0
## Wind P3 0.26 0.84 0.23 0.832 0.168 1.3
##
## RC1 RC3 RC2
## SS loadings 7.45 4.68 3.71
## Proportion Var 0.32 0.20 0.16
## Cumulative Var 0.32 0.53 0.69
## Proportion Explained 0.47 0.30 0.23
## Cumulative Proportion 0.47 0.77 1.00
##
## Mean item complexity = 1.6
## Test of the hypothesis that 3 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.09
## with the empirical chi square 354.16 with prob < 1.9e-12
##
## Fit based upon off diagonal values = 0.97
One can observe now that in case of two PC NGP1, ORP1, WP1, SP2, CP3, NGP3, and NEP3 are irrelevant (u2>0.5). For sure, the variables should be understood as factors (with interaction between period and energy source), so we cannot treat either period 2 and natural gas as irrelevant at all. However, it is difficult to find some trend here. However, relatively high u2 statistic is repeated for three PC for Wind P1 and for almost all of remaining variables it oscillating around u2=0.5
Moreover, partly aggregated data analysis dor dimension reduction helped to reject hypothesis that hydro-electric variable is irrelevant, concerning its significance for periodic data.
pam_results_AP1_2 <- pam(consBySource.s.pca1$x[,1:2], k = 3)
Assign the cluster assignments to a variable
cluster_assignments_AP1_pam <- pam_results_AP1_2$clustering
Create a data frame with the principal components and cluster assignments
df_pca_cluster_pam_AP1 <- data.frame(PC1 = consBySource.s.pca1$x[,1],
PC2 = consBySource.s.pca1$x[,2],
Cluster = cluster_assignments_AP1_pam)
clusters_PAM_AP1<-eclust(df_pca_cluster_pam_AP1, "pam", k=3)
pam_results_AP2_2 <- pam(consBySourcePeriods2nc.s.pca1$x[,1:2], k = 3)
Assign the cluster assignments to a variable
cluster_assignments_AP2_2_pam <- pam_results_AP2_2$clustering
Create a data frame with the principal components and cluster assignments
df_pca_cluster_AP2_pam_2 <- data.frame(PC1 = consBySourcePeriods2nc.s.pca1$x[,1],
PC2 = consBySourcePeriods2nc.s.pca1$x[,2],
Cluster = cluster_assignments_AP2_2_pam)
clusters_PAM_AP2<-eclust(df_pca_cluster_AP2_pam_2, "pam", k=3)
Going through approaches for PAM we can inspect the contents of clusters, which can provide a valuable information about similarities and differences between the approaches.
head(clusters_PAM_AP1$clustering)
## Canada Mexico Argentina
## 1 2 2
## Brazil Colombia Other S. & Cent. America
## 1 3 3
head(clusters_PAM_AP2$clustering)
## Canada Mexico Argentina
## 1 2 2
## Brazil Colombia Other S. & Cent. America
## 1 3 3
## Loading required package: MASS
## Warning in `[<-.data.frame`(`*tmp*`, , 3, value =
## structure(list(`clusters_PAM_AP2[[3]]` = c(1L, : replacement element 1 has 92
## rows to replace 89 rows
countriesDiffAP1AP2
## [1] "Austria" "Australia" "India"
## [4] "Indonesia" "Thailand" "Other Asia Pacific"
## [7] "Chile" "Ecuador" "Other South America"
## [10] "Greece" "Slovenia" "Switzerland"
## [13] "Turkey" "Ukraine" "Azerbaijan"
## [16] "Belarus" "Kazakhstan" "Iran"
## [19] "Kuwait" "Saudi Arabia" "Algeria"
## [22] "South Africa" "Western Africa" "Japan"
## [25] "Pakistan" "Singapore"
for(i in 1:7){
for(j in 1:89){
if (clusters_PAM_AP1AP2[j,1]==countriesDiffAP1AP2[i])
print(clusters_PAM_AP1AP2[j,])
}
}
## Countires clustersAP1 clustersAP2
## 7 Austria 3 2
## Countires clustersAP1 clustersAP2
## 20 Australia 2 3
## Countires clustersAP1 clustersAP2
## 21 India 1 3
## Countires clustersAP1 clustersAP2
## 22 Indonesia 2 3
## Countires clustersAP1 clustersAP2
## 24 Thailand 2 1
## Countires clustersAP1 clustersAP2
## 25 Other Asia Pacific 3 2
## Countires clustersAP1 clustersAP2
## 26 Chile 3 2
We can clearly see that all the differences are arising from reclustering part of the countries from cluster 3 (aggregated data) to cluster 2 (partly aggregated).
The database has continuous values, thus one can use ECLAT algorithm. It work well with continuous values and can uncover interesting relationships between different energy sources consumption across different periods.
It would be appropriate to transoform the database into categorical values. The operations will be conducted on prePCA database with Periods.
## Coal P1 Natural gas P1 Hydro-electric P1
## Canada 14.4801324 27.7529715 39.738376
## Mexico 1.3242230 9.8959751 3.249680
## Argentina 0.6988188 5.7336927 1.270948
## Brazil 2.8593759 0.3406913 15.152184
## Colombia 1.7581327 1.2967292 1.845700
## Other S. & Cent. America 0.0000000 0.0000000 0.000000
## Nuclear energy P1 Oil P1 Other renewables P1 Wind P1
## Canada 3.3935634 63.32215 0.13416835 0
## Mexico 0.0000000 26.75130 0.08639892 0
## Argentina 0.2429242 19.88110 0.01282650 0
## Brazil 0.0000000 30.26294 0.20914166 0
## Colombia 0.0000000 5.13372 0.02193810 0
## Other S. & Cent. America 0.0000000 0.00000 0.00000000 0
## Coal P2 Natural gas P2 Hydro-electric P2
## Canada 22.064179 48.599328 65.220727
## Mexico 3.820415 20.503075 5.206741
## Argentina 0.648215 16.203328 4.691644
## Brazil 8.927735 3.783929 47.673589
## Colombia 2.378913 3.083431 5.619455
## Other S. & Cent. America 0.000000 0.000000 0.000000
## Nuclear energy P2 Oil P2 Other renewables P2
## Canada 15.3005109 69.216054 1.22396350
## Mexico 0.9519939 61.677636 1.02453288
## Argentina 1.3024608 17.510567 0.04081527
## Brazil 0.6513195 56.288042 1.20964263
## Colombia 0.0000000 8.550348 0.08329355
## Other S. & Cent. America 0.0000000 0.000000 0.00000000
## Solar P2 Wind P2 Coal P3 Natural gas P3
## Canada 1.112705e-03 0.016856360 17.7371050 69.321847
## Mexico 7.328643e-04 0.001315871 9.0980499 48.609042
## Argentina 1.789604e-06 0.002637747 0.8665842 29.886419
## Brazil 0.000000e+00 0.001159112 11.8489313 20.621647
## Colombia 9.663324e-05 0.000000000 3.1812589 6.586559
## Other S. & Cent. America 0.000000e+00 0.000000000 0.0000000 0.000000
## Hydro-electric P3 Nuclear energy P3 Oil P3
## Canada 69.944766 17.142067 86.08862
## Mexico 5.726074 1.886403 69.67695
## Argentina 5.840895 1.352816 22.37975
## Brazil 70.266550 2.572143 84.58640
## Colombia 8.695515 0.000000 10.53889
## Other S. & Cent. America 0.000000 0.000000 0.00000
## Other renewables P3 Solar P3 Wind P3
## Canada 2.1560094 0.319940360 2.885488149
## Mexico 1.3998575 0.323019396 1.134161163
## Argentina 0.3018447 0.042855977 0.307695846
## Brazil 7.8036116 0.365122023 3.469551342
## Colombia 0.3109332 0.006456122 0.008771958
## Other S. & Cent. America 0.0000000 0.000000000 0.000000000
We again need to clean a little bit a database.
#standarization
consBySourcePeriods2ncPre <- preProcess(consBySourcePeriods2nc,
method=c("center", "scale"))
consBySourcePeriods2nc.sAR <- predict(consBySourcePeriods2ncPre,
consBySourcePeriods2nc)
summary(consBySourcePeriods2nc.sAR)
## Coal P1 Natural gas P1 Hydro-electric P1 Nuclear energy P1
## Min. :-0.3823 Min. :-0.4623 Min. :-0.4060 Min. :-0.3182
## 1st Qu.:-0.3823 1st Qu.:-0.4623 1st Qu.:-0.4060 1st Qu.:-0.3182
## Median :-0.3650 Median :-0.3982 Median :-0.3392 Median :-0.3182
## Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 Mean : 0.0000
## 3rd Qu.:-0.1807 3rd Qu.:-0.1477 3rd Qu.:-0.1406 3rd Qu.:-0.3167
## Max. : 6.3520 Max. : 4.7549 Max. : 7.1204 Max. : 4.7070
## Oil P1 Other renewables P1 Wind P1 Coal P2
## Min. :-0.5117 Min. :-0.3611 Min. :-0.1102 Min. :-0.4853
## 1st Qu.:-0.4587 1st Qu.:-0.3611 1st Qu.:-0.1102 1st Qu.:-0.4784
## Median :-0.3148 Median :-0.3611 Median :-0.1102 Median :-0.4011
## Mean : 0.0000 Mean : 0.0000 Mean : 0.0000 Mean : 0.0000
## 3rd Qu.:-0.1103 3rd Qu.:-0.1614 3rd Qu.:-0.1102 3rd Qu.:-0.1274
## Max. : 6.1705 Max. : 6.9601 Max. : 9.3206 Max. : 4.8546
## Natural gas P2 Hydro-electric P2 Nuclear energy P2 Oil P2
## Min. :-0.676438 Min. :-0.42475 Min. :-0.3161 Min. :-0.66817
## 1st Qu.:-0.630253 1st Qu.:-0.41192 1st Qu.:-0.3161 1st Qu.:-0.50369
## Median :-0.368173 Median :-0.31247 Median :-0.3161 Median :-0.33522
## Mean : 0.000000 Mean : 0.00000 Mean : 0.0000 Mean : 0.00000
## 3rd Qu.: 0.005086 3rd Qu.: 0.01336 3rd Qu.:-0.2390 3rd Qu.: 0.05315
## Max. : 3.876255 Max. : 6.74367 Max. : 6.6281 Max. : 6.42019
## Other renewables P2 Solar P2 Wind P2 Coal P3
## Min. :-0.41922 Min. :-0.1858 Min. :-0.2440 Min. :-0.37184
## 1st Qu.:-0.41922 1st Qu.:-0.1858 1st Qu.:-0.2440 1st Qu.:-0.36105
## Median :-0.40239 Median :-0.1858 Median :-0.2433 Median :-0.30822
## Mean : 0.00000 Mean : 0.0000 Mean : 0.0000 Mean : 0.00000
## 3rd Qu.:-0.09122 3rd Qu.:-0.1626 3rd Qu.:-0.2131 3rd Qu.:-0.05312
## Max. : 6.74063 Max. : 8.9983 Max. : 7.3558 Max. : 7.95954
## Natural gas P3 Hydro-electric P3 Nuclear energy P3 Oil P3
## Min. :-0.7764 Min. :-0.43823 Min. :-0.3223 Min. :-0.77426
## 1st Qu.:-0.6625 1st Qu.:-0.42574 1st Qu.:-0.3223 1st Qu.:-0.58170
## Median :-0.4419 Median :-0.33067 Median :-0.3223 Median :-0.36936
## Mean : 0.0000 Mean : 0.00000 Mean : 0.0000 Mean : 0.00000
## 3rd Qu.: 0.3654 3rd Qu.: 0.06527 3rd Qu.:-0.1801 3rd Qu.: 0.08044
## Max. : 4.7167 Max. : 5.92171 Max. : 7.6909 Max. : 4.61021
## Other renewables P3 Solar P3 Wind P3
## Min. :-0.51716 Min. :-0.3878 Min. :-0.4136
## 1st Qu.:-0.51111 1st Qu.:-0.3784 1st Qu.:-0.4113
## Median :-0.45602 Median :-0.3289 Median :-0.3700
## Mean : 0.00000 Mean : 0.0000 Mean : 0.0000
## 3rd Qu.: 0.08845 3rd Qu.:-0.1278 3rd Qu.:-0.1351
## Max. : 4.83185 Max. : 5.7053 Max. : 6.4092
#Based on the standardized values i can create bins for association rules
#algorithms requirements.
#excluding China and US
consBySourcePeriods2nc.s.vector<-c(consBySourcePeriods2nc.s)
consBySourcePeriods2nc.s.vector<-unlist(consBySourcePeriods2nc.s.vector)
head(consBySourcePeriods2nc.s.vector)
## Coal P11 Coal P12 Coal P13 Coal P14 Coal P15 Coal P16
## 0.5019054 -0.2949857 -0.3328682 -0.2019971 -0.2687026 -0.3751977
#firstly, general overview and inspecting the deciles
summary(consBySourcePeriods2nc.s.vector)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.7563 -0.3942 -0.3105 0.0000 -0.1084 9.4799
qConsBySourcePeriods2nc.s1 <- quantile(consBySourcePeriods2nc.s.vector,
c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9))
qConsBySourcePeriods2nc.s1
## 10% 20% 30% 40% 50% 60%
## -0.47553949 -0.41121442 -0.37105309 -0.33242991 -0.31049251 -0.23684761
## 70% 80% 90%
## -0.13383376 0.01840376 0.69568675
ggplot(data.frame(consBySourcePeriods2nc.s.vector),
aes(consBySourcePeriods2nc.s.vector)) +
geom_histogram(binwidth = 0.1) +
labs(x = "Value", y = "Frequency") +
ggtitle("Distribution of Vector Data") +
theme_minimal()
qConsBySourcePeriods2nc.s2 <- quantile(consBySourcePeriods2nc.s.vector,
c(0.25, 0.5))
qConsBySourcePeriods2nc.s2
## 25% 50%
## -0.3941980 -0.3104925
## Coal P1 Natural gas P1 Hydro-electric P1
## Canada 2 2 2
## Mexico 2 2 2
## Argentina 1 2 2
## Brazil 2 1 2
## Colombia 2 2 2
## Other S. & Cent. America 1 0 0
## Nuclear energy P1 Oil P1 Other renewables P1 Wind P1
## Canada 2 2 2 2
## Mexico 1 2 2 2
## Argentina 2 2 2 2
## Brazil 1 2 2 2
## Colombia 1 2 2 2
## Other S. & Cent. America 1 0 1 2
## Coal P2 Natural gas P2 Hydro-electric P2
## Canada 2 2 2
## Mexico 2 2 2
## Argentina 0 2 2
## Brazil 2 1 2
## Colombia 1 0 2
## Other S. & Cent. America 0 0 0
## Nuclear energy P2 Oil P2 Other renewables P2 Solar P2
## Canada 2 2 2 2
## Mexico 2 2 2 2
## Argentina 2 2 1 2
## Brazil 2 2 2 2
## Colombia 1 1 2 2
## Other S. & Cent. America 1 0 0 2
## Wind P2 Coal P3 Natural gas P3 Hydro-electric P3
## Canada 2 2 2 2
## Mexico 2 2 2 2
## Argentina 2 1 2 2
## Brazil 2 2 2 2
## Colombia 2 2 0 2
## Other S. & Cent. America 2 1 0 0
## Nuclear energy P3 Oil P3 Other renewables P3 Solar P3
## Canada 2 2 2 2
## Mexico 2 2 2 2
## Argentina 2 2 2 1
## Brazil 2 2 2 2
## Colombia 1 0 2 1
## Other S. & Cent. America 1 0 0 1
## Wind P3
## Canada 2
## Mexico 2
## Argentina 2
## Brazil 2
## Colombia 0
## Other S. & Cent. America 0
Going with the same logic:
qConsBySource.s2
## 10% 40% 70% 90%
## -0.4755395 -0.3324299 -0.1338338 0.6956868
head(consBySource.sAR.binned.df)
## Coal Natural gas Hydro-electric Nuclear energy Oil
## Canada 3 4 4 4 4
## Mexico 2 4 3 2 4
## Argentina 1 4 3 2 3
## Brazil 3 3 4 2 4
## Colombia 2 1 3 2 1
## Other S. & Cent. America 1 0 1 2 0
## Other renewables Solar Wind
## Canada 4 3 4
## Mexico 4 3 3
## Argentina 1 2 2
## Brazil 4 3 4
## Colombia 2 1 1
## Other S. & Cent. America 0 1 1
After some data manipulation, there are for aggregated 3 and for partly aggregated 5 data levels of energy usage, based on assumed binning breaks. Now, we can perform steps for association rules detection.
Let’s try with aggregated data.
install.packages("arules")
install.packages("arulesViz")
install.packages("arulesCBA")
library(arules)
## Loading required package: Matrix
##
## Attaching package: 'arules'
## The following object is masked from 'package:flexclust':
##
## info
## The following object is masked from 'package:modeltools':
##
## info
## The following objects are masked from 'package:base':
##
## abbreviate, write
library(arulesViz)
library(arulesCBA)
## $Canada
## [1] "Coal=3" "Natural gas=4" "Hydro-electric=4"
## [4] "Nuclear energy=4" "Oil=4" "Other renewables=4"
## [7] "Solar=3" "Wind=4"
##
## $Mexico
## [1] "Coal=2" "Natural gas=4" "Hydro-electric=3"
## [4] "Nuclear energy=2" "Oil=4" "Other renewables=4"
## [7] "Solar=3" "Wind=3"
##
## $Argentina
## [1] "Coal=1" "Natural gas=4" "Hydro-electric=3"
## [4] "Nuclear energy=2" "Oil=3" "Other renewables=1"
## [7] "Solar=2" "Wind=2"
##
## $Brazil
## [1] "Coal=3" "Natural gas=3" "Hydro-electric=4"
## [4] "Nuclear energy=2" "Oil=4" "Other renewables=4"
## [7] "Solar=3" "Wind=4"
##
## $Colombia
## [1] "Coal=2" "Natural gas=1" "Hydro-electric=3"
## [4] "Nuclear energy=2" "Oil=1" "Other renewables=2"
## [7] "Solar=1" "Wind=1"
##
## $`Other S. & Cent. America`
## [1] "Coal=1" "Natural gas=0" "Hydro-electric=1"
## [4] "Nuclear energy=2" "Oil=0" "Other renewables=0"
## [7] "Solar=1" "Wind=1"
## Coal=0 Coal=1 Coal=2 Coal=3
## 0 47 18 15
## Coal=4 Natural gas=0 Natural gas=1 Natural gas=2
## 9 42 6 9
## Natural gas=3 Natural gas=4 Hydro-electric=0 Hydro-electric=1
## 18 14 0 43
## Hydro-electric=2 Hydro-electric=3 Hydro-electric=4 Nuclear energy=0
## 18 21 7 0
## Nuclear energy=1 Nuclear energy=2 Nuclear energy=3 Nuclear energy=4
## 0 70 10 9
## Oil=0 Oil=1 Oil=2 Oil=3
## 28 20 13 15
## Oil=4 Other renewables=0 Other renewables=1 Other renewables=2
## 13 43 10 7
## Other renewables=3 Other renewables=4 Solar=0 Solar=1
## 17 12 0 42
## Solar=2 Solar=3 Solar=4 Wind=0
## 24 14 9 0
## Wind=1 Wind=2 Wind=3 Wind=4
## 50 17 13 9
freq.sources<-eclat(transAGR, parameter=list(supp=0.3, maxlen=15))
## Eclat
##
## parameter specification:
## tidLists support minlen maxlen target ext
## FALSE 0.3 1 15 frequent itemsets TRUE
##
## algorithmic control:
## sparse sort verbose
## 7 -2 TRUE
##
## Absolute minimum support count: 26
##
## create itemset ...
## set transactions ...[34 item(s), 89 transaction(s)] done [0.00s].
## sorting and recoding items ... [8 item(s)] done [0.00s].
## creating bit matrix ... [8 row(s), 89 column(s)] done [0.00s].
## writing ... [53 set(s)] done [0.00s].
## Creating S4 object ... done [0.00s].
freq.sources <- sort(freq.sources, by = "support", decreasing = TRUE)
## items support count
## [1] {Nuclear energy=2} 0.7865169 70
## [2] {Wind=1} 0.5617978 50
## [3] {Coal=1} 0.5280899 47
## [4] {Nuclear energy=2,
## Wind=1} 0.5168539 46
## [5] {Coal=1,
## Nuclear energy=2} 0.5056180 45
## [6] {Other renewables=0} 0.4831461 43
## [7] {Hydro-electric=1} 0.4831461 43
## [8] {Solar=1} 0.4719101 42
## [9] {Natural gas=0} 0.4719101 42
## [10] {Nuclear energy=2,
## Other renewables=0} 0.4606742 41
## [11] {Nuclear energy=2,
## Solar=1} 0.4494382 40
## [12] {Nuclear energy=2,
## Other renewables=0,
## Wind=1} 0.4157303 37
## [13] {Other renewables=0,
## Wind=1} 0.4157303 37
## [14] {Natural gas=0,
## Nuclear energy=2} 0.4044944 36
## [15] {Nuclear energy=2,
## Solar=1,
## Wind=1} 0.4044944 36
## [16] {Solar=1,
## Wind=1} 0.4044944 36
## [17] {Coal=1,
## Solar=1} 0.4044944 36
## [18] {Hydro-electric=1,
## Nuclear energy=2} 0.4044944 36
## [19] {Coal=1,
## Wind=1} 0.4044944 36
## [20] {Coal=1,
## Nuclear energy=2,
## Solar=1} 0.3932584 35
## [21] {Coal=1,
## Nuclear energy=2,
## Wind=1} 0.3932584 35
## [22] {Coal=1,
## Nuclear energy=2,
## Other renewables=0} 0.3707865 33
## [23] {Coal=1,
## Other renewables=0} 0.3707865 33
## [24] {Hydro-electric=1,
## Wind=1} 0.3595506 32
## [25] {Nuclear energy=2,
## Other renewables=0,
## Solar=1,
## Wind=1} 0.3483146 31
## [26] {Nuclear energy=2,
## Other renewables=0,
## Solar=1} 0.3483146 31
## [27] {Other renewables=0,
## Solar=1,
## Wind=1} 0.3483146 31
## [28] {Coal=1,
## Nuclear energy=2,
## Solar=1,
## Wind=1} 0.3483146 31
## [29] {Coal=1,
## Solar=1,
## Wind=1} 0.3483146 31
## [30] {Other renewables=0,
## Solar=1} 0.3483146 31
## [31] {Coal=1,
## Nuclear energy=2,
## Other renewables=0,
## Wind=1} 0.3483146 31
## [32] {Coal=1,
## Other renewables=0,
## Wind=1} 0.3483146 31
## [33] {Coal=1,
## Hydro-electric=1,
## Nuclear energy=2} 0.3370787 30
## [34] {Coal=1,
## Hydro-electric=1} 0.3370787 30
## [35] {Hydro-electric=1,
## Other renewables=0} 0.3370787 30
## [36] {Hydro-electric=1,
## Nuclear energy=2,
## Other renewables=0} 0.3258427 29
## [37] {Hydro-electric=1,
## Nuclear energy=2,
## Wind=1} 0.3258427 29
## [38] {Coal=1,
## Natural gas=0} 0.3146067 28
## [39] {Coal=1,
## Nuclear energy=2,
## Other renewables=0,
## Solar=1,
## Wind=1} 0.3146067 28
## [40] {Coal=1,
## Nuclear energy=2,
## Other renewables=0,
## Solar=1} 0.3146067 28
## [41] {Coal=1,
## Other renewables=0,
## Solar=1,
## Wind=1} 0.3146067 28
## [42] {Coal=1,
## Other renewables=0,
## Solar=1} 0.3146067 28
## [43] {Oil=0} 0.3146067 28
## [44] {Coal=1,
## Nuclear energy=2,
## Oil=0} 0.3033708 27
## [45] {Nuclear energy=2,
## Oil=0} 0.3033708 27
## [46] {Coal=1,
## Oil=0} 0.3033708 27
## [47] {Natural gas=0,
## Wind=1} 0.3033708 27
## [48] {Hydro-electric=1,
## Nuclear energy=2,
## Solar=1} 0.3033708 27
## [49] {Hydro-electric=1,
## Solar=1} 0.3033708 27
## [50] {Hydro-electric=1,
## Nuclear energy=2,
## Other renewables=0,
## Wind=1} 0.3033708 27
## [51] {Hydro-electric=1,
## Other renewables=0,
## Wind=1} 0.3033708 27
## [52] {Coal=1,
## Hydro-electric=1,
## Nuclear energy=2,
## Wind=1} 0.3033708 27
## [53] {Coal=1,
## Hydro-electric=1,
## Wind=1} 0.3033708 27
freq.rules<-ruleInduction(freq.sources, transAGR, confidence=0.9)
## lhs rhs support confidence lift itemset
## [1] {Wind=1} => {Nuclear energy=2} 0.5168539 0.9200000 1.169714 4
## [2] {Coal=1} => {Nuclear energy=2} 0.5056180 0.9574468 1.217325 5
## [3] {Other renewables=0} => {Nuclear energy=2} 0.4606742 0.9534884 1.212292 10
## [4] {Solar=1} => {Nuclear energy=2} 0.4494382 0.9523810 1.210884 11
## [5] {Other renewables=0,
## Wind=1} => {Nuclear energy=2} 0.4157303 1.0000000 1.271429 12
## [6] {Nuclear energy=2,
## Other renewables=0} => {Wind=1} 0.4157303 0.9024390 1.606341 12
## [7] {Solar=1,
## Wind=1} => {Nuclear energy=2} 0.4044944 1.0000000 1.271429 15
## [8] {Nuclear energy=2,
## Solar=1} => {Wind=1} 0.4044944 0.9000000 1.602000 15
## [9] {Coal=1,
## Solar=1} => {Nuclear energy=2} 0.3932584 0.9722222 1.236111 20
## [10] {Coal=1,
## Wind=1} => {Nuclear energy=2} 0.3932584 0.9722222 1.236111 21
## [11] {Coal=1,
## Other renewables=0} => {Nuclear energy=2} 0.3707865 1.0000000 1.271429 22
## [12] {Other renewables=0,
## Solar=1,
## Wind=1} => {Nuclear energy=2} 0.3483146 1.0000000 1.271429 25
## [13] {Nuclear energy=2,
## Other renewables=0,
## Solar=1} => {Wind=1} 0.3483146 1.0000000 1.780000 25
## [14] {Other renewables=0,
## Solar=1} => {Nuclear energy=2} 0.3483146 1.0000000 1.271429 26
## [15] {Other renewables=0,
## Solar=1} => {Wind=1} 0.3483146 1.0000000 1.780000 27
## [16] {Coal=1,
## Solar=1,
## Wind=1} => {Nuclear energy=2} 0.3483146 1.0000000 1.271429 28
## [17] {Coal=1,
## Other renewables=0,
## Wind=1} => {Nuclear energy=2} 0.3483146 1.0000000 1.271429 31
## [18] {Coal=1,
## Nuclear energy=2,
## Other renewables=0} => {Wind=1} 0.3483146 0.9393939 1.672121 31
## [19] {Coal=1,
## Other renewables=0} => {Wind=1} 0.3483146 0.9393939 1.672121 32
## [20] {Coal=1,
## Hydro-electric=1} => {Nuclear energy=2} 0.3370787 1.0000000 1.271429 33
## [21] {Hydro-electric=1,
## Other renewables=0} => {Nuclear energy=2} 0.3258427 0.9666667 1.229048 36
## [22] {Hydro-electric=1,
## Wind=1} => {Nuclear energy=2} 0.3258427 0.9062500 1.152232 37
## [23] {Nuclear energy=2,
## Other renewables=0,
## Solar=1,
## Wind=1} => {Coal=1} 0.3146067 0.9032258 1.710364 39
## [24] {Coal=1,
## Other renewables=0,
## Solar=1,
## Wind=1} => {Nuclear energy=2} 0.3146067 1.0000000 1.271429 39
## [25] {Coal=1,
## Nuclear energy=2,
## Solar=1,
## Wind=1} => {Other renewables=0} 0.3146067 0.9032258 1.869467 39
## [26] {Coal=1,
## Nuclear energy=2,
## Other renewables=0,
## Wind=1} => {Solar=1} 0.3146067 0.9032258 1.913978 39
## [27] {Coal=1,
## Nuclear energy=2,
## Other renewables=0,
## Solar=1} => {Wind=1} 0.3146067 1.0000000 1.780000 39
## [28] {Nuclear energy=2,
## Other renewables=0,
## Solar=1} => {Coal=1} 0.3146067 0.9032258 1.710364 40
## [29] {Coal=1,
## Other renewables=0,
## Solar=1} => {Nuclear energy=2} 0.3146067 1.0000000 1.271429 40
## [30] {Other renewables=0,
## Solar=1,
## Wind=1} => {Coal=1} 0.3146067 0.9032258 1.710364 41
## [31] {Coal=1,
## Solar=1,
## Wind=1} => {Other renewables=0} 0.3146067 0.9032258 1.869467 41
## [32] {Coal=1,
## Other renewables=0,
## Wind=1} => {Solar=1} 0.3146067 0.9032258 1.913978 41
## [33] {Coal=1,
## Other renewables=0,
## Solar=1} => {Wind=1} 0.3146067 1.0000000 1.780000 41
## [34] {Other renewables=0,
## Solar=1} => {Coal=1} 0.3146067 0.9032258 1.710364 42
## [35] {Nuclear energy=2,
## Oil=0} => {Coal=1} 0.3033708 1.0000000 1.893617 44
## [36] {Coal=1,
## Oil=0} => {Nuclear energy=2} 0.3033708 1.0000000 1.271429 44
## [37] {Oil=0} => {Nuclear energy=2} 0.3033708 0.9642857 1.226020 45
## [38] {Oil=0} => {Coal=1} 0.3033708 0.9642857 1.825988 46
## [39] {Hydro-electric=1,
## Solar=1} => {Nuclear energy=2} 0.3033708 1.0000000 1.271429 48
## [40] {Hydro-electric=1,
## Other renewables=0,
## Wind=1} => {Nuclear energy=2} 0.3033708 1.0000000 1.271429 50
## [41] {Hydro-electric=1,
## Nuclear energy=2,
## Wind=1} => {Other renewables=0} 0.3033708 0.9310345 1.927025 50
## [42] {Hydro-electric=1,
## Nuclear energy=2,
## Other renewables=0} => {Wind=1} 0.3033708 0.9310345 1.657241 50
## [43] {Hydro-electric=1,
## Other renewables=0} => {Wind=1} 0.3033708 0.9000000 1.602000 51
## [44] {Hydro-electric=1,
## Nuclear energy=2,
## Wind=1} => {Coal=1} 0.3033708 0.9310345 1.763023 52
## [45] {Coal=1,
## Hydro-electric=1,
## Wind=1} => {Nuclear energy=2} 0.3033708 1.0000000 1.271429 52
## [46] {Coal=1,
## Hydro-electric=1,
## Nuclear energy=2} => {Wind=1} 0.3033708 0.9000000 1.602000 52
## [47] {Coal=1,
## Hydro-electric=1} => {Wind=1} 0.3033708 0.9000000 1.602000 53
## Eclat
##
## parameter specification:
## tidLists support minlen maxlen target ext
## FALSE 0.3 1 15 closed frequent itemsets TRUE
##
## algorithmic control:
## sparse sort verbose
## 7 -2 TRUE
##
## Absolute minimum support count: 26
##
## create itemset ...
## set transactions ...[34 item(s), 89 transaction(s)] done [0.00s].
## sorting and recoding items ... [8 item(s)] done [0.00s].
## creating bit matrix ... [8 row(s), 89 column(s)] done [0.00s].
## writing ... [36 set(s)] done [0.00s].
## Creating S4 object ... done [0.00s].
## items support count
## [1] {Coal=1,
## Nuclear energy=2,
## Oil=0} 0.3033708 27
## [2] {Natural gas=0,
## Nuclear energy=2} 0.4044944 36
## [3] {Natural gas=0,
## Wind=1} 0.3033708 27
## [4] {Coal=1,
## Natural gas=0} 0.3146067 28
## [5] {Hydro-electric=1,
## Nuclear energy=2,
## Solar=1} 0.3033708 27
## [6] {Coal=1,
## Nuclear energy=2,
## Other renewables=0,
## Solar=1,
## Wind=1} 0.3146067 28
## [7] {Nuclear energy=2,
## Other renewables=0,
## Solar=1,
## Wind=1} 0.3483146 31
## [8] {Coal=1,
## Nuclear energy=2,
## Solar=1,
## Wind=1} 0.3483146 31
## [9] {Coal=1,
## Nuclear energy=2,
## Solar=1} 0.3932584 35
## [10] {Nuclear energy=2,
## Solar=1,
## Wind=1} 0.4044944 36
## [11] {Nuclear energy=2,
## Solar=1} 0.4494382 40
## [12] {Coal=1,
## Solar=1} 0.4044944 36
## [13] {Hydro-electric=1,
## Nuclear energy=2,
## Other renewables=0,
## Wind=1} 0.3033708 27
## [14] {Hydro-electric=1,
## Nuclear energy=2,
## Other renewables=0} 0.3258427 29
## [15] {Coal=1,
## Hydro-electric=1,
## Nuclear energy=2,
## Wind=1} 0.3033708 27
## [16] {Coal=1,
## Hydro-electric=1,
## Nuclear energy=2} 0.3370787 30
## [17] {Hydro-electric=1,
## Nuclear energy=2,
## Wind=1} 0.3258427 29
## [18] {Hydro-electric=1,
## Nuclear energy=2} 0.4044944 36
## [19] {Hydro-electric=1,
## Wind=1} 0.3595506 32
## [20] {Hydro-electric=1,
## Other renewables=0} 0.3370787 30
## [21] {Coal=1,
## Nuclear energy=2,
## Other renewables=0,
## Wind=1} 0.3483146 31
## [22] {Coal=1,
## Nuclear energy=2,
## Other renewables=0} 0.3707865 33
## [23] {Nuclear energy=2,
## Other renewables=0,
## Wind=1} 0.4157303 37
## [24] {Nuclear energy=2,
## Other renewables=0} 0.4606742 41
## [25] {Coal=1,
## Nuclear energy=2,
## Wind=1} 0.3932584 35
## [26] {Coal=1,
## Nuclear energy=2} 0.5056180 45
## [27] {Coal=1,
## Wind=1} 0.4044944 36
## [28] {Nuclear energy=2,
## Wind=1} 0.5168539 46
## [29] {Nuclear energy=2} 0.7865169 70
## [30] {Wind=1} 0.5617978 50
## [31] {Coal=1} 0.5280899 47
## [32] {Other renewables=0} 0.4831461 43
## [33] {Hydro-electric=1} 0.4831461 43
## [34] {Solar=1} 0.4719101 42
## [35] {Natural gas=0} 0.4719101 42
## [36] {Oil=0} 0.3146067 28
## {Coal=1,Nuclear energy=2,Oil=0}
## TRUE
## {Natural gas=0,Nuclear energy=2}
## TRUE
## {Natural gas=0,Wind=1}
## TRUE
## {Coal=1,Natural gas=0}
## TRUE
## {Hydro-electric=1,Nuclear energy=2,Solar=1}
## TRUE
## {Coal=1,Nuclear energy=2,Other renewables=0,Solar=1,Wind=1}
## TRUE
## {Nuclear energy=2,Other renewables=0,Solar=1,Wind=1}
## TRUE
## {Coal=1,Nuclear energy=2,Solar=1,Wind=1}
## TRUE
## {Coal=1,Nuclear energy=2,Solar=1}
## TRUE
## {Nuclear energy=2,Solar=1,Wind=1}
## TRUE
## {Nuclear energy=2,Solar=1}
## TRUE
## {Coal=1,Solar=1}
## TRUE
## {Hydro-electric=1,Nuclear energy=2,Other renewables=0,Wind=1}
## TRUE
## {Hydro-electric=1,Nuclear energy=2,Other renewables=0}
## TRUE
## {Coal=1,Hydro-electric=1,Nuclear energy=2,Wind=1}
## TRUE
## {Coal=1,Hydro-electric=1,Nuclear energy=2}
## TRUE
## {Hydro-electric=1,Nuclear energy=2,Wind=1}
## TRUE
## {Hydro-electric=1,Nuclear energy=2}
## TRUE
## {Hydro-electric=1,Wind=1}
## TRUE
## {Hydro-electric=1,Other renewables=0}
## TRUE
## {Coal=1,Nuclear energy=2,Other renewables=0,Wind=1}
## TRUE
## {Coal=1,Nuclear energy=2,Other renewables=0}
## TRUE
## {Nuclear energy=2,Other renewables=0,Wind=1}
## TRUE
## {Nuclear energy=2,Other renewables=0}
## TRUE
## {Coal=1,Nuclear energy=2,Wind=1}
## TRUE
## {Coal=1,Nuclear energy=2}
## TRUE
## {Coal=1,Wind=1}
## TRUE
## {Nuclear energy=2,Wind=1}
## TRUE
## {Nuclear energy=2}
## TRUE
## {Wind=1}
## TRUE
## {Coal=1}
## TRUE
## {Other renewables=0}
## TRUE
## {Hydro-electric=1}
## TRUE
## {Solar=1}
## TRUE
## {Natural gas=0}
## TRUE
## {Oil=0}
## TRUE
## Eclat
##
## parameter specification:
## tidLists support minlen maxlen target ext
## FALSE 0.3 1 15 maximally frequent itemsets TRUE
##
## algorithmic control:
## sparse sort verbose
## 7 -2 TRUE
##
## Absolute minimum support count: 26
##
## create itemset ...
## set transactions ...[34 item(s), 89 transaction(s)] done [0.00s].
## sorting and recoding items ... [8 item(s)] done [0.00s].
## creating bit matrix ... [8 row(s), 89 column(s)] done [0.00s].
## writing ... [8 set(s)] done [0.00s].
## Creating S4 object ... done [0.00s].
## items support count
## [1] {Coal=1,
## Nuclear energy=2,
## Oil=0} 0.3033708 27
## [2] {Natural gas=0,
## Nuclear energy=2} 0.4044944 36
## [3] {Natural gas=0,
## Wind=1} 0.3033708 27
## [4] {Coal=1,
## Natural gas=0} 0.3146067 28
## [5] {Hydro-electric=1,
## Nuclear energy=2,
## Solar=1} 0.3033708 27
## [6] {Coal=1,
## Nuclear energy=2,
## Other renewables=0,
## Solar=1,
## Wind=1} 0.3146067 28
## [7] {Hydro-electric=1,
## Nuclear energy=2,
## Other renewables=0,
## Wind=1} 0.3033708 27
## [8] {Coal=1,
## Hydro-electric=1,
## Nuclear energy=2,
## Wind=1} 0.3033708 27
trans.sel<-transAGR[,itemFrequency(transAGR)>0.45]
d.jac.i<-dissimilarity(trans.sel, which="items") # Jaccard as default
round(d.jac.i,2)
## Coal=1 Natural gas=0 Hydro-electric=1 Nuclear energy=2
## Natural gas=0 0.54
## Hydro-electric=1 0.50 0.63
## Nuclear energy=2 0.38 0.53 0.53
## Other renewables=0 0.42 0.65 0.46 0.43
## Solar=1 0.32 0.58 0.53 0.44
## Wind=1 0.41 0.58 0.48 0.38
## Other renewables=0 Solar=1
## Natural gas=0
## Hydro-electric=1
## Nuclear energy=2
## Other renewables=0
## Solar=1 0.43
## Wind=1 0.34 0.36
Interpretation: low uwage of natural gas infrequently goes in pair with Hydro electric on level 1, Nuclear on level 2, Solar on level 1, Wind on level 1. However, the most valuable this information will be knowing the frequence for each energy source on given level.
itemFrequency(transAGR, type="absolute")
## Coal=0 Coal=1 Coal=2 Coal=3
## 0 47 18 15
## Coal=4 Natural gas=0 Natural gas=1 Natural gas=2
## 9 42 6 9
## Natural gas=3 Natural gas=4 Hydro-electric=0 Hydro-electric=1
## 18 14 0 43
## Hydro-electric=2 Hydro-electric=3 Hydro-electric=4 Nuclear energy=0
## 18 21 7 0
## Nuclear energy=1 Nuclear energy=2 Nuclear energy=3 Nuclear energy=4
## 0 70 10 9
## Oil=0 Oil=1 Oil=2 Oil=3
## 28 20 13 15
## Oil=4 Other renewables=0 Other renewables=1 Other renewables=2
## 13 43 10 7
## Other renewables=3 Other renewables=4 Solar=0 Solar=1
## 17 12 0 42
## Solar=2 Solar=3 Solar=4 Wind=0
## 24 14 9 0
## Wind=1 Wind=2 Wind=3 Wind=4
## 50 17 13 9
Here the conslusion would be as follows: Hydro-electric is most frequently used on level 1 (out of 4), where for level 2, 3 and 4 jointly it is used much about the same as for level 1. Thus, higher consumption of Hydro-electrict might be supported by the Natural gas (J=0.63 for NG=0 and HE=1).
Now, lets move to the partly aggregated data, where scope of usage looks also a little bit different (it has 2 levels insted of 4 levels and, similarly as for aggregated data, level “0”).
transPAGR <- as(consBySourcePeriods2nc.sAR.binned.df, "transactions")
## $Canada
## [1] "Coal P1=2" "Natural gas P1=2" "Hydro-electric P1=2"
## [4] "Nuclear energy P1=2" "Oil P1=2" "Other renewables P1=2"
## [7] "Wind P1=2" "Coal P2=2" "Natural gas P2=2"
## [10] "Hydro-electric P2=2" "Nuclear energy P2=2" "Oil P2=2"
## [13] "Other renewables P2=2" "Solar P2=2" "Wind P2=2"
## [16] "Coal P3=2" "Natural gas P3=2" "Hydro-electric P3=2"
## [19] "Nuclear energy P3=2" "Oil P3=2" "Other renewables P3=2"
## [22] "Solar P3=2" "Wind P3=2"
##
## $Mexico
## [1] "Coal P1=2" "Natural gas P1=2" "Hydro-electric P1=2"
## [4] "Nuclear energy P1=1" "Oil P1=2" "Other renewables P1=2"
## [7] "Wind P1=2" "Coal P2=2" "Natural gas P2=2"
## [10] "Hydro-electric P2=2" "Nuclear energy P2=2" "Oil P2=2"
## [13] "Other renewables P2=2" "Solar P2=2" "Wind P2=2"
## [16] "Coal P3=2" "Natural gas P3=2" "Hydro-electric P3=2"
## [19] "Nuclear energy P3=2" "Oil P3=2" "Other renewables P3=2"
## [22] "Solar P3=2" "Wind P3=2"
##
## $Argentina
## [1] "Coal P1=1" "Natural gas P1=2" "Hydro-electric P1=2"
## [4] "Nuclear energy P1=2" "Oil P1=2" "Other renewables P1=2"
## [7] "Wind P1=2" "Coal P2=0" "Natural gas P2=2"
## [10] "Hydro-electric P2=2" "Nuclear energy P2=2" "Oil P2=2"
## [13] "Other renewables P2=1" "Solar P2=2" "Wind P2=2"
## [16] "Coal P3=1" "Natural gas P3=2" "Hydro-electric P3=2"
## [19] "Nuclear energy P3=2" "Oil P3=2" "Other renewables P3=2"
## [22] "Solar P3=1" "Wind P3=2"
##
## $Brazil
## [1] "Coal P1=2" "Natural gas P1=1" "Hydro-electric P1=2"
## [4] "Nuclear energy P1=1" "Oil P1=2" "Other renewables P1=2"
## [7] "Wind P1=2" "Coal P2=2" "Natural gas P2=1"
## [10] "Hydro-electric P2=2" "Nuclear energy P2=2" "Oil P2=2"
## [13] "Other renewables P2=2" "Solar P2=2" "Wind P2=2"
## [16] "Coal P3=2" "Natural gas P3=2" "Hydro-electric P3=2"
## [19] "Nuclear energy P3=2" "Oil P3=2" "Other renewables P3=2"
## [22] "Solar P3=2" "Wind P3=2"
##
## $Colombia
## [1] "Coal P1=2" "Natural gas P1=2" "Hydro-electric P1=2"
## [4] "Nuclear energy P1=1" "Oil P1=2" "Other renewables P1=2"
## [7] "Wind P1=2" "Coal P2=1" "Natural gas P2=0"
## [10] "Hydro-electric P2=2" "Nuclear energy P2=1" "Oil P2=1"
## [13] "Other renewables P2=2" "Solar P2=2" "Wind P2=2"
## [16] "Coal P3=2" "Natural gas P3=0" "Hydro-electric P3=2"
## [19] "Nuclear energy P3=1" "Oil P3=0" "Other renewables P3=2"
## [22] "Solar P3=1" "Wind P3=0"
##
## $`Other S. & Cent. America`
## [1] "Coal P1=1" "Natural gas P1=0" "Hydro-electric P1=0"
## [4] "Nuclear energy P1=1" "Oil P1=0" "Other renewables P1=1"
## [7] "Wind P1=2" "Coal P2=0" "Natural gas P2=0"
## [10] "Hydro-electric P2=0" "Nuclear energy P2=1" "Oil P2=0"
## [13] "Other renewables P2=0" "Solar P2=2" "Wind P2=2"
## [16] "Coal P3=1" "Natural gas P3=0" "Hydro-electric P3=0"
## [19] "Nuclear energy P3=1" "Oil P3=0" "Other renewables P3=0"
## [22] "Solar P3=1" "Wind P3=0"
## Coal P1=0 Coal P1=1 Coal P1=2
## 0 56 36
## Natural gas P1=0 Natural gas P1=1 Natural gas P1=2
## 47 9 36
## Hydro-electric P1=0 Hydro-electric P1=1 Hydro-electric P1=2
## 31 21 40
## Nuclear energy P1=0 Nuclear energy P1=1 Nuclear energy P1=2
## 0 70 22
## Oil P1=0 Oil P1=1 Oil P1=2
## 31 15 46
## Other renewables P1=0 Other renewables P1=1 Other renewables P1=2
## 0 64 28
## Wind P1=0 Wind P1=1 Wind P1=2
## 0 0 92
## Coal P2=0 Coal P2=1 Coal P2=2
## 47 10 35
## Natural gas P2=0 Natural gas P2=1 Natural gas P2=2
## 45 6 41
## Hydro-electric P2=0 Hydro-electric P2=1 Hydro-electric P2=2
## 29 17 46
## Nuclear energy P2=0 Nuclear energy P2=1 Nuclear energy P2=2
## 0 61 31
## Oil P2=0 Oil P2=1 Oil P2=2
## 40 8 44
## Other renewables P2=0 Other renewables P2=1 Other renewables P2=2
## 47 13 32
## Solar P2=0 Solar P2=1 Solar P2=2
## 0 0 92
## Wind P2=0 Wind P2=1 Wind P2=2
## 0 0 92
## Coal P3=0 Coal P3=1 Coal P3=2
## 0 46 46
## Natural gas P3=0 Natural gas P3=1 Natural gas P3=2
## 49 3 40
## Hydro-electric P3=0 Hydro-electric P3=1 Hydro-electric P3=2
## 30 19 43
## Nuclear energy P3=0 Nuclear energy P3=1 Nuclear energy P3=2
## 0 62 30
## Oil P3=0 Oil P3=1 Oil P3=2
## 46 8 38
## Other renewables P3=0 Other renewables P3=1 Other renewables P3=2
## 53 3 36
## Solar P3=0 Solar P3=1 Solar P3=2
## 0 49 43
## Wind P3=0 Wind P3=1 Wind P3=2
## 34 24 34
freq.sourcesP<-eclat(transPAGR, parameter=list(supp=0.7, maxlen=15))
## Eclat
##
## parameter specification:
## tidLists support minlen maxlen target ext
## FALSE 0.7 1 15 frequent itemsets TRUE
##
## algorithmic control:
## sparse sort verbose
## 7 -2 TRUE
##
## Absolute minimum support count: 64
##
## create itemset ...
## set transactions ...[56 item(s), 92 transaction(s)] done [0.00s].
## sorting and recoding items ... [4 item(s)] done [0.00s].
## creating bit matrix ... [4 row(s), 92 column(s)] done [0.00s].
## writing ... [15 set(s)] done [0.00s].
## Creating S4 object ... done [0.00s].
freq.sourcesP <- sort(freq.sourcesP, by = "support", decreasing = TRUE)
head(inspect(freq.sourcesP))
## items support count
## [1] {Wind P1=2,
## Solar P2=2,
## Wind P2=2} 1.0000000 92
## [2] {Wind P1=2,
## Wind P2=2} 1.0000000 92
## [3] {Wind P1=2,
## Solar P2=2} 1.0000000 92
## [4] {Solar P2=2,
## Wind P2=2} 1.0000000 92
## [5] {Wind P2=2} 1.0000000 92
## [6] {Solar P2=2} 1.0000000 92
## [7] {Wind P1=2} 1.0000000 92
## [8] {Nuclear energy P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2} 0.7608696 70
## [9] {Nuclear energy P1=1,
## Wind P1=2,
## Wind P2=2} 0.7608696 70
## [10] {Nuclear energy P1=1,
## Wind P1=2,
## Solar P2=2} 0.7608696 70
## [11] {Nuclear energy P1=1,
## Solar P2=2,
## Wind P2=2} 0.7608696 70
## [12] {Nuclear energy P1=1,
## Wind P2=2} 0.7608696 70
## [13] {Nuclear energy P1=1,
## Solar P2=2} 0.7608696 70
## [14] {Nuclear energy P1=1,
## Wind P1=2} 0.7608696 70
## [15] {Nuclear energy P1=1} 0.7608696 70
## NULL
freq.rulesP<-ruleInduction(freq.sourcesP, transPAGR, confidence=0.9)
## lhs rhs support confidence lift itemset
## [1] {Wind=1} => {Nuclear energy=2} 0.5168539 0.9200000 1.169714 4
## [2] {Coal=1} => {Nuclear energy=2} 0.5056180 0.9574468 1.217325 5
## [3] {Other renewables=0} => {Nuclear energy=2} 0.4606742 0.9534884 1.212292 10
## [4] {Solar=1} => {Nuclear energy=2} 0.4494382 0.9523810 1.210884 11
## [5] {Other renewables=0,
## Wind=1} => {Nuclear energy=2} 0.4157303 1.0000000 1.271429 12
## [6] {Nuclear energy=2,
## Other renewables=0} => {Wind=1} 0.4157303 0.9024390 1.606341 12
## [7] {Solar=1,
## Wind=1} => {Nuclear energy=2} 0.4044944 1.0000000 1.271429 15
## [8] {Nuclear energy=2,
## Solar=1} => {Wind=1} 0.4044944 0.9000000 1.602000 15
## [9] {Coal=1,
## Solar=1} => {Nuclear energy=2} 0.3932584 0.9722222 1.236111 20
## [10] {Coal=1,
## Wind=1} => {Nuclear energy=2} 0.3932584 0.9722222 1.236111 21
## [11] {Coal=1,
## Other renewables=0} => {Nuclear energy=2} 0.3707865 1.0000000 1.271429 22
## [12] {Other renewables=0,
## Solar=1,
## Wind=1} => {Nuclear energy=2} 0.3483146 1.0000000 1.271429 25
## [13] {Nuclear energy=2,
## Other renewables=0,
## Solar=1} => {Wind=1} 0.3483146 1.0000000 1.780000 25
## [14] {Other renewables=0,
## Solar=1} => {Nuclear energy=2} 0.3483146 1.0000000 1.271429 26
## [15] {Other renewables=0,
## Solar=1} => {Wind=1} 0.3483146 1.0000000 1.780000 27
## [16] {Coal=1,
## Solar=1,
## Wind=1} => {Nuclear energy=2} 0.3483146 1.0000000 1.271429 28
## [17] {Coal=1,
## Other renewables=0,
## Wind=1} => {Nuclear energy=2} 0.3483146 1.0000000 1.271429 31
## [18] {Coal=1,
## Nuclear energy=2,
## Other renewables=0} => {Wind=1} 0.3483146 0.9393939 1.672121 31
## [19] {Coal=1,
## Other renewables=0} => {Wind=1} 0.3483146 0.9393939 1.672121 32
## [20] {Coal=1,
## Hydro-electric=1} => {Nuclear energy=2} 0.3370787 1.0000000 1.271429 33
## [21] {Hydro-electric=1,
## Other renewables=0} => {Nuclear energy=2} 0.3258427 0.9666667 1.229048 36
## [22] {Hydro-electric=1,
## Wind=1} => {Nuclear energy=2} 0.3258427 0.9062500 1.152232 37
## [23] {Nuclear energy=2,
## Other renewables=0,
## Solar=1,
## Wind=1} => {Coal=1} 0.3146067 0.9032258 1.710364 39
## [24] {Coal=1,
## Other renewables=0,
## Solar=1,
## Wind=1} => {Nuclear energy=2} 0.3146067 1.0000000 1.271429 39
## [25] {Coal=1,
## Nuclear energy=2,
## Solar=1,
## Wind=1} => {Other renewables=0} 0.3146067 0.9032258 1.869467 39
## [26] {Coal=1,
## Nuclear energy=2,
## Other renewables=0,
## Wind=1} => {Solar=1} 0.3146067 0.9032258 1.913978 39
## [27] {Coal=1,
## Nuclear energy=2,
## Other renewables=0,
## Solar=1} => {Wind=1} 0.3146067 1.0000000 1.780000 39
## [28] {Nuclear energy=2,
## Other renewables=0,
## Solar=1} => {Coal=1} 0.3146067 0.9032258 1.710364 40
## [29] {Coal=1,
## Other renewables=0,
## Solar=1} => {Nuclear energy=2} 0.3146067 1.0000000 1.271429 40
## [30] {Other renewables=0,
## Solar=1,
## Wind=1} => {Coal=1} 0.3146067 0.9032258 1.710364 41
## [31] {Coal=1,
## Solar=1,
## Wind=1} => {Other renewables=0} 0.3146067 0.9032258 1.869467 41
## [32] {Coal=1,
## Other renewables=0,
## Wind=1} => {Solar=1} 0.3146067 0.9032258 1.913978 41
## [33] {Coal=1,
## Other renewables=0,
## Solar=1} => {Wind=1} 0.3146067 1.0000000 1.780000 41
## [34] {Other renewables=0,
## Solar=1} => {Coal=1} 0.3146067 0.9032258 1.710364 42
## [35] {Nuclear energy=2,
## Oil=0} => {Coal=1} 0.3033708 1.0000000 1.893617 44
## [36] {Coal=1,
## Oil=0} => {Nuclear energy=2} 0.3033708 1.0000000 1.271429 44
## [37] {Oil=0} => {Nuclear energy=2} 0.3033708 0.9642857 1.226020 45
## [38] {Oil=0} => {Coal=1} 0.3033708 0.9642857 1.825988 46
## [39] {Hydro-electric=1,
## Solar=1} => {Nuclear energy=2} 0.3033708 1.0000000 1.271429 48
## [40] {Hydro-electric=1,
## Other renewables=0,
## Wind=1} => {Nuclear energy=2} 0.3033708 1.0000000 1.271429 50
## [41] {Hydro-electric=1,
## Nuclear energy=2,
## Wind=1} => {Other renewables=0} 0.3033708 0.9310345 1.927025 50
## [42] {Hydro-electric=1,
## Nuclear energy=2,
## Other renewables=0} => {Wind=1} 0.3033708 0.9310345 1.657241 50
## [43] {Hydro-electric=1,
## Other renewables=0} => {Wind=1} 0.3033708 0.9000000 1.602000 51
## [44] {Hydro-electric=1,
## Nuclear energy=2,
## Wind=1} => {Coal=1} 0.3033708 0.9310345 1.763023 52
## [45] {Coal=1,
## Hydro-electric=1,
## Wind=1} => {Nuclear energy=2} 0.3033708 1.0000000 1.271429 52
## [46] {Coal=1,
## Hydro-electric=1,
## Nuclear energy=2} => {Wind=1} 0.3033708 0.9000000 1.602000 52
## [47] {Coal=1,
## Hydro-electric=1} => {Wind=1} 0.3033708 0.9000000 1.602000 53
freq.closedP<-eclat(transPAGR, parameter=list(supp=0.5, maxlen=15,
target="closed frequent itemsets"))
## Eclat
##
## parameter specification:
## tidLists support minlen maxlen target ext
## FALSE 0.5 1 15 closed frequent itemsets TRUE
##
## algorithmic control:
## sparse sort verbose
## 7 -2 TRUE
##
## Absolute minimum support count: 46
##
## create itemset ...
## set transactions ...[56 item(s), 92 transaction(s)] done [0.00s].
## sorting and recoding items ... [19 item(s)] done [0.00s].
## creating bit matrix ... [19 row(s), 92 column(s)] done [0.00s].
## writing ... [34 set(s)] done [0.00s].
## Creating S4 object ... done [0.00s].
## items support count
## [1] {Oil P1=2,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2} 0.5000000 46
## [2] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Oil P3=0} 0.5000000 46
## [3] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Coal P3=1} 0.5000000 46
## [4] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Coal P3=2} 0.5000000 46
## [5] {Wind P1=2,
## Hydro-electric P2=2,
## Solar P2=2,
## Wind P2=2} 0.5000000 46
## [6] {Natural gas P1=0,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2} 0.5108696 47
## [7] {Wind P1=2,
## Coal P2=0,
## Solar P2=2,
## Wind P2=2} 0.5108696 47
## [8] {Other renewables P1=1,
## Wind P1=2,
## Other renewables P2=0,
## Solar P2=2,
## Wind P2=2,
## Other renewables P3=0} 0.5000000 46
## [9] {Other renewables P1=1,
## Wind P1=2,
## Other renewables P2=0,
## Solar P2=2,
## Wind P2=2} 0.5108696 47
## [10] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Solar P3=1} 0.5326087 49
## [11] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Natural gas P3=0} 0.5326087 49
## [12] {Nuclear energy P1=1,
## Other renewables P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Other renewables P3=0} 0.5217391 48
## [13] {Other renewables P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Other renewables P3=0} 0.5543478 51
## [14] {Nuclear energy P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Other renewables P3=0} 0.5434783 50
## [15] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Other renewables P3=0} 0.5760870 53
## [16] {Coal P1=1,
## Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.5000000 46
## [17] {Coal P1=1,
## Nuclear energy P1=1,
## Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2} 0.5108696 47
## [18] {Coal P1=1,
## Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2} 0.5217391 48
## [19] {Coal P1=1,
## Nuclear energy P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.5000000 46
## [20] {Coal P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.5108696 47
## [21] {Coal P1=1,
## Nuclear energy P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2} 0.5652174 52
## [22] {Coal P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2} 0.6086957 56
## [23] {Nuclear energy P1=1,
## Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.6304348 58
## [24] {Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.6413043 59
## [25] {Nuclear energy P1=1,
## Other renewables P1=1,
## Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2} 0.5000000 46
## [26] {Nuclear energy P1=1,
## Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2} 0.6521739 60
## [27] {Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2} 0.6630435 61
## [28] {Other renewables P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.5000000 46
## [29] {Nuclear energy P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.6413043 59
## [30] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.6739130 62
## [31] {Nuclear energy P1=1,
## Other renewables P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2} 0.5869565 54
## [32] {Other renewables P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2} 0.6956522 64
## [33] {Nuclear energy P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2} 0.7608696 70
## [34] {Wind P1=2,
## Solar P2=2,
## Wind P2=2} 1.0000000 92
## {Oil P1=2,Wind P1=2,Solar P2=2,Wind P2=2}
## TRUE
## {Wind P1=2,Solar P2=2,Wind P2=2,Oil P3=0}
## TRUE
## {Wind P1=2,Solar P2=2,Wind P2=2,Coal P3=1}
## TRUE
## {Wind P1=2,Solar P2=2,Wind P2=2,Coal P3=2}
## TRUE
## {Wind P1=2,Hydro-electric P2=2,Solar P2=2,Wind P2=2}
## TRUE
## {Natural gas P1=0,Wind P1=2,Solar P2=2,Wind P2=2}
## TRUE
## {Wind P1=2,Coal P2=0,Solar P2=2,Wind P2=2}
## TRUE
## {Other renewables P1=1,Wind P1=2,Other renewables P2=0,Solar P2=2,Wind P2=2,Other renewables P3=0}
## TRUE
## {Other renewables P1=1,Wind P1=2,Other renewables P2=0,Solar P2=2,Wind P2=2}
## TRUE
## {Wind P1=2,Solar P2=2,Wind P2=2,Solar P3=1}
## TRUE
## {Wind P1=2,Solar P2=2,Wind P2=2,Natural gas P3=0}
## TRUE
## {Nuclear energy P1=1,Other renewables P1=1,Wind P1=2,Solar P2=2,Wind P2=2,Other renewables P3=0}
## TRUE
## {Other renewables P1=1,Wind P1=2,Solar P2=2,Wind P2=2,Other renewables P3=0}
## TRUE
## {Nuclear energy P1=1,Wind P1=2,Solar P2=2,Wind P2=2,Other renewables P3=0}
## TRUE
## {Wind P1=2,Solar P2=2,Wind P2=2,Other renewables P3=0}
## TRUE
## {Coal P1=1,Wind P1=2,Nuclear energy P2=1,Solar P2=2,Wind P2=2,Nuclear energy P3=1}
## TRUE
## {Coal P1=1,Nuclear energy P1=1,Wind P1=2,Nuclear energy P2=1,Solar P2=2,Wind P2=2}
## TRUE
## {Coal P1=1,Wind P1=2,Nuclear energy P2=1,Solar P2=2,Wind P2=2}
## TRUE
## {Coal P1=1,Nuclear energy P1=1,Wind P1=2,Solar P2=2,Wind P2=2,Nuclear energy P3=1}
## TRUE
## {Coal P1=1,Wind P1=2,Solar P2=2,Wind P2=2,Nuclear energy P3=1}
## TRUE
## {Coal P1=1,Nuclear energy P1=1,Wind P1=2,Solar P2=2,Wind P2=2}
## TRUE
## {Coal P1=1,Wind P1=2,Solar P2=2,Wind P2=2}
## TRUE
## {Nuclear energy P1=1,Wind P1=2,Nuclear energy P2=1,Solar P2=2,Wind P2=2,Nuclear energy P3=1}
## TRUE
## {Wind P1=2,Nuclear energy P2=1,Solar P2=2,Wind P2=2,Nuclear energy P3=1}
## TRUE
## {Nuclear energy P1=1,Other renewables P1=1,Wind P1=2,Nuclear energy P2=1,Solar P2=2,Wind P2=2}
## TRUE
## {Nuclear energy P1=1,Wind P1=2,Nuclear energy P2=1,Solar P2=2,Wind P2=2}
## TRUE
## {Wind P1=2,Nuclear energy P2=1,Solar P2=2,Wind P2=2}
## TRUE
## {Other renewables P1=1,Wind P1=2,Solar P2=2,Wind P2=2,Nuclear energy P3=1}
## TRUE
## {Nuclear energy P1=1,Wind P1=2,Solar P2=2,Wind P2=2,Nuclear energy P3=1}
## TRUE
## {Wind P1=2,Solar P2=2,Wind P2=2,Nuclear energy P3=1}
## TRUE
## {Nuclear energy P1=1,Other renewables P1=1,Wind P1=2,Solar P2=2,Wind P2=2}
## TRUE
## {Other renewables P1=1,Wind P1=2,Solar P2=2,Wind P2=2}
## TRUE
## {Nuclear energy P1=1,Wind P1=2,Solar P2=2,Wind P2=2}
## TRUE
## {Wind P1=2,Solar P2=2,Wind P2=2}
## TRUE
## Eclat
##
## parameter specification:
## tidLists support minlen maxlen target ext
## FALSE 0.5 1 15 maximally frequent itemsets TRUE
##
## algorithmic control:
## sparse sort verbose
## 7 -2 TRUE
##
## Absolute minimum support count: 46
##
## create itemset ...
## set transactions ...[56 item(s), 92 transaction(s)] done [0.00s].
## sorting and recoding items ... [19 item(s)] done [0.00s].
## creating bit matrix ... [19 row(s), 92 column(s)] done [0.00s].
## writing ... [17 set(s)] done [0.00s].
## Creating S4 object ... done [0.00s].
## items support count
## [1] {Oil P1=2,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2} 0.5000000 46
## [2] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Oil P3=0} 0.5000000 46
## [3] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Coal P3=1} 0.5000000 46
## [4] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Coal P3=2} 0.5000000 46
## [5] {Wind P1=2,
## Hydro-electric P2=2,
## Solar P2=2,
## Wind P2=2} 0.5000000 46
## [6] {Natural gas P1=0,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2} 0.5108696 47
## [7] {Wind P1=2,
## Coal P2=0,
## Solar P2=2,
## Wind P2=2} 0.5108696 47
## [8] {Other renewables P1=1,
## Wind P1=2,
## Other renewables P2=0,
## Solar P2=2,
## Wind P2=2,
## Other renewables P3=0} 0.5000000 46
## [9] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Solar P3=1} 0.5326087 49
## [10] {Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Natural gas P3=0} 0.5326087 49
## [11] {Nuclear energy P1=1,
## Other renewables P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Other renewables P3=0} 0.5217391 48
## [12] {Coal P1=1,
## Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.5000000 46
## [13] {Coal P1=1,
## Nuclear energy P1=1,
## Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2} 0.5108696 47
## [14] {Coal P1=1,
## Nuclear energy P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.5000000 46
## [15] {Nuclear energy P1=1,
## Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.6304348 58
## [16] {Nuclear energy P1=1,
## Other renewables P1=1,
## Wind P1=2,
## Nuclear energy P2=1,
## Solar P2=2,
## Wind P2=2} 0.5000000 46
## [17] {Other renewables P1=1,
## Wind P1=2,
## Solar P2=2,
## Wind P2=2,
## Nuclear energy P3=1} 0.5000000 46
## Coal P1=1 Nuclear energy P1=1 Other renewables P1=1
## Nuclear energy P1=1 0.30
## Other renewables P1=1 0.40 0.32
## Wind P1=2 0.39 0.24 0.30
## Nuclear energy P2=1 0.30 0.15 0.42
## Solar P2=2 0.39 0.24 0.30
## Wind P2=2 0.39 0.24 0.30
## Nuclear energy P3=1 0.34 0.19 0.43
## Wind P1=2 Nuclear energy P2=1 Solar P2=2 Wind P2=2
## Nuclear energy P1=1
## Other renewables P1=1
## Wind P1=2
## Nuclear energy P2=1 0.34
## Solar P2=2 0.00 0.34
## Wind P2=2 0.00 0.34 0.00
## Nuclear energy P3=1 0.33 0.08 0.33 0.33
Interpretation: there are a lot of interesting inter-temporary information based on provided indexes. Some conspicuous ones are: if nuclear energy appeared in P2, it was likely it will appear in P3 more than impact of P1 on P2 and P1 on P3.