Select Git revision
compareModels_IMA2019.html
-
Ben Anderson authoredBen Anderson authored
compareModels_IMA2019.html 36.07 KiB
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="author" content="Ben Anderson (University of Otago)" />
<title>Comparing SAVE and GREEN Grid small area electricity demand models</title>
<script src="compareModels_IMA2019_files/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="compareModels_IMA2019_files/bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="compareModels_IMA2019_files/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="compareModels_IMA2019_files/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="compareModels_IMA2019_files/bootstrap-3.3.5/shim/respond.min.js"></script>
<script src="compareModels_IMA2019_files/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="compareModels_IMA2019_files/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="compareModels_IMA2019_files/tocify-1.9.1/jquery.tocify.js"></script>
<script src="compareModels_IMA2019_files/navigation-1.1/tabsets.js"></script>
<script src="compareModels_IMA2019_files/navigation-1.1/codefolding.js"></script>
<link href="compareModels_IMA2019_files/highlightjs-9.12.0/default.css" rel="stylesheet" />
<script src="compareModels_IMA2019_files/highlightjs-9.12.0/highlight.js"></script>
<script src="compareModels_IMA2019_files/kePrint-0.0.1/kePrint.js"></script>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}
</script>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
</style>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
background: white;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "";
border: none;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open')
});
});
</script>
<!-- code folding -->
<style type="text/css">
.code-folding-btn { margin-bottom: 4px; }
</style>
<script>
$(document).ready(function () {
window.initializeCodeFolding("hide" === "show");
});
</script>
<script>
$(document).ready(function () {
// move toc-ignore selectors from section div to header
$('div.section.toc-ignore')
.removeClass('toc-ignore')
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
// establish options
var options = {
selectors: "h1,h2,h3",
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_').toLowerCase();
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = true;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
}
.tocify .list-group-item {
border-radius: 0px;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row-fluid">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<div class="fluid-row" id="header">
<div class="btn-group pull-right">
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span>Code</span> <span class="caret"></span></button>
<ul class="dropdown-menu" style="min-width: 50px;">
<li><a id="rmd-show-all-code" href="#">Show All Code</a></li>
<li><a id="rmd-hide-all-code" href="#">Hide All Code</a></li>
</ul>
</div>
<h1 class="title toc-ignore">Comparing SAVE and GREEN Grid small area electricity demand models</h1>
<h3 class="subtitle">Analysis for paper presented at the IMA 7th World Congress, Galway June 19-21</h3>
<h4 class="author">Ben Anderson (University of Otago)</h4>
<h4 class="date">Last run at: 2019-06-20 16:03:24</h4>
</div>
<div id="report-purpose" class="section level1">
<h1><span class="header-section-number">1</span> Report Purpose</h1>
<p>To compare SAVE small area models:</p>
<ul>
<li>SDRC2.1 v1.0: Time Use Model with all hot water = elec but not heat</li>
<li>SDRC2.1 v2.0: Time Use Model with no hot water = elec and not heat</li>
<li>SDRC2.2: Observed kWh Model</li>
</ul>
</div>
<div id="join-models" class="section level1">
<h1><span class="header-section-number">2</span> Join models</h1>
<p>Join SAVE models</p>
<pre class="r"><code># Compare models ----
# join them at LSOA level
# v2.1 = 2001 v2,2 = 2011: some LSOAs may have changed
sdrc2.1v1_LSOA_dt <- drake::readd(sdrc2.1v1)
sdrc2.1v2_LSOA_dt <- drake::readd(sdrc2.1v2)
sdrc2.2_LSOA_dt <- drake::readd(sdrc2.2_BL)
sdrc2.1v1_LSOA_dt[, halfHour := hms] # mean weekday
sdrc2.1v1_LSOA_dt[, sdrc2.1v1meankWh := mean_powerkWh]
sdrc2.1v1_LSOA_dt <- sdrc2.1v1_LSOA_dt[,.(zonecode, halfHour, sdrc2.1v1meankWh)]
sdrc2.1v1_LSOA_dt[, halfHour := hms::trunc_hms(halfHour, 60*30)]
data.table::setkey(sdrc2.1v1_LSOA_dt, zonecode, halfHour)
sdrc2.1v2_LSOA_dt[, halfHour := hms] # mean weekday
sdrc2.1v2_LSOA_dt[, sdrc2.1v2meankWh := mean_powerkWh]
sdrc2.1v2_LSOA_dt <- sdrc2.1v2_LSOA_dt[,.(zonecode, halfHour, sdrc2.1v2meankWh)]
sdrc2.1v2_LSOA_dt[, halfHour := hms::trunc_hms(halfHour, 60*30)] # to remove the 1 sec (why is that there?)
data.table::setkey(sdrc2.1v2_LSOA_dt, zonecode, halfHour)
sdrc2.2_LSOA_dt[, sdrc2.2meankWh := meankWh] # mean weekday
sdrc2.2_LSOA_dt[, zonecode := LSOA11CD]
sdrc2.2_LSOA_dt <- sdrc2.2_LSOA_dt[,.(zonecode, halfHour, sdrc2.2meankWh)]
data.table::setkey(sdrc2.2_LSOA_dt, zonecode, halfHour)
# 2001 LSOAs:
data.table::uniqueN(sdrc2.1v1_LSOA_dt$zonecode)</code></pre>
<pre><code>## [1] 146</code></pre>
<pre class="r"><code>data.table::uniqueN(sdrc2.1v2_LSOA_dt$zonecode)</code></pre>
<pre><code>## [1] 146</code></pre>
<pre class="r"><code># 2011 LSOAs:
data.table::uniqueN(sdrc2.2_LSOA_dt$zonecode)</code></pre>
<pre><code>## [1] 148</code></pre>
<pre class="r"><code># so we'll get some NAs through not matching
mergedLSOA <- sdrc2.1v1_LSOA_dt[sdrc2.1v2_LSOA_dt][sdrc2.2_LSOA_dt]
kableExtra::kable(head(mergedLSOA), caption = "Combined models data table: 10 rows") %>%
kable_styling()</code></pre>
<table class="table" style="margin-left: auto; margin-right: auto;">
<caption>
<span id="tab:joinModels">Table 2.1: </span>Combined models data table: 10 rows
</caption>
<thead>
<tr>
<th style="text-align:left;">
zonecode
</th>
<th style="text-align:left;">
halfHour
</th>
<th style="text-align:right;">
sdrc2.1v1meankWh
</th>
<th style="text-align:right;">
sdrc2.1v2meankWh
</th>
<th style="text-align:right;">
sdrc2.2meankWh
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
E01017136
</td>
<td style="text-align:left;">
00:00:00
</td>
<td style="text-align:right;">
0.0895407
</td>
<td style="text-align:right;">
0.0532208
</td>
<td style="text-align:right;">
0.2547518
</td>
</tr>
<tr>
<td style="text-align:left;">
E01017136
</td>
<td style="text-align:left;">
00:30:00
</td>
<td style="text-align:right;">
0.0547033
</td>
<td style="text-align:right;">
0.0547033
</td>
<td style="text-align:right;">
0.2184891
</td>
</tr>
<tr>
<td style="text-align:left;">
E01017136
</td>
<td style="text-align:left;">
01:00:00
</td>
<td style="text-align:right;">
0.0019581
</td>
<td style="text-align:right;">
0.0019581
</td>
<td style="text-align:right;">
0.2022398
</td>
</tr>
<tr>
<td style="text-align:left;">
E01017136
</td>
<td style="text-align:left;">
01:30:00
</td>
<td style="text-align:right;">
0.0050028
</td>
<td style="text-align:right;">
0.0050028
</td>
<td style="text-align:right;">
0.1896946
</td>
</tr>
<tr>
<td style="text-align:left;">
E01017136
</td>
<td style="text-align:left;">
02:00:00
</td>
<td style="text-align:right;">
0.0000243
</td>
<td style="text-align:right;">
0.0000157
</td>
<td style="text-align:right;">
0.1720313
</td>
</tr>
<tr>
<td style="text-align:left;">
E01017136
</td>
<td style="text-align:left;">
02:30:00
</td>
<td style="text-align:right;">
0.0260250
</td>
<td style="text-align:right;">
0.0093787
</td>
<td style="text-align:right;">
0.1648835
</td>
</tr>
</tbody>
</table>
<pre class="r"><code>t <- summary(mergedLSOA)
kableExtra::kable(t, caption = "Summary of combined models data table") %>%
kable_styling()</code></pre>
<table class="table" style="margin-left: auto; margin-right: auto;">
<caption>
<span id="tab:joinModels">Table 2.1: </span>Summary of combined models data table
</caption>
<thead>
<tr>
<th style="text-align:left;">
</th>
<th style="text-align:left;">
zonecode
</th>
<th style="text-align:left;">
halfHour
</th>
<th style="text-align:left;">
sdrc2.1v1meankWh
</th>
<th style="text-align:left;">
sdrc2.1v2meankWh
</th>
<th style="text-align:left;">
sdrc2.2meankWh
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
Length:7104
</td>
<td style="text-align:left;">
Length:7104
</td>
<td style="text-align:left;">
Min. :0.0000
</td>
<td style="text-align:left;">
Min. :0.0000
</td>
<td style="text-align:left;">
Min. :0.07645
</td>
</tr>
<tr>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
Class :character
</td>
<td style="text-align:left;">
Class1:hms
</td>
<td style="text-align:left;">
1st Qu.:0.0634
</td>
<td style="text-align:left;">
1st Qu.:0.0400
</td>
<td style="text-align:left;">
1st Qu.:0.16881
</td>
</tr>
<tr>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
Mode :character
</td>
<td style="text-align:left;">
Class2:difftime
</td>
<td style="text-align:left;">
Median :0.2515
</td>
<td style="text-align:left;">
Median :0.2104
</td>
<td style="text-align:left;">
Median :0.21548
</td>
</tr>
<tr>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
Mode :numeric
</td>
<td style="text-align:left;">
Mean :0.2413
</td>
<td style="text-align:left;">
Mean :0.1989
</td>
<td style="text-align:left;">
Mean :0.22544
</td>
</tr>
<tr>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
3rd Qu.:0.3686
</td>
<td style="text-align:left;">
3rd Qu.:0.3090
</td>
<td style="text-align:left;">
3rd Qu.:0.26375
</td>
</tr>
<tr>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
Max. :0.7701
</td>
<td style="text-align:left;">
Max. :0.7145
</td>
<td style="text-align:left;">
Max. :0.54337
</td>
</tr>
<tr>
<td style="text-align:left;">
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA’s :432
</td>
<td style="text-align:left;">
NA’s :432
</td>
<td style="text-align:left;">
NA
</td>
</tr>
</tbody>
</table>
</div>
<div id="compare-sdrc2.1-model-1-with-model-2" class="section level1">
<h1><span class="header-section-number">3</span> Compare SDRC2.1 Model 1 with Model 2</h1>
<p>At LSOA level…</p>
<pre class="r"><code>mergedLSOA[,peakFlag := "4. All other times"]
mergedLSOA[halfHour >= hms::as.hms("07:00:00") & halfHour < hms::as.hms("09:00:00"),
peakFlag := "1. Morning Peak"]
mergedLSOA[halfHour >= hms::as.hms("16:00:00") & halfHour < hms::as.hms("20:00:00"),
peakFlag := "3. Evening Peak"]
mergedLSOA[halfHour >= hms::as.hms("09:00:00") & halfHour <= hms::as.hms("16:00:00"),
peakFlag := "2. Day time"]
# plot LSOAs ----
p <- ggplot2::ggplot(mergedLSOA, aes(x = sdrc2.1v1meankWh,
y = sdrc2.1v2meankWh,
colour = zonecode)) +
geom_abline(intercept = 0, slope = 1) +
geom_point() +
facet_wrap(. ~ peakFlag) +
theme(legend.position = "None") +
labs(x = "mean kWh (Sim: Time Use model v1)",
y = "mean kWh (Sim: Time Use model v2)",
caption = paste0("Southampton: LSOAs\n",
"1:1 line shown"))
#xlim(0,0.8) +
#ylim(0,0.6) +
p</code></pre>
<pre><code>## Warning: Removed 432 rows containing missing values (geom_point).</code></pre>
<div class="figure">
<img src="compareModels_IMA2019_files/figure-html/compare_v1_v2-1.png" alt="Half-hourly mean kWh for model 1 vs model 2 for each LSOA" width="672" />
<p class="caption">
(#fig:compare_v1_v2)Half-hourly mean kWh for model 1 vs model 2 for each LSOA
</p>
</div>
<pre class="r"><code>ggplot2::ggsave(paste0(pPath,"lsoaProfiles_Winter-Weekdays-Compare-SDCR2.1_v1_v2.png"), p)</code></pre>
<pre><code>## Saving 7 x 5 in image</code></pre>
<pre><code>## Warning: Removed 432 rows containing missing values (geom_point).</code></pre>
<pre class="r"><code>peaks <- unique(mergedLSOA$peakFlag)
for(p in peaks){
message("Testing correlation for: ", p)
print(with(mergedLSOA[peakFlag == p], cor.test(sdrc2.1v1meankWh,
sdrc2.1v2meankWh,
na.action = "na.omit")
))
print(with(mergedLSOA[peakFlag == p], cor.test(sdrc2.1v1meankWh,
sdrc2.1v2meankWh,
na.action = "na.omit",
method = "spearman")
))
}</code></pre>
<pre><code>## Testing correlation for: 4. All other times</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v1meankWh and sdrc2.1v2meankWh
## t = 270.28, df = 3056, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9782422 0.9810923
## sample estimates:
## cor
## 0.9797167</code></pre>
<pre><code>## Warning in cor.test.default(sdrc2.1v1meankWh, sdrc2.1v2meankWh, na.action =
## "na.omit", : Cannot compute exact p-value with ties</code></pre>
<pre><code>##
## Spearman's rank correlation rho
##
## data: sdrc2.1v1meankWh and sdrc2.1v2meankWh
## S = 191010000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9599227</code></pre>
<pre><code>## Testing correlation for: 1. Morning Peak</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v1meankWh and sdrc2.1v2meankWh
## t = 44.572, df = 554, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.8647061 0.9011672
## sample estimates:
## cor
## 0.8842772
##
##
## Spearman's rank correlation rho
##
## data: sdrc2.1v1meankWh and sdrc2.1v2meankWh
## S = 3396200, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.8814432</code></pre>
<pre><code>## Testing correlation for: 2. Day time</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v1meankWh and sdrc2.1v2meankWh
## t = 169.13, df = 2083, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9624248 0.9682626
## sample estimates:
## cor
## 0.9654647
##
##
## Spearman's rank correlation rho
##
## data: sdrc2.1v1meankWh and sdrc2.1v2meankWh
## S = 58153000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9615052</code></pre>
<pre><code>## Testing correlation for: 3. Evening Peak</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v1meankWh and sdrc2.1v2meankWh
## t = 51.648, df = 971, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.8385040 0.8721458
## sample estimates:
## cor
## 0.8562301
##
##
## Spearman's rank correlation rho
##
## data: sdrc2.1v1meankWh and sdrc2.1v2meankWh
## S = 23526000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.8467606</code></pre>
</div>
<div id="compare-sdrc2.1-model-1-with-sdrc2.2-model" class="section level1">
<h1><span class="header-section-number">4</span> Compare SDRC2.1 Model 1 with SDRC2.2 model</h1>
<p>At LSOA level…</p>
<pre class="r"><code># plot LSOAs ----
p <- ggplot2::ggplot(mergedLSOA, aes(x = sdrc2.1v1meankWh,
y = sdrc2.2meankWh,
colour = zonecode)) +
geom_abline(intercept = 0, slope = 1) +
geom_point() +
facet_wrap(. ~ peakFlag) +
theme(legend.position = "None") +
labs(x = "mean kWh (Sim: Time Use model v1)",
y = "mean kWh (Sim: Observed kWh model)",
caption = paste0("Southampton: LSOAs\n",
"1:1 line shown"))
#xlim(0,0.8) +
#ylim(0,0.6) +
p</code></pre>
<pre><code>## Warning: Removed 432 rows containing missing values (geom_point).</code></pre>
<div class="figure">
<img src="compareModels_IMA2019_files/figure-html/compare_v1-1.png" alt="Half-hourly mean kWh for model 1 vs observed for each LSOA" width="672" />
<p class="caption">
(#fig:compare_v1)Half-hourly mean kWh for model 1 vs observed for each LSOA
</p>
</div>
<pre class="r"><code>ggplot2::ggsave(paste0(pPath,"lsoaProfiles_Winter-Weekdays-Compare-SDCR2.1_v1_SDRC2.2.png"), p)</code></pre>
<pre><code>## Saving 7 x 5 in image</code></pre>
<pre><code>## Warning: Removed 432 rows containing missing values (geom_point).</code></pre>
<pre class="r"><code>peaks <- unique(mergedLSOA$peakFlag)
for(p in peaks){
message("Testing correlation for: ", p)
print(with(mergedLSOA[peakFlag == p], cor.test(sdrc2.1v1meankWh,
sdrc2.2meankWh,
na.action = "na.omit")
))
print(with(mergedLSOA[peakFlag == p], cor.test(sdrc2.1v1meankWh,
sdrc2.2meankWh,
na.action = "na.omit",
method = "spearman")
))
}</code></pre>
<pre><code>## Testing correlation for: 4. All other times</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v1meankWh and sdrc2.2meankWh
## t = 107.09, df = 3056, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.8808839 0.8958154
## sample estimates:
## cor
## 0.8885848</code></pre>
<pre><code>## Warning in cor.test.default(sdrc2.1v1meankWh, sdrc2.2meankWh, na.action =
## "na.omit", : Cannot compute exact p-value with ties</code></pre>
<pre><code>##
## Spearman's rank correlation rho
##
## data: sdrc2.1v1meankWh and sdrc2.2meankWh
## S = 807030000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.8306725</code></pre>
<pre><code>## Testing correlation for: 1. Morning Peak</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v1meankWh and sdrc2.2meankWh
## t = 15.378, df = 554, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.4858961 0.6026934
## sample estimates:
## cor
## 0.5469508
##
##
## Spearman's rank correlation rho
##
## data: sdrc2.1v1meankWh and sdrc2.2meankWh
## S = 13489000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.5291273</code></pre>
<pre><code>## Testing correlation for: 2. Day time</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v1meankWh and sdrc2.2meankWh
## t = 6.6301, df = 2083, p-value = 4.259e-11
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.1014597 0.1855445
## sample estimates:
## cor
## 0.1437616
##
##
## Spearman's rank correlation rho
##
## data: sdrc2.1v1meankWh and sdrc2.2meankWh
## S = 1239100000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.1797718</code></pre>
<pre><code>## Testing correlation for: 3. Evening Peak</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v1meankWh and sdrc2.2meankWh
## t = 16.666, df = 971, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.4212534 0.5190775
## sample estimates:
## cor
## 0.4716152
##
##
## Spearman's rank correlation rho
##
## data: sdrc2.1v1meankWh and sdrc2.2meankWh
## S = 73407000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.5218617</code></pre>
</div>
<div id="compare-sdrc2.1-model-2-with-sdrc2.2-model" class="section level1">
<h1><span class="header-section-number">5</span> Compare SDRC2.1 Model 2 with SDRC2.2 model</h1>
<p>At LSOA level…</p>
<pre class="r"><code># plot LSOAs ----
p <- ggplot2::ggplot(mergedLSOA, aes(x = sdrc2.1v2meankWh,
y = sdrc2.2meankWh,
colour = zonecode)) +
geom_abline(intercept = 0, slope = 1) +
geom_point() +
facet_wrap(. ~ peakFlag) +
theme(legend.position = "None") +
labs(x = "mean kWh (Sim: Time Use model v2)",
y = "mean kWh (Sim: Observed kWh model)",
caption = paste0("Southampton: LSOAs\n",
"1:1 line shown"))
#xlim(0,0.8) +
#ylim(0,0.6) +
p</code></pre>
<pre><code>## Warning: Removed 432 rows containing missing values (geom_point).</code></pre>
<div class="figure">
<img src="compareModels_IMA2019_files/figure-html/compare_v2-1.png" alt="Half-hourly mean kWh for model 2 vs observed for each LSOA" width="672" />
<p class="caption">
(#fig:compare_v2)Half-hourly mean kWh for model 2 vs observed for each LSOA
</p>
</div>
<pre class="r"><code>ggplot2::ggsave(paste0(pPath,"lsoaProfiles_Winter-Weekdays-Compare-SDCR2.1_v2_SDRC2.2.png"), p)</code></pre>
<pre><code>## Saving 7 x 5 in image</code></pre>
<pre><code>## Warning: Removed 432 rows containing missing values (geom_point).</code></pre>
<pre class="r"><code>peaks <- unique(mergedLSOA$peakFlag)
for(p in peaks){
message("Testing correlation for: ", p)
print(with(mergedLSOA[peakFlag == p], cor.test(sdrc2.1v2meankWh,
sdrc2.2meankWh,
na.action = "na.omit")
))
print(with(mergedLSOA[peakFlag == p], cor.test(sdrc2.1v2meankWh,
sdrc2.2meankWh,
na.action = "na.omit",
method = "spearman")
))
}</code></pre>
<pre><code>## Testing correlation for: 4. All other times</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v2meankWh and sdrc2.2meankWh
## t = 98.363, df = 3056, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.8629776 0.8800105
## sample estimates:
## cor
## 0.8717572</code></pre>
<pre><code>## Warning in cor.test.default(sdrc2.1v2meankWh, sdrc2.2meankWh, na.action =
## "na.omit", : Cannot compute exact p-value with ties</code></pre>
<pre><code>##
## Spearman's rank correlation rho
##
## data: sdrc2.1v2meankWh and sdrc2.2meankWh
## S = 737500000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.8452601</code></pre>
<pre><code>## Testing correlation for: 1. Morning Peak</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v2meankWh and sdrc2.2meankWh
## t = 12.463, df = 554, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.4003834 0.5304691
## sample estimates:
## cor
## 0.4679572
##
##
## Spearman's rank correlation rho
##
## data: sdrc2.1v2meankWh and sdrc2.2meankWh
## S = 15710000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.4515852</code></pre>
<pre><code>## Testing correlation for: 2. Day time</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v2meankWh and sdrc2.2meankWh
## t = 6.8258, df = 2083, p-value = 1.142e-11
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.1056565 0.1896375
## sample estimates:
## cor
## 0.1479136
##
##
## Spearman's rank correlation rho
##
## data: sdrc2.1v2meankWh and sdrc2.2meankWh
## S = 1238600000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.1800939</code></pre>
<pre><code>## Testing correlation for: 3. Evening Peak</code></pre>
<pre><code>##
## Pearson's product-moment correlation
##
## data: sdrc2.1v2meankWh and sdrc2.2meankWh
## t = 12.946, df = 971, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.3287437 0.4359993
## sample estimates:
## cor
## 0.3836646
##
##
## Spearman's rank correlation rho
##
## data: sdrc2.1v2meankWh and sdrc2.2meankWh
## S = 89992000, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.4138357</code></pre>
</div>
<div id="compare-differences" class="section level1">
<h1><span class="header-section-number">6</span> Compare differences</h1>
<pre class="r"><code>mergedLSOA[, diffv1 := sdrc2.1v1meankWh - sdrc2.2meankWh]
mergedLSOA[, diffv2 := sdrc2.1v2meankWh - sdrc2.2meankWh]
t <- mergedLSOA[, .(meanDelta_v1 = mean(diffv1, na.rm = TRUE),
meanDelta_v2 = mean(diffv2, na.rm = TRUE)), keyby = .(peakFlag)]
kableExtra::kable(t, caption = "Summary of delta (+ve value means TU model higher)") %>%
kable_styling()</code></pre>
<table class="table" style="margin-left: auto; margin-right: auto;">
<caption>
(#tab:compare_delta)Summary of delta (+ve value means TU model higher)
</caption>
<thead>
<tr>
<th style="text-align:left;">
peakFlag
</th>
<th style="text-align:right;">
meanDelta_v1
</th>
<th style="text-align:right;">
meanDelta_v2
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left;">
<ol style="list-style-type: decimal">
<li>Morning Peak
</td>
<td style="text-align:right;">
0.1863666
</td>
<td style="text-align:right;">
-0.0032733
</td>
</tr>
<tr>
<td style="text-align:left;">
<ol start="2" style="list-style-type: decimal">
<li>Day time
</td>
<td style="text-align:right;">
0.0517761
</td>
<td style="text-align:right;">
0.0273071
</td>
</tr>
<tr>
<td style="text-align:left;">
<ol start="3" style="list-style-type: decimal">
<li>Evening Peak
</td>
<td style="text-align:right;">
0.1011569
</td>
<td style="text-align:right;">
0.0452777
</td>
</tr>
<tr>
<td style="text-align:left;">
<ol start="4" style="list-style-type: decimal">
<li>All other times
</td>
<td style="text-align:right;">
-0.0667253
</td>
<td style="text-align:right;">
-0.0901955
</td>
</tr>
</tbody>
</table></li>
</ol></li>
</ol></li>
</ol></li>
</ol>
<pre class="r"><code>t1 <- mergedLSOA[, .(delta = diffv1, halfHour)]
t1[, label := "TU model 1: observed model"]
t2 <- mergedLSOA[, .(delta = diffv2, halfHour)]
t2[, label := "TU model 2 : observed model"]
dt <- rbind(t1,t2)
# plot LSOAs ----
p <- ggplot2::ggplot(dt, aes(x = halfHour, group = halfHour)) +
geom_boxplot(aes(y = delta)) +
facet_grid(label ~ .) +
labs(y = "delta mean kWh",
caption = paste0("Southampton: LSOAs"))
p</code></pre>
<pre><code>## Warning: Removed 864 rows containing non-finite values (stat_boxplot).</code></pre>
<div class="figure">
<img src="compareModels_IMA2019_files/figure-html/compare_delta-1.png" alt="Half-hourly mean kWh for model 2 vs observed for each LSOA" width="672" />
<p class="caption">
(#fig:compare_delta)Half-hourly mean kWh for model 2 vs observed for each LSOA
</p>
</div>
<pre class="r"><code>ggplot2::ggsave(paste0(pPath,"lsoaProfiles_Winter-Weekdays-Compare-delta_SDCR2.1_SDRC2.2.png"), p)</code></pre>
<pre><code>## Saving 7 x 5 in image</code></pre>
<pre><code>## Warning: Removed 864 rows containing non-finite values (stat_boxplot).</code></pre>
</div>
<div id="input-data-description" class="section level1">
<h1><span class="header-section-number">7</span> Input data description</h1>
<pre class="r"><code>skimr::skim(sdrc2.1v1_LSOA_dt)</code></pre>
<pre><code>## Skim summary statistics
## n obs: 7008
## n variables: 3
##
## ── Variable type:character ────────────────────────────────────────────────────────────────────────
## variable missing complete n min max empty n_unique
## zonecode 0 7008 7008 9 9 0 146
##
## ── Variable type:difftime ─────────────────────────────────────────────────────────────────────────
## variable missing complete n min max median n_unique
## halfHour 0 7008 7008 0 secs 84600 secs 42300 secs 48
##
## ── Variable type:numeric ──────────────────────────────────────────────────────────────────────────
## variable missing complete n mean sd p0 p25 p50 p75 p100
## sdrc2.1v1meankWh 0 7008 7008 0.24 0.17 0 0.064 0.25 0.37 0.77
## hist
## ▇▃▅▆▃▂▁▁</code></pre>
<pre class="r"><code>skimr::skim(sdrc2.1v2_LSOA_dt)</code></pre>
<pre><code>## Skim summary statistics
## n obs: 7008
## n variables: 3
##
## ── Variable type:character ────────────────────────────────────────────────────────────────────────
## variable missing complete n min max empty n_unique
## zonecode 0 7008 7008 9 9 0 146
##
## ── Variable type:difftime ─────────────────────────────────────────────────────────────────────────
## variable missing complete n min max median n_unique
## halfHour 0 7008 7008 0 secs 84600 secs 42300 secs 48
##
## ── Variable type:numeric ──────────────────────────────────────────────────────────────────────────
## variable missing complete n mean sd p0 p25 p50 p75 p100
## sdrc2.1v2meankWh 0 7008 7008 0.2 0.15 0 0.04 0.21 0.31 0.71
## hist
## ▇▃▅▅▂▁▁▁</code></pre>
<pre class="r"><code>skimr::skim(sdrc2.2_LSOA_dt)</code></pre>
<pre><code>## Skim summary statistics
## n obs: 7104
## n variables: 3
##
## ── Variable type:character ────────────────────────────────────────────────────────────────────────
## variable missing complete n min max empty n_unique
## zonecode 0 7104 7104 9 9 0 148
##
## ── Variable type:difftime ─────────────────────────────────────────────────────────────────────────
## variable missing complete n min max median n_unique
## halfHour 0 7104 7104 0 secs 84600 secs 42300 secs 48
##
## ── Variable type:numeric ──────────────────────────────────────────────────────────────────────────
## variable missing complete n mean sd p0 p25 p50 p75 p100
## sdrc2.2meankWh 0 7104 7104 0.23 0.078 0.076 0.17 0.22 0.26 0.54
## hist
## ▂▅▇▂▂▁▁▁</code></pre>
</div>
<div id="references" class="section level1">
<h1><span class="header-section-number">8</span> References</h1>
</div>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>