<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/time-series-intervention-analysis-with-fuel-prices-by-ellis2013nz/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://freerangestats.info/blog/2018/08/14/fuel-prices"> free range statistics - R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>A couple of months ago <a rel="nofollow" href="http://freerangestats.info/blog/2018/07/01/petrol-spend" target="_blank">I blogged about consumer spending on vehicle fuel by income</a>. The impetus for that post was the introduction on 1 July 2018 of an 11.5 cent per litre <a rel="nofollow" href="https://www.transport.govt.nz/land/regional-fuel-tax/" target="_blank">“regional fuel tax” in Auckland</a>.</p>
<p>One vehement critic of the levy, largely on the grounds of its impact on the poor, has been <a rel="nofollow" href="https://nzinitiative.org.nz/about-us/our-people/sam-warburton/" target="_blank">Sam Warburton</a> (@Economissive on Twitter) of the New Zealand Initiative. Since early May 2018 (ie seven weeks before the fuel levy began), Sam has been collecting fuel prices from <a rel="nofollow" href="http://pricewatch.co.nz/" target="_blank">pricewatch.co.nz</a>, and he recently <a rel="nofollow" href="https://twitter.com/Economissive/status/1028861304306425856" target="_blank">made the data available</a>.</p>
<p>One of the issues of controversy about a levy like this is whether it will lead to “price spreading” – fuel companies absorbing some of the extra tax in Auckland and increasing prices in other regions. A relatively small number of firms make retail pricing decisions about fuel in New Zealand so it’s plausible that imperfect competition is making this possible. I had a look at the data to see if the intervention of the fuel levy in New Zealand’s biggest city can be seen to impact on fuel pricing in the rest of the country.</p>
<p>To cut to the chase, this graphic exemplifies my approach and results:</p>
<p><img width="100%" src="http://freerangestats.io/img/0129-auck-minus-rest.svg"></p>
<p>We see that after the spike at the time the tax was introduced, fuel prices in other regions have converged somewhat on Auckland’s prices (particularly when considering the relative change happening before the tax). The impact of the tax is still clearly felt much more strongly in Auckland than anywhere else (as of course would be expected – the question at issue is whether <em>anywhere</em> else would be impacted at all). More on that later.</p>
<h2>The data</h2>
<p>First, let’s look at the data Sam’s collected. The Twitter thread linked to above provides an Excel workbook on Dropbox. There’s a worksheet for each region (which are defined similarly, but not identically, to New Zealand’s official Regions) as well as one describing the source. For each region we have data on fuel prices for combinations of Company, Date, fuel type (eg diesel, 91 octane, etc) and Region. If we plot all the data other than liquid petroleum gas (which has particularly sparse observations), it looks like this:</p>
<p><img src="https://i2.wp.com/freerangestats.io/img/0129-overview.png?w=100%25" data-recalc-dims="1"></p>
<p>“Companies” have been sorted in order of increasing average price for that graphic, but fairly crudely (ie not taking into account different mixes of fuel type by Company).</p>
<p>We can see we have more data for 91 octane petrol than the other types. For the rest of this post I’ll be focusing on just 91 octane.</p>
<p>Here’s the R code to tidy up the data to this point and draw the graphic. It assumes you’ve manually downloaded the Excel workbook to your working folder (I’m currently working with severely restricted internet, so couldn’t experiment in automating that process.)</p>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>library</span><span>(</span><span>scales</span><span>)</span><span>
</span><span>library</span><span>(</span><span>openxlsx</span><span>)</span><span>
</span><span>library</span><span>(</span><span>nlme</span><span>)</span><span>
</span><span># Import data:
</span><span>sn</span><span> </span><span>&lt;-</span><span> </span><span>getSheetNames</span><span>(</span><span>&quot;fuel price data.xlsx&quot;</span><span>)</span><span>
</span><span>sn</span><span> </span><span>&lt;-</span><span> </span><span>sn</span><span>[</span><span>sn</span><span> </span><span>!=</span><span> </span><span>&quot;Source&quot;</span><span>]</span><span>
</span><span>fuel_orig</span><span> </span><span>&lt;-</span><span> </span><span>list</span><span>()</span><span>
</span><span>for</span><span>(</span><span>i</span><span> </span><span>in</span><span> </span><span>1</span><span>:</span><span>length</span><span>(</span><span>sn</span><span>)){</span><span>
</span><span>tmp</span><span> </span><span>&lt;-</span><span> </span><span>read.xlsx</span><span>(</span><span>&quot;fuel price data.xlsx&quot;</span><span>,</span><span> </span><span>sheet</span><span> </span><span>=</span><span> </span><span>sn</span><span>[</span><span>i</span><span>],</span><span> </span><span>cols</span><span> </span><span>=</span><span> </span><span>1</span><span>:</span><span>7</span><span>,</span><span> </span><span>detectDates</span><span> </span><span>=</span><span> </span><span>TRUE</span><span>,</span><span> </span><span>na.strings</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>&quot;NA&quot;</span><span>,</span><span> </span><span>&quot;n/a&quot;</span><span>))</span><span>
</span><span>tmp</span><span>[</span><span> </span><span>,</span><span> </span><span>&quot;region&quot;</span><span>]</span><span> </span><span>&lt;-</span><span> </span><span>sn</span><span>[</span><span>i</span><span>]</span><span>
</span><span>fuel_orig</span><span>[[</span><span>i</span><span>]]</span><span> </span><span>&lt;-</span><span> </span><span>tmp</span><span>
</span><span>}</span><span>
</span><span># Combine into a single data frame
</span><span>fuel_df</span><span> </span><span>&lt;-</span><span> </span><span>do.call</span><span>(</span><span>&quot;rbind&quot;</span><span>,</span><span> </span><span>fuel_orig</span><span>)</span><span>
</span><span># some useful extra information:
</span><span>south_island</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>&quot;Canterbury&quot;</span><span>,</span><span> </span><span>&quot;Nelson&quot;</span><span>,</span><span> </span><span>&quot;Otago&quot;</span><span>,</span><span> </span><span>&quot;Southland&quot;</span><span>,</span><span> </span><span>&quot;West Coast&quot;</span><span>)</span><span>
</span><span>big_four</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>&quot;CALTEX&quot;</span><span>,</span><span> </span><span>&quot;Z ENERGY&quot;</span><span>,</span><span> </span><span>&quot;BP&quot;</span><span>,</span><span> </span><span>&quot;MOBIL&quot;</span><span>)</span><span>
</span><span># Make long, thin, tidy version:
</span><span>fuel_tidy</span><span> </span><span>&lt;-</span><span> </span><span>fuel_df</span><span> </span><span>%>%</span><span>
</span><span>select</span><span>(</span><span>-</span><span>LPG</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>gather</span><span>(</span><span>fueltype</span><span>,</span><span> </span><span>value</span><span>,</span><span> </span><span>-</span><span>Company</span><span>,</span><span> </span><span>-</span><span>Date</span><span>,</span><span> </span><span>-</span><span>region</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>!</span><span>is.na</span><span>(</span><span>value</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>island</span><span> </span><span>=</span><span> </span><span>ifelse</span><span>(</span><span>region</span><span> </span><span>%in%</span><span> </span><span>south_island</span><span>,</span><span> </span><span>&quot;South&quot;</span><span>,</span><span> </span><span>&quot;North&quot;</span><span>),</span><span>
</span><span>company_type</span><span> </span><span>=</span><span> </span><span>ifelse</span><span>(</span><span>Company</span><span> </span><span>%in%</span><span> </span><span>big_four</span><span>,</span><span> </span><span>&quot;Big Four&quot;</span><span>,</span><span> </span><span>&quot;Smaller&quot;</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>region</span><span> </span><span>=</span><span> </span><span>fct_reorder</span><span>(</span><span>region</span><span>,</span><span> </span><span>as.numeric</span><span>(</span><span>as.factor</span><span>(</span><span>island</span><span>))),</span><span>
</span><span>Company</span><span> </span><span>=</span><span> </span><span>fct_reorder</span><span>(</span><span>Company</span><span>,</span><span> </span><span>value</span><span>))</span><span>
</span><span># Overview graphic:
</span><span>fuel_tidy</span><span> </span><span>%>%</span><span>
</span><span>ggplot</span><span>(</span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>Date</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>value</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>Company</span><span>))</span><span> </span><span>+</span><span>
</span><span>facet_grid</span><span>(</span><span>fueltype</span><span>~</span><span>region</span><span>,</span><span> </span><span>scales</span><span> </span><span>=</span><span> </span><span>&quot;free_y&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>size</span><span> </span><span>=</span><span> </span><span>0.8</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_y_continuous</span><span>(</span><span>&quot;Price per litre at the pump&quot;</span><span>,</span><span> </span><span>label</span><span> </span><span>=</span><span> </span><span>dollar</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>&quot;Date in 2018&quot;</span><span>,</span><span> </span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Source: pricewatch.co.nz, collated by @Economissive&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>&quot;Petrol prices in New Zealand over several months in mid 2018&quot;</span><span>)</span><span> </span><span>+</span><span> </span><span>guides</span><span>(</span><span>colour</span><span> </span><span>=</span><span> </span><span>guide_legend</span><span>(</span><span>override.aes</span><span> </span><span>=</span><span> </span><span>list</span><span>(</span><span>size</span><span>=</span><span>5</span><span>)))</span><span> </span><span>+</span><span>
</span><span>scale_colour_brewer</span><span>(</span><span>palette</span><span> </span><span>=</span><span> </span><span>&quot;Set1&quot;</span><span>)</span></code></pre>
</figure>
<h2>Regional comparisons with Auckland</h2>
<p>I tried a couple of different ways of comparing prices in individual regions with those in Auckland. I think this graphic is probably the most informative and straightforward:</p>
<p><img width="100%" src="http://freerangestats.io/img/0129-petrol-comp-auckland.svg"></p>
<p>The grey line in the background of each facet represents Auckland’s price; the shaded blue rectangle is the post-tax period (ie 1 July 2018 and onwards). The grey shaded area shows the difference between the given region’s price and that of Auckland.</p>
<p>We can see a lot of regional variation here, and an interesting pattern with three (or maybe even all) of the South Island regions experiencing price declines in June then picking up in July. Of course, the 11.5 cent increase in price in Auckland is very obvious in the grey lines and shading. Later on I’ll be using time series intervention analysis on this data; this is an approach commonly used in evaluating the impact of evaluations. If we were only after the direct impact, there would be no need to do any statistical tests beyond this graphic above; the big spike in prices hits you between the eyes, and there is no doubt about the discontinuity in Auckland’s prices on 1 July! The question, of course, is how sustained that impact is, and whether it bled into secondary impacts in other regions.</p>
<p>Here’s a second graphic that tries to visually simplify what’s going on, by calculating a single line of the ratio of prices in each region to those in Auckland. I think what it gains in visual simplicity (less lines and shading) it loses in clear interpretability. In particular, it’s not possible to tell from this graphic what changes in the graphic come from changes in Auckland, and which come from changes in the comparison region. That’s not a deal-breaker for using a graphic like this, but it does strongly suggest we should also include the first one, with the rawer average prices per region plainly shown without transformation, for context.</p>
<p><img width="100%" src="http://freerangestats.io/img/0129-petrol-perc-auckland.svg"></p>
<p>Note that even after the introduction of the Auckland-specific fuel tax, 91 octane petrol in several regions still costs more than in Auckland. The regions with prices higher than Auckland in the most recent data in the collection are West Coast, Otago, Nelson, Canterbury and Wellington.</p>
<p>Here’s the R code for those two graphics:</p>
<figure>
<pre><code data-lang="r"><span># construct two convenient summaries of the data, different ways of comparing regions to Auckland:
</span><span>p</span><span>91</span><span> </span><span>&lt;-</span><span> </span><span>fuel_tidy</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>fueltype</span><span> </span><span>==</span><span> </span><span>&quot;91&quot;</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>region</span><span>,</span><span> </span><span>island</span><span>,</span><span> </span><span>Date</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>summarise</span><span>(</span><span>value</span><span> </span><span>=</span><span> </span><span>mean</span><span>(</span><span>value</span><span>,</span><span> </span><span>tr</span><span> </span><span>=</span><span> </span><span>0.2</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>ungroup</span><span>()</span><span> </span><span>p</span><span>91</span><span>_</span><span>rel</span><span> </span><span>&lt;-</span><span> </span><span>p</span><span>91</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>Date</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>Auckland</span><span> </span><span>=</span><span> </span><span>value</span><span>[</span><span>region</span><span> </span><span>==</span><span> </span><span>&quot;Auckland&quot;</span><span>])</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>!</span><span> </span><span>region</span><span> </span><span>%in%</span><span> </span><span>c</span><span>(</span><span>&quot;Auckland&quot;</span><span>,</span><span> </span><span>&quot;Wairarapa&quot;</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>perc_of_auck</span><span> </span><span>=</span><span> </span><span>value</span><span> </span><span>/</span><span> </span><span>Auckland</span><span>)</span><span>
</span><span># Plot showing original price data
</span><span>ggplot</span><span>()</span><span> </span><span>+</span><span>
</span><span># annoying trick necessary here to draw a semi-transparent background rectangle: </span><span> </span><span>geom_rect</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>data.frame</span><span>(</span><span>&quot;hello world&quot;</span><span>),</span><span> </span><span>xmin</span><span> </span><span>=</span><span> </span><span>as.Date</span><span>(</span><span>&quot;2018-07-01&quot;</span><span>),</span><span> </span><span>xmax</span><span> </span><span>=</span><span> </span><span>Inf</span><span>,</span><span> </span><span>ymin</span><span> </span><span>=</span><span> </span><span>-</span><span>Inf</span><span>,</span><span> </span><span>ymax</span><span> </span><span>=</span><span> </span><span>Inf</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>&quot;blue&quot;</span><span>,</span><span> </span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.1</span><span>)</span><span> </span><span>+</span><span>
</span><span># now draw the actual data:
</span><span> </span><span>geom_ribbon</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>p</span><span>91</span><span>_</span><span>rel</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>Date</span><span>,</span><span> </span><span>ymin</span><span> </span><span>=</span><span> </span><span>Auckland</span><span>,</span><span> </span><span>ymax</span><span> </span><span>=</span><span> </span><span>value</span><span>),</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>&quot;grey&quot;</span><span>,</span><span> </span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.5</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_line</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>p</span><span>91</span><span>_</span><span>rel</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>Date</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>Auckland</span><span>),</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>&quot;grey50&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_line</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>p</span><span>91</span><span>_</span><span>rel</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span>=</span><span> </span><span>Date</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>value</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>island</span><span>),</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>1.2</span><span>)</span><span> </span><span>+</span><span>
</span><span>facet_wrap</span><span>(</span><span>~</span><span>region</span><span>,</span><span> </span><span>ncol</span><span> </span><span>=</span><span> </span><span>3</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_y_continuous</span><span>(</span><span>&quot;Price of 91 octane petrol compared to in Auckland\n&quot;</span><span>,</span><span> </span><span>label</span><span> </span><span>=</span><span> </span><span>dollar</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>&quot;2018; grey line shows Auckland&quot;</span><span>,</span><span>
</span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Source: pricewatch.co.nz, collated by @Economissive&quot;</span><span>)</span><span>
</span><span># ratio of Auckland prices to others
</span><span>ggplot</span><span>()</span><span> </span><span>+</span><span>
</span><span>geom_hline</span><span>(</span><span>yintercept</span><span> </span><span>=</span><span> </span><span>1</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>&quot;grey50&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_rect</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>data.frame</span><span>(</span><span>&quot;hello world&quot;</span><span>),</span><span> </span><span>xmin</span><span> </span><span>=</span><span> </span><span>as.Date</span><span>(</span><span>&quot;2018-07-01&quot;</span><span>),</span><span> </span><span>xmax</span><span> </span><span>=</span><span> </span><span>Inf</span><span>,</span><span> </span><span>ymin</span><span> </span><span>=</span><span> </span><span>-</span><span>Inf</span><span>,</span><span> </span><span>ymax</span><span> </span><span>=</span><span> </span><span>Inf</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>&quot;blue&quot;</span><span>,</span><span> </span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.1</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_line</span><span>(</span><span>data</span><span> </span><span>=</span><span> </span><span>p</span><span>91</span><span>_</span><span>rel</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span>=</span><span> </span><span>Date</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>perc_of_auck</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>island</span><span>))</span><span> </span><span>+</span><span>
</span><span>facet_wrap</span><span>(</span><span>~</span><span>region</span><span>,</span><span> </span><span>ncol</span><span> </span><span>=</span><span> </span><span>3</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_y_continuous</span><span>(</span><span>&quot;Price of 91 octane petrol as a percentage of in Auckland\n&quot;</span><span>,</span><span> </span><span>label</span><span> </span><span>=</span><span> </span><span>percent</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>&quot;2018&quot;</span><span>,</span><span>
</span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Source: pricewatch.co.nz, collated by @Economissive&quot;</span><span>)</span></code></pre>
</figure>
<h2>Modelling the impact of an intervention over time</h2>
<p>When it came to directly addressing our question of interest regarding price spreading, I opted to group all non-Auckland regions together and compare average prices there with those in Auckland. There are better ways of modelling this that make full use of the granular data available (mostly involving mixed effects models, and more complex ways of representing the trend over time than linearly; and they would certainly take into account weighting from the spread in population over regions) but they come with big costs in complexity that I don’t have time for right now. Plus, the difference-of-averages method struck me as the easiest way to interpret and communicate, not to mention think about, the question of whether prices were converging back towards eachother after the initial shock of the addition of the tax. This leads me to the graphic I showed earlier in this post:</p>
<p><img width="100%" src="http://freerangestats.io/img/0129-auck-minus-rest.svg"></p>
<p>The linear regression lines shown in that graphic are a simplified version of the formal statistical model we want to fit and use to test our hypothesis. We’re looking for evidence that the slope of the post-tax line is materially less than the slope of the pre-tax line; in other words, is the gap in pricing between Auckland and other regions declining after the initial 11.5 cent shock of the tax.</p>
<p>I defined this as a simple linear model, but fit it using generalized least squares with time series residuals (auto-regressive moving average of order (1, 1)). This is straightforward to specify and fit using the <code>gls</code> function in Pinheiro, Bates et al’s <code>nlme</code> package, but there are other ways of doing it too.</p>
<p>This results in the following:</p>
<table>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td></td>
<td><em>Dependent variable:</em></td>
</tr>
<tr>
<td></td>
<td colspan="1"></td>
</tr>
<tr>
<td></td>
<td>value</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>Date</td>
<td>0.001<sup>**</sup></td>
</tr>
<tr>
<td></td>
<td>(0.0003)</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>post_tax</td>
<td>19.159<sup>**</sup></td>
</tr>
<tr>
<td></td>
<td>(7.804)</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>Date:post_tax</td>
<td>-0.001<sup>**</sup></td>
</tr>
<tr>
<td></td>
<td>(0.0004)</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td>Constant</td>
<td>-10.470<sup>**</sup></td>
</tr>
<tr>
<td></td>
<td>(4.946)</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>Observations</td>
<td>93</td>
</tr>
<tr>
<td>Log Likelihood</td>
<td>330.591</td>
</tr>
<tr>
<td>Akaike Inf. Crit.</td>
<td>-647.182</td>
</tr>
<tr>
<td>Bayesian Inf. Crit.</td>
<td>-629.761</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td><em>Note:</em></td>
<td><sup>*</sup>p&lt;0.1; <sup>**</sup>p&lt;0.05; <sup>***</sup>p&lt;0.01</td>
</tr>
</table>
<p>…which simply confirms what is visually obvious, that there is indeed statistically significant evidence of the slope changing direction downwards after the tax is introduced. In other words, we do have evidence consistent with some degree of “spreading” taking place. After the initial clean shock of the introduction of the tax, prices in Auckland and in the rest of the country are indeed converging somewhat; although nowhere near as much as the full cost of the tax.</p>
<p>This effect holds whether I use all of New Zealand as the comparison point or just the South Island (which has less competition in fuel retailers) or just the North Island, although in the latter case the effect is not as strong (as can be seen in the graphic). It also doesn’t seem to matter whether we use all available prices, or just those of the “big four” companies that are present in all regions.</p>
<p>We can’t say for sure the effect comes from introducing the tax from just looking at the numbers. Drawing that conclusion would require carefully considering any other possible causality options. For example, one driver of the pattern we’re seeing is clearly that prices in Canterbury, Nelson and Otago stopped declining and started rising slightly in July. What are other plausible causes of that pattern? Understanding and considering such alternative theories would need more knowledge of the fuel market in New Zealand than I have, so I’ll leave it to others to debate that. All I can safely conclude is what I wrote above:</p>
<blockquote>
<p>after the spike caused by the tax, fuel prices in Auckland and in the rest of the country are converging somewhat (although much less than the full cost of the tax), and plausibly this is because of companies’ price adjustments down in Auckland and up elsewhere to spread the cost of the tax over a broader base.</p>
</blockquote>
<p>Here’s the code for that final graphic and statistical modelling;</p>
<figure>
<pre><code data-lang="r"><span># Data on the difference between Auckland's average price and those in other areas:
</span><span>diff_data</span><span> </span><span>&lt;-</span><span> </span><span>fuel_tidy</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>fueltype</span><span> </span><span>==</span><span> </span><span>&quot;91&quot;</span><span> </span><span>&amp;</span><span> </span><span>company_type</span><span> </span><span>==</span><span> </span><span>&quot;Big Four&quot;</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>Date</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>summarise</span><span>(</span><span>auck_v_rest</span><span> </span><span>=</span><span> </span><span>mean</span><span>(</span><span>value</span><span>[</span><span>region</span><span> </span><span>==</span><span> </span><span>&quot;Auckland&quot;</span><span>])</span><span> </span><span>-</span><span> </span><span>mean</span><span>(</span><span>value</span><span>[</span><span>region</span><span> </span><span>!=</span><span> </span><span>&quot;Auckland&quot;</span><span>]),</span><span>
</span><span>auck_v_si</span><span> </span><span>=</span><span> </span><span>mean</span><span>(</span><span>value</span><span>[</span><span>region</span><span> </span><span>==</span><span> </span><span>&quot;Auckland&quot;</span><span>])</span><span> </span><span>-</span><span> </span><span>mean</span><span>(</span><span>value</span><span>[</span><span>island</span><span> </span><span>==</span><span> </span><span>&quot;South&quot;</span><span>]),</span><span>
</span><span>auck_v_ni</span><span> </span><span>=</span><span> </span><span>mean</span><span>(</span><span>value</span><span>[</span><span>region</span><span> </span><span>==</span><span> </span><span>&quot;Auckland&quot;</span><span>])</span><span> </span><span>-</span><span> </span><span>mean</span><span>(</span><span>value</span><span>[</span><span>island</span><span> </span><span>==</span><span> </span><span>&quot;North&quot;</span><span> </span><span>&amp;</span><span> </span><span>region</span><span> </span><span>!=</span><span> </span><span>&quot;Auckland&quot;</span><span>]),</span><span>
</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>post_tax</span><span> </span><span>=</span><span> </span><span>as.integer</span><span>(</span><span>Date</span><span> </span><span>>=</span><span> </span><span>as.Date</span><span>(</span><span>&quot;2018-07-01&quot;</span><span>)))</span><span> </span><span>%>%</span><span>
</span><span>gather</span><span>(</span><span>comparison</span><span>,</span><span> </span><span>value</span><span>,</span><span> </span><span>-</span><span>Date</span><span>,</span><span> </span><span>-</span><span>post_tax</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>comparison</span><span> </span><span>=</span><span> </span><span>case_when</span><span>(</span><span>
</span><span>comparison</span><span> </span><span>==</span><span> </span><span>&quot;auck_v_si&quot;</span><span> </span><span>~</span><span> </span><span>&quot;Compared to South Island&quot;</span><span>,</span><span>
</span><span>comparison</span><span> </span><span>==</span><span> </span><span>&quot;auck_v_ni&quot;</span><span> </span><span>~</span><span> </span><span>&quot;Compared to rest of North island&quot;</span><span>,</span><span>
</span><span>comparison</span><span> </span><span>==</span><span> </span><span>&quot;auck_v_rest&quot;</span><span> </span><span>~</span><span> </span><span>&quot;Compared to all NZ except Auckland&quot;</span><span>))</span><span>
</span><span># Graphic:
</span><span>ggplot</span><span>(</span><span>diff_data</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>Date</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>value</span><span>))</span><span> </span><span>+</span><span>
</span><span>facet_wrap</span><span>(</span><span>~</span><span>comparison</span><span>,</span><span> </span><span>ncol</span><span> </span><span>=</span><span> </span><span>3</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_line</span><span>()</span><span> </span><span>+</span><span>
</span><span>geom_smooth</span><span>(</span><span>aes</span><span>(</span><span>group</span><span> </span><span>=</span><span> </span><span>post_tax</span><span>),</span><span> </span><span>method</span><span> </span><span>=</span><span> </span><span>&quot;lm&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_y_continuous</span><span>(</span><span>&quot;Average price of 91 octane petrol in Auckland\nminus average price in comparison area&quot;</span><span>,</span><span>
</span><span>label</span><span> </span><span>=</span><span> </span><span>dollar</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>&quot;Date in 2018\nAverage prices have not been weighted by population or sales&quot;</span><span>,</span><span>
</span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Source: pricewatch.co.nz, collated by @Economissive&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>&quot;Fuel prices in Auckland compared to three other comparison areas&quot;</span><span>,</span><span>
</span><span>&quot;Restricted to prices from BP, Caltex, Mobil and Z Energy&quot;</span><span>)</span><span>
</span><span># Modelling:
# first, make a convenient subset of the data (useful later in various tests and diagnostics):
</span><span>D</span><span> </span><span>&lt;-</span><span> </span><span>subset</span><span>(</span><span>diff_data</span><span>,</span><span> </span><span>comparison</span><span> </span><span>==</span><span> </span><span>&quot;Compared to all NZ except Auckland&quot;</span><span>)</span><span>
</span><span># Fit model, taking care to specify time series residuals, which aren't as useful for inference
# as i.i.d. residuals and hence lead to more conservative inference:
</span><span>model</span><span> </span><span>&lt;-</span><span> </span><span>gls</span><span>(</span><span>value</span><span> </span><span>~</span><span> </span><span>Date</span><span> </span><span>*</span><span> </span><span>post_tax</span><span>,</span><span> </span><span>data</span><span> </span><span>=</span><span> </span><span>subset</span><span>(</span><span>diff_data</span><span>,</span><span> </span><span>comparison</span><span> </span><span>==</span><span> </span><span>&quot;Compared to all NZ except Auckland&quot;</span><span>),</span><span>
</span><span>cor</span><span> </span><span>=</span><span> </span><span>corARMA</span><span>(</span><span>p</span><span> </span><span>=</span><span> </span><span>1</span><span>,</span><span> </span><span>q</span><span> </span><span>=</span><span> </span><span>1</span><span>))</span><span>
</span><span># print-friendly summary of coefficieints
</span><span>stargazer</span><span>::</span><span>stargazer</span><span>(</span><span>model</span><span>,</span><span> </span><span>type</span><span> </span><span>=</span><span> </span><span>&quot;html&quot;</span><span>)</span><span>
</span><span># more comprehensive summary (not shown in blog):
</span><span>summary</span><span>(</span><span>model</span><span>)</span><span> </span></code></pre>
</figure>
<h2>Observations per region</h2>
<p>A topic of interest in fuel pricing debate in New Zealand is the number of companies present in each region, with a particular focus on the presence of Gull. In case of interest, here are the observations in the pricewatch data collected by Sam Warburton:</p>
<table>
<thead>
<tr>
<th>region</th>
<th>–</th>
<th>ALTERNATE FUEL</th>
<th>GULL</th>
<th>CHALLENGE</th>
<th>CALTEX</th>
<th>MOBIL</th>
<th>Z ENERGY</th>
<th>GAS ALLEY</th>
<th>BP</th>
</tr>
</thead>
<tbody>
<tr>
<td>Auckland</td>
<td>206</td>
<td>143</td>
<td>349</td>
<td>251</td>
<td>279</td>
<td>372</td>
<td>279</td>
<td>279</td>
<td>372</td>
</tr>
<tr>
<td>Bay of Plenty</td>
<td>262</td>
<td>200</td>
<td>295</td>
<td>202</td>
<td>278</td>
<td>264</td>
<td>279</td>
<td>161</td>
<td>370</td>
</tr>
<tr>
<td>Coromandel</td>
<td>3</td>
<td>6</td>
<td>249</td>
<td>4</td>
<td>209</td>
<td>219</td>
<td>233</td>
<td>69</td>
<td>277</td>
</tr>
<tr>
<td>Waikato</td>
<td>0</td>
<td>0</td>
<td>228</td>
<td>227</td>
<td>276</td>
<td>302</td>
<td>278</td>
<td>220</td>
<td>367</td>
</tr>
<tr>
<td>Hawke’s Bay</td>
<td>0</td>
<td>45</td>
<td>217</td>
<td>16</td>
<td>261</td>
<td>228</td>
<td>255</td>
<td>132</td>
<td>345</td>
</tr>
<tr>
<td>Northland</td>
<td>0</td>
<td>0</td>
<td>205</td>
<td>52</td>
<td>274</td>
<td>229</td>
<td>256</td>
<td>268</td>
<td>275</td>
</tr>
<tr>
<td>Manawatū-Whanganui</td>
<td>0</td>
<td>108</td>
<td>193</td>
<td>120</td>
<td>275</td>
<td>265</td>
<td>277</td>
<td>176</td>
<td>371</td>
</tr>
<tr>
<td>Taranaki</td>
<td>0</td>
<td>184</td>
<td>178</td>
<td>188</td>
<td>243</td>
<td>88</td>
<td>274</td>
<td>188</td>
<td>301</td>
</tr>
<tr>
<td>Wellington</td>
<td>0</td>
<td>91</td>
<td>78</td>
<td>252</td>
<td>278</td>
<td>277</td>
<td>279</td>
<td>213</td>
<td>372</td>
</tr>
<tr>
<td>East Coast</td>
<td>0</td>
<td>41</td>
<td>71</td>
<td>158</td>
<td>221</td>
<td>122</td>
<td>145</td>
<td>104</td>
<td>211</td>
</tr>
<tr>
<td>Central Plateau</td>
<td>0</td>
<td>0</td>
<td>44</td>
<td>51</td>
<td>159</td>
<td>244</td>
<td>275</td>
<td>0</td>
<td>295</td>
</tr>
<tr>
<td>Wairarapa</td>
<td>0</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>2</td>
<td>42</td>
<td>3</td>
<td>2</td>
<td>103</td>
</tr>
<tr>
<td>Canterbury</td>
<td>0</td>
<td>262</td>
<td>0</td>
<td>279</td>
<td>279</td>
<td>278</td>
<td>279</td>
<td>245</td>
<td>372</td>
</tr>
<tr>
<td>Nelson</td>
<td>0</td>
<td>50</td>
<td>0</td>
<td>34</td>
<td>216</td>
<td>237</td>
<td>263</td>
<td>163</td>
<td>237</td>
</tr>
<tr>
<td>Otago</td>
<td>0</td>
<td>225</td>
<td>0</td>
<td>226</td>
<td>273</td>
<td>265</td>
<td>277</td>
<td>116</td>
<td>364</td>
</tr>
<tr>
<td>Southland</td>
<td>0</td>
<td>114</td>
<td>0</td>
<td>197</td>
<td>249</td>
<td>195</td>
<td>226</td>
<td>98</td>
<td>245</td>
</tr>
<tr>
<td>West Coast</td>
<td>0</td>
<td>115</td>
<td>0</td>
<td>227</td>
<td>119</td>
<td>121</td>
<td>115</td>
<td>65</td>
<td>242</td>
</tr>
</tbody>
</table>
<p>That table was generated by:</p>
<figure>
<pre><code data-lang="r"><span>library</span><span>(</span><span>knitr</span><span>)</span><span>
</span><span>fuel_tidy</span><span> </span><span>%>%</span><span>
</span><span>group_by</span><span>(</span><span>region</span><span>,</span><span> </span><span>Company</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>summarise</span><span>(</span><span>freq</span><span> </span><span>=</span><span> </span><span>n</span><span>())</span><span> </span><span>%>%</span><span>
</span><span>spread</span><span>(</span><span>Company</span><span>,</span><span> </span><span>freq</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>0</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>arrange</span><span>(</span><span>desc</span><span>(</span><span>GULL</span><span>))</span><span> </span><span>%>%</span><span>
</span><span>kable</span></code></pre>
</figure>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://freerangestats.info/blog/2018/08/14/fuel-prices"> free range statistics - R</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/3UZf8d4xqrQ" height="1"></a></div>