<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/spend-on-petrol-by-income-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/07/01/petrol-spend"> free range statistics - R</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>Fuel tax debates</h2>
<p>So, there’s currently a <a rel="nofollow" href="https://twitter.com/simonbwilson/status/1012792274332233728" target="_blank">vibrant debate on a small New Zealandish corner of Twitter</a> about a petrol tax coming into effect in Auckland today, and the different impacts of such taxes on richer and poorer households.</p>
<p>The Government has released analysis from the Stats NZ Household Expenditure Survey <a rel="nofollow" href="https://www.nzherald.co.nz/nz/news/article.cfm?c_id=1&objectid=12078915" target="_blank">showing higher petrol consumption per household for higher income households</a> (and hence paying more of the new tax). <a rel="nofollow" href="https://twitter.com/Economissive/status/1012944031469338625" target="_blank">Sam Warburton, an economist with the New Zealand Institute, argues in response</a> that poorer households have older, often larger, less efficient vehicles, leading to higher fuel costs per kilometre. This means a fuel tax will not only result in poor people paying more as a percentage of their income (as any sales tax on basic commodities will do), but paying more <em>per kilometre</em>. Further, poor people are more likely to live out of the big urban centres, and when in an urban area are less likely to be well serviced by public transport.</p>
<p>Mr Warburton also argues that the results from the Household Expenditure Survey are misleading because they include “people who can’t afford or otherwise don’t own cars”. <a rel="nofollow" href="https://twitter.com/Economissive/status/981306458699476992" target="_blank">His own analysis </a> from the Ministry of Transport’s Household Travel Survey shows that households including two or more children, with Māori, with unemployed people, or in the poorer regions all pay more tax per kilometre.</p>
<p>I’m totally convinced by Mr Warburton on the argument that poorer people are paying more tax per kilometre, which makes a fuel tax a particularly <a rel="nofollow" href="https://en.wikipedia.org/wiki/Regressive_tax" target="_blank">regressive tax</a>. Even paying the same rate per kilometre would be regressive because transport costs are a higher proportion of income for poorer people; so more tax <em>per kilometre</em> is really rubbing salt into the wound. I’m not convinced though by the suggestion that they will pay more of the new tax even in absolute terms; I’m inclined to trust the Household Economic Survey on this one.</p>
<h2>The USA Consumer Expenditure Survey</h2>
<p>One good thing about this debate was it motivated me to do something that’s been on my list for a while, which is to get my toes in the water with the USA Bureau of Labor Statistics’ impressive <a rel="nofollow" href="https://www.bls.gov/cex/home.htm" target="_blank">Consumer Expenditure Survey</a>. Huge amounts of confidentialised microdata from this mammoth program are freely available for download – without even filling in any forms! This makes it suitable to use in a blog post in a way I couldn’t with the New Zealand or Australian Household Expenditure Surveys (both of which have Confidentialised Unit Record Files for researchers, but with restrictions that get in the way of quick usage in public like this).</p>
<p>Big caveat for what follows – literally I looked at this survey for the first time today, and it is <em>very complex</em>. Just for starters, the Consumer Expenditure Survey really <a rel="nofollow" href="https://www.bls.gov/cex/" target="_blank">comprises two surveys</a> – an Interview Survey for “major and/or recurring items” and the Diary Survey for “minor or frequently purchased items”. It is very possible that I am using not-the-best variables. Feedback welcomed.</p>
<h3>Densities of income and fuel spend</h3>
<p>Let’s get started by downloading the data. Here’s a couple of graphs of what I think are the main variables of interest here. These draw on:</p>
<ul>
<li><code>gasmocq</code> “Gasoline and motor oil this quarter”</li>
<li><code>fincbtxm</code> “Total amount of family income – imputed or collected” (in the past 12 months? although the data dictionary only implies this)</li>
<li><code>fam_size</code> “Number of Members in CU” (ie in responding household)</li>
<li><code>bls_urbn</code> “Is this CU located in an urban or a rural area”</li>
</ul>
<p><img width="100%" src="http://freerangestats.io/img/0124-densities.svg"></p>
<p><img width="100%" src="http://freerangestats.io/img/0124-densities-inc.svg"></p>
<p>Both these graphics are showing a quantity divided by household size to get a simple estimate of amount per person. A better approach would be to used equivalised figures, taking into account economies of scale for larger households and different cost structures for different age groups, but it probably would have taken me all morning just to work out a safe way of doing that so I’ve stuck with the simpler method.</p>
<p>Both these graphics – and most of those that follow – also use <a rel="nofollow" href="http://freerangestats.info/blog/2015/09/05/creating-a-scale-transformation" target="_blank">John and Draper’s modulus transform that I wrote about in some of my first ever posts on this blog</a>. It’s a great way to effectively visualise heavily skewed data that has zero and negative values as well as positive, a common occurrence with economic variables. The helper functions for the transformation are available in my bag-of-misc R package <code>frs</code> available from GitHub.</p>
<p>Here’s code to do that download, prepare the data for later and draw graphs:</p>
<figure>
<pre><code data-lang="r"><span># mandatory reading: https://www.bls.gov/cex/pumd_novice_guide.pdf
</span><span>
</span><span>library</span><span>(</span><span>haven</span><span>)</span><span>
</span><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>frs</span><span>)</span><span> </span><span># for modulus transforms of scales
</span><span>library</span><span>(</span><span>MASS</span><span>)</span><span> </span><span># for rlm. Watch out for dplyr::select and MASS::select clash.
</span><span>library</span><span>(</span><span>ggExtra</span><span>)</span><span>
</span><span>library</span><span>(</span><span>survey</span><span>)</span><span>
</span><span># download the latest year's data (caution - 71MB):
</span><span>dir.create</span><span>(</span><span>&quot;bls-cd&quot;</span><span>)</span><span>
</span><span>download.file</span><span>(</span><span>&quot;https://www.bls.gov/cex/pumd/data/stata/intrvw16.zip&quot;</span><span>,</span><span>
</span><span>destfile</span><span> </span><span>=</span><span> </span><span>&quot;bls-cd/intrvw16.zip&quot;</span><span>,</span><span> </span><span>mode</span><span> </span><span>=</span><span> </span><span>&quot;wb&quot;</span><span>)</span><span>
</span><span># download the data dictionary
</span><span>download.file</span><span>(</span><span>&quot;https://www.bls.gov/cex/pumd/ce_pumd_interview_diary_dictionary.xlsx&quot;</span><span>,</span><span>
</span><span>destfile</span><span> </span><span>=</span><span> </span><span>&quot;bls-cd/ce_pumd_interview_diary_dictionary.xlsx&quot;</span><span>,</span><span> </span><span>mode</span><span> </span><span>=</span><span> </span><span>&quot;wb&quot;</span><span>)</span><span>
</span><span>unzip</span><span>(</span><span>&quot;bls-cd/intrvw16.zip&quot;</span><span>,</span><span> </span><span>exdir</span><span> </span><span>=</span><span> </span><span>&quot;bls-cd&quot;</span><span>)</span><span>
</span><span># The FMLI files have characteristics, income, weights, and summary expenditure
# the numbers in file names refer to year and quarter. So intrvw16/fmli162.dta is # 2016, second quarter
</span><span>
</span><span># Import 2017 first quarter:
</span><span>fmli171</span><span> </span><span>&lt;-</span><span> </span><span>read_dta</span><span>(</span><span>&quot;bls-cd/intrvw16/fmli171.dta&quot;</span><span>)</span><span>
</span><span># looks like no attributes associated with the various columns; have to use the Excel data dictionary
</span><span>str</span><span>(</span><span>attributes</span><span>(</span><span>fmli171</span><span>))</span><span>
</span><span>attr</span><span>(</span><span>fmli171</span><span>,</span><span> </span><span>&quot;labels&quot;</span><span>)</span><span>
</span><span>attr</span><span>(</span><span>fmli171</span><span>,</span><span> </span><span>&quot;label&quot;</span><span>)</span><span>
</span><span># which columns are numeric, candidates to hold income and expenditure non-binned data:
</span><span>formats</span><span> </span><span>&lt;-</span><span> </span><span>sapply</span><span>(</span><span>fmli171</span><span>,</span><span> </span><span>function</span><span>(</span><span>x</span><span>){</span><span>attr</span><span>(</span><span>x</span><span>,</span><span> </span><span>&quot;format.stata&quot;</span><span>)})</span><span>
</span><span>formats</span><span>[</span><span>grepl</span><span>(</span><span>&quot;[0-9]g&quot;</span><span>,</span><span> </span><span>formats</span><span>)]</span><span>
</span><span># Bit of basic processing for convenience. Make a new data frame called d with some labels we need later,
# and the per person variables calculated in one place. # First, the code labels for income classes:
</span><span>inclasses</span><span> </span><span>&lt;-</span><span> </span><span>c</span><span>(</span><span>&quot;Less than $5,000&quot;</span><span>,</span><span> </span><span>&quot;$5,000 to $9,999&quot;</span><span>,</span><span> </span><span>&quot;$10,000 to $14,999&quot;</span><span>,</span><span> </span><span>&quot;$15,000 to $19,999&quot;</span><span>,</span><span>
</span><span>&quot;$20,000 to $29,999&quot;</span><span>,</span><span> </span><span>&quot;$30,000 to $39,999&quot;</span><span>,</span><span> </span><span>&quot;$40,000 to $49,999&quot;</span><span>,</span><span> </span><span>&quot;$50,000 to $69,999&quot;</span><span>,</span><span>
</span><span>&quot;$70,000 and over&quot;</span><span>)</span><span>
</span><span>inclass_lu</span><span> </span><span>&lt;-</span><span> </span><span>data_frame</span><span>(</span><span>
</span><span>inclass</span><span> </span><span>=</span><span> </span><span>paste0</span><span>(</span><span>&quot;0&quot;</span><span>,</span><span> </span><span>1</span><span>:</span><span>9</span><span>),</span><span>
</span><span>inclass_ch</span><span> </span><span>=</span><span> </span><span>ordered</span><span>(</span><span>inclasses</span><span>,</span><span> </span><span>levels</span><span> </span><span>=</span><span> </span><span>inclasses</span><span>)</span><span>
</span><span>)</span><span> </span><span># create the working version of the data frame:
</span><span>d</span><span> </span><span>&lt;-</span><span> </span><span>fmli171</span><span> </span><span>%>%</span><span>
</span><span>mutate</span><span>(</span><span>gas_pp</span><span> </span><span>=</span><span> </span><span>gasmocq</span><span> </span><span>/</span><span> </span><span>fam_size</span><span> </span><span>*</span><span> </span><span>4</span><span>,</span><span>
</span><span>inc_pp</span><span> </span><span>=</span><span> </span><span>fincbtxm</span><span> </span><span>/</span><span> </span><span>fam_size</span><span>,</span><span>
</span><span>gas_p_inc</span><span> </span><span>=</span><span> </span><span>gasmocq</span><span> </span><span>*</span><span> </span><span>4</span><span> </span><span>/</span><span> </span><span>fincbtxm</span><span>,</span><span>
</span><span>no_gas</span><span> </span><span>=</span><span> </span><span>as.integer</span><span>(</span><span>gas_pp</span><span> </span><span>==</span><span> </span><span>0</span><span>),</span><span>
</span><span>bls_urbn_ch</span><span> </span><span>=</span><span> </span><span>ifelse</span><span>(</span><span>bls_urbn</span><span> </span><span>==</span><span> </span><span>1</span><span>,</span><span> </span><span>&quot;Urban&quot;</span><span>,</span><span> </span><span>&quot;Rural&quot;</span><span>),</span><span>
</span><span>)</span><span> </span><span>%>%</span><span>
</span><span>left_join</span><span>(</span><span>inclass_lu</span><span>,</span><span> </span><span>by</span><span> </span><span>=</span><span> </span><span>&quot;inclass&quot;</span><span>)</span><span>
</span><span># parameter for how much to transform the dollar scales:
</span><span>lambda</span><span> </span><span>&lt;-</span><span> </span><span>0.2</span><span>
</span><span>ggplot</span><span>(</span><span>d</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>gas_pp</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>bls_urbn_ch</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_density</span><span>()</span><span> </span><span>+</span><span> </span><span>scale_x_continuous</span><span>(</span><span>label</span><span> </span><span>=</span><span> </span><span>dollar</span><span>,</span><span>
</span><span>trans</span><span> </span><span>=</span><span> </span><span>modulus_trans</span><span>(</span><span>lambda</span><span>),</span><span>
</span><span>breaks</span><span> </span><span>=</span><span> </span><span>modulus_breaks</span><span>(</span><span>lambda</span><span>))</span><span> </span><span>+</span><span> </span><span>geom_rug</span><span>()</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>&quot;Spend on petrol has a spike at $0 and a skewed distribution beyond that&quot;</span><span>,</span><span>
</span><span>&quot;Unweighted, 2017 quarter 1. Horizontal scale has been transformed.&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Source: USA Bureau of Labor Statistics Consumer Expenditure Survey&quot;</span><span>,</span><span>
</span><span>colour</span><span> </span><span>=</span><span> </span><span>&quot;&quot;</span><span>,</span><span>
</span><span>x</span><span> </span><span>=</span><span> </span><span>&quot;Expenditure per person on gasoline and motor oil this quarter x 4&quot;</span><span>)</span><span>
</span><span># some looks at various variables as described in the Excel data dictionary:
</span><span>summary</span><span>(</span><span>fmli171</span><span>$</span><span>cuincome</span><span>)</span><span> </span><span># total income; not present
</span><span>summary</span><span>(</span><span>fmli171</span><span>$</span><span>earnincx</span><span>)</span><span> </span><span># earnings before tax; not present
</span><span>table</span><span>(</span><span>fmli171</span><span>$</span><span>earncomp</span><span>)</span><span> </span><span># composition of earners
</span><span>table</span><span>(</span><span>fmli171</span><span>$</span><span>cutenure</span><span>)</span><span> </span><span># housing tenure (6 categories)
</span><span>table</span><span>(</span><span>fmli171</span><span>$</span><span>inclass</span><span>)</span><span> </span><span># income bracket
</span><span>summary</span><span>(</span><span>fmli171</span><span>$</span><span>inc_rank</span><span>)</span><span> </span><span># Weighted cumulative percent ranking based on total current income before taxes (for complete income reporters)
</span><span>summary</span><span>(</span><span>fmli171</span><span>$</span><span>othrincm</span><span>)</span><span> </span><span># other income
</span><span>summary</span><span>(</span><span>fmli171</span><span>$</span><span>ffrmincx</span><span>)</span><span> </span><span># farm income, not present
</span><span>summary</span><span>(</span><span>fmli171</span><span>$</span><span>fincbtax</span><span>)</span><span> </span><span># total amount of family income before taxes in the past 12 months
</span><span>summary</span><span>(</span><span>fmli171</span><span>$</span><span>finlwt21</span><span>)</span><span> </span><span># final calibrated weight
</span><span>
</span><span>ggplot</span><span>(</span><span>d</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>inc_pp</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>bls_urbn_ch</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_density</span><span>()</span><span> </span><span>+</span><span>
</span><span>geom_rug</span><span>()</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>&quot;After imputation, income has a skewed distribution with no spike at zero&quot;</span><span>,</span><span>
</span><span>&quot;Unweighted, 2017 quarter 1. Horizontal scale has been transformed.&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_x_continuous</span><span>(</span><span>label</span><span> </span><span>=</span><span> </span><span>dollar</span><span>,</span><span>
</span><span>trans</span><span> </span><span>=</span><span> </span><span>modulus_trans</span><span>(</span><span>lambda</span><span>),</span><span>
</span><span>breaks</span><span> </span><span>=</span><span> </span><span>modulus_breaks</span><span>(</span><span>lambda</span><span>))</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Source: USA Bureau of Labor Statistics Consumer Expenditure Survey&quot;</span><span>,</span><span>
</span><span>colour</span><span> </span><span>=</span><span> </span><span>&quot;&quot;</span><span>,</span><span>
</span><span>x</span><span> </span><span>=</span><span> </span><span>&quot;Family income per person before taxes in the past 12 months&quot;</span><span>)</span></code></pre>
</figure>
<h3>Relationship of income and fuel spend</h3>
<p>Here are some different ways of looking at the relationship between household income and the amount spent on fuel. They all show a lot of variation between individual households, but significant evidence of a material positive relationship between the two.</p>
<p>First, here’s a graph that tries to combine the binned “income classification” with the ranking of the household on income(ie its quantile if you like). The categories aren’t as neat as might be expected, I’m pretty sure because of these variables representing different states of imputation:</p>
<p><img width="100%" src="http://freerangestats.io/img/0124-quantile.svg"></p>
<p>The collection of people who don’t spend any money on petrol drags the regression line downwards, but it’s the slope that counts; definitely upwards. The higher ranked a household is on income, the more they spend per person on gasoline and motor oil.</p>
<p>BTW, note that the points in these plots are different sizes. The size is mapped to the calibrated survey weight indicating how many people in the US population each sample point is representing; this is a good starting point for trying to represented weighted data in a scatter plot.</p>
<p>I’m wary of using quantiles or rankings in this sort of analysis; I don’t see much or any gain over other transformations and new risks and interpretability problems are introduced. Perhaps more usefully, here are some straightforward scatterplots of income per person and vehicle fuel expenditure per person:</p>
<p><img width="100%" src="http://freerangestats.io/img/0124-scatter-1.svg"></p>
<p><img width="100%" src="http://freerangestats.io/img/0124-scatter-2.svg"></p>
<p>No doubt about that strong relationship; poorer households spend less on fuel (and nearly everything else, of course, although that’s not shown) than do richer households.</p>
<p>On the other hand, there’s equally no doubt that poorer households spend more on fuel as a proportion of their income:</p>
<p><img width="100%" src="http://freerangestats.io/img/0124-props.svg"></p>
<p>Here’s the code for those four graphics:</p>
<figure>
<pre><code data-lang="r"><span>#-----------income quantile v fuel scatter plot-------------------
</span><span>ggplot</span><span>(</span><span>d</span><span>,</span><span> </span><span>aes</span><span>(</span><span>y</span><span> </span><span>=</span><span> </span><span>gas_pp</span><span>,</span><span> </span><span>x</span><span> </span><span>=</span><span> </span><span>inc_rank</span><span>,</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>finlwt21</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>aes</span><span>(</span><span>colour</span><span> </span><span>=</span><span> </span><span>inclass_ch</span><span>),</span><span> </span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.2</span><span>)</span><span> </span><span>+</span><span> </span><span>geom_smooth</span><span>(</span><span>method</span><span> </span><span>=</span><span> </span><span>&quot;rlm&quot;</span><span>,</span><span> </span><span>aes</span><span>(</span><span>weight</span><span> </span><span>=</span><span> </span><span>finlwt21</span><span>))</span><span> </span><span>+</span><span>
</span><span>scale_y_continuous</span><span>(</span><span>label</span><span> </span><span>=</span><span> </span><span>dollar</span><span>,</span><span>
</span><span>trans</span><span> </span><span>=</span><span> </span><span>modulus_trans</span><span>(</span><span>lambda</span><span>),</span><span>
</span><span>breaks</span><span> </span><span>=</span><span> </span><span>modulus_breaks</span><span>(</span><span>lambda</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;Income quantile&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>&quot;Spend on petrol increases as income quantile of the household increases&quot;</span><span>,</span><span>
</span><span>&quot;Blue line shows robust regression using M estimator. Vertical axis is transformed.&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Source: USA Bureau of Labor Statistics Consumer Expenditure Survey&quot;</span><span>,</span><span>
</span><span>colour</span><span> </span><span>=</span><span> </span><span>str_wrap</span><span>(</span><span>&quot;Income class of household based on income before taxes&quot;</span><span>,</span><span> </span><span>20</span><span>),</span><span>
</span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Expenditure per person on gasoline and motor oil this quarter&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>legend.position</span><span> </span><span>=</span><span> </span><span>&quot;right&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>=</span><span> </span><span>4</span><span>,</span><span> </span><span>alpha</span><span> </span><span>=</span><span> </span><span>1</span><span>)))</span><span> </span><span>+</span><span>
</span><span>scale_size_area</span><span>(</span><span>guide</span><span> </span><span>=</span><span> </span><span>&quot;none&quot;</span><span>)</span><span>
</span><span>#-----------scatter plots----------------
</span><span>p</span><span> </span><span>&lt;-</span><span> </span><span>ggplot</span><span>(</span><span>d</span><span>,</span><span> </span><span>aes</span><span>(</span><span>x</span><span> </span><span>=</span><span> </span><span>inc_pp</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>gas_pp</span><span>,</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>finlwt21</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.3</span><span>)</span><span> </span><span>+</span><span>
</span><span>geom_smooth</span><span>(</span><span>method</span><span> </span><span>=</span><span> </span><span>&quot;rlm&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_x_continuous</span><span>(</span><span>&quot;Income per person in household in past 12 months&quot;</span><span>,</span><span>
</span><span>label</span><span> </span><span>=</span><span> </span><span>dollar</span><span>,</span><span>
</span><span>trans</span><span> </span><span>=</span><span> </span><span>modulus_trans</span><span>(</span><span>lambda</span><span>),</span><span>
</span><span>breaks</span><span> </span><span>=</span><span> </span><span>modulus_breaks</span><span>(</span><span>lambda</span><span>))</span><span> </span><span>+</span><span>
</span><span>scale_y_continuous</span><span>(</span><span>label</span><span> </span><span>=</span><span> </span><span>dollar</span><span>,</span><span>
</span><span>trans</span><span> </span><span>=</span><span> </span><span>modulus_trans</span><span>(</span><span>lambda</span><span>),</span><span>
</span><span>breaks</span><span> </span><span>=</span><span> </span><span>modulus_breaks</span><span>(</span><span>lambda</span><span>))</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>legend.position</span><span> </span><span>=</span><span> </span><span>&quot;none&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>&quot;Spend on petrol increases as income of the household increases&quot;</span><span>,</span><span>
</span><span>&quot;Blue line shows robust regression using M estimator. Both axes are transformed.&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Source: USA Bureau of Labor Statistics Consumer Expenditure Survey&quot;</span><span>,</span><span>
</span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Expenditure per person on gasoline and motor oil this quarter x 4&quot;</span><span>)</span><span> </span><span>ggMarginal</span><span>(</span><span>p</span><span>,</span><span> </span><span>type</span><span> </span><span>=</span><span> </span><span>&quot;density&quot;</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>&quot;grey&quot;</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>NA</span><span>)</span><span>
</span><span>ggMarginal</span><span>(</span><span>p</span><span> </span><span>%+%</span><span> </span><span>filter</span><span>(</span><span>d</span><span>,</span><span> </span><span>gas_pp</span><span> </span><span>></span><span> </span><span>0</span><span> </span><span>&amp;</span><span> </span><span>inc_pp</span><span> </span><span>></span><span> </span><span>0</span><span>),</span><span> </span><span>type</span><span> </span><span>=</span><span> </span><span>&quot;density&quot;</span><span>,</span><span> </span><span>fill</span><span> </span><span>=</span><span> </span><span>&quot;grey&quot;</span><span>,</span><span> </span><span>colour</span><span> </span><span>=</span><span> </span><span>NA</span><span>)</span><span>
</span><span>#-----------proportion spent on fuel-------------	</span><span>d</span><span> </span><span>%>%</span><span>
</span><span>filter</span><span>(</span><span>inc_pp</span><span> </span><span>></span><span> </span><span>1000</span><span>)</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>inc_pp</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>gas_p_inc</span><span>,</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>finlwt21</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_point</span><span>(</span><span>alpha</span><span> </span><span>=</span><span> </span><span>0.3</span><span>)</span><span> </span><span>+</span><span>
</span><span>scale_x_continuous</span><span>(</span><span>&quot;Income per person in household in past 12 months&quot;</span><span>,</span><span>
</span><span>label</span><span> </span><span>=</span><span> </span><span>dollar</span><span>,</span><span>
</span><span>trans</span><span> </span><span>=</span><span> </span><span>modulus_trans</span><span>(</span><span>lambda</span><span>),</span><span>
</span><span>breaks</span><span> </span><span>=</span><span> </span><span>modulus_breaks</span><span>(</span><span>lambda</span><span>))</span><span> </span><span>+</span><span>
</span><span>coord_cartesian</span><span>(</span><span>ylim</span><span> </span><span>=</span><span> </span><span>c</span><span>(</span><span>0</span><span>,</span><span> </span><span>1</span><span>))</span><span> </span><span>+</span><span>
</span><span>scale_y_continuous</span><span>()</span><span> </span><span>+</span><span>
</span><span>geom_smooth</span><span>(</span><span>se</span><span> </span><span>=</span><span> </span><span>FALSE</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>legend.position</span><span> </span><span>=</span><span> </span><span>&quot;none&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>&quot;Poorer households spend more on petrol proportionately than do richer households&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Source: USA Bureau of Labor Statistics Consumer Expenditure Survey&quot;</span><span>,</span><span>
</span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Expenditure per person on gasoline and motor oil\nas a proportion of income&quot;</span><span>)</span><span> </span></code></pre>
</figure>
<h3>Who is likely to spend nothing on petrol at all?</h3>
<p>Finally, I was interested in who spends nothing on petrol at all. This relates to Mr Warburton’s argument that the New Zealand Household Economic Survey if flawed for these purposes because the average spend on petrol includes people who have been priced out of vehicles altogether. In fact, with the US data, there is a very strong negative relationship between household income and the probability of spending zero on gasoline and motor oil.:</p>
<p><img width="100%" src="http://freerangestats.io/img/0124-no-gas.svg"><br>
<img width="100%" src="http://freerangestats.io/img/0124-no-gas2.svg"></p>
<p>However, as the previous scatterplots showed, removing either or both of the zero income and zero fuel spend cases from the US Consumer Expenditure survey doesn’t serve to remove the relationship between income and gasoline spend.</p>
<p>Finally, here’s the code for this last bit of analysis:</p>
<figure>
<pre><code data-lang="r"><span>p</span><span>1</span><span> </span><span>&lt;-</span><span> </span><span>d</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>inc_pp</span><span>,</span><span> </span><span>y</span><span> </span><span>=</span><span> </span><span>no_gas</span><span>,</span><span> </span><span>size</span><span> </span><span>=</span><span> </span><span>finlwt21</span><span>))</span><span> </span><span>+</span><span>
</span><span>geom_point</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_smooth</span><span>(</span><span>method</span><span> </span><span>=</span><span> </span><span>&quot;glm&quot;</span><span>,</span><span> </span><span>method.args</span><span> </span><span>=</span><span> </span><span>list</span><span>(</span><span>family</span><span> </span><span>=</span><span> </span><span>&quot;binomial&quot;</span><span>))</span><span> </span><span>+</span><span>
</span><span>scale_x_continuous</span><span>(</span><span>&quot;Income per person in household in past 12 months&quot;</span><span>,</span><span>
</span><span>label</span><span> </span><span>=</span><span> </span><span>dollar</span><span>,</span><span>
</span><span>trans</span><span> </span><span>=</span><span> </span><span>modulus_trans</span><span>(</span><span>lambda</span><span>),</span><span>
</span><span>breaks</span><span> </span><span>=</span><span> </span><span>modulus_breaks</span><span>(</span><span>lambda</span><span>))</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>y</span><span> </span><span>=</span><span> </span><span>&quot;Probability of spending $0 on gasoline and motor oil this quarter\n&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>theme</span><span>(</span><span>legend.position</span><span> </span><span>=</span><span> </span><span>&quot;none&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>labs</span><span>(</span><span>caption</span><span> </span><span>=</span><span> </span><span>&quot;Source: USA Bureau of Labor Statistics Consumer Expenditure Survey 2017 Q1&quot;</span><span>)</span><span> </span><span>+</span><span>
</span><span>ggtitle</span><span>(</span><span>&quot;Poorer households are more likely to spend nothing on petrol at all&quot;</span><span>,</span><span>
</span><span>&quot;Blue line shows logistic regression; points show American households&quot;</span><span>)</span><span>
</span><span>print</span><span>(</span><span>p</span><span>1</span><span>)</span><span>
</span><span>p</span><span>2</span><span> </span><span>&lt;-</span><span> </span><span>p</span><span>1</span><span> </span><span>%+%</span><span> </span><span>filter</span><span>(</span><span>d</span><span>,</span><span> </span><span>inc_pp</span><span> </span><span>></span><span> </span><span>0</span><span>)</span><span> </span><span>+</span><span> </span><span>ggtitle</span><span>(</span><span>&quot;&quot;</span><span>,</span><span> </span><span>&quot;Effect holds even if restricted to households with positive income&quot;</span><span>)</span><span>
</span><span>print</span><span>(</span><span>p</span><span>2</span><span>)</span><span>
</span><span># Check out the relationship with slightly more formal modelling than just on the fly in the graphic.
# crude approximation of the survey design, that takes just the primary sampling units and weights
# into account but ignores the stratification and post-stratification calibration (this will be
# conservative for inference so that's ok). # Also, better would be to transform `inc_pp`, or use a gam, or something. This will do for now!
</span><span>dd</span><span> </span><span>&lt;-</span><span> </span><span>svydesign</span><span>(</span><span>~</span><span>psu</span><span>,</span><span> </span><span>data</span><span> </span><span>=</span><span> </span><span>d</span><span>,</span><span> </span><span>weights</span><span> </span><span>=</span><span> </span><span>~</span><span>finlwt21</span><span>)</span><span>
</span><span>mod</span><span> </span><span>&lt;-</span><span> </span><span>svyglm</span><span>(</span><span>no_gas</span><span> </span><span>~</span><span> </span><span>inc_pp</span><span>,</span><span> </span><span>design</span><span> </span><span>=</span><span> </span><span>dd</span><span>,</span><span> </span><span>family</span><span> </span><span>=</span><span> </span><span>&quot;quasibinomial&quot;</span><span>)</span><span>
</span><span>summary</span><span>(</span><span>mod</span><span>)</span></code></pre>
</figure>
<p>Just as I was finalising this post, <a rel="nofollow" href="https://twitter.com/Thoughtfulnz/status/1013288397392117760" target="_blank">new discussion started</a> suggesting the American Time Use Survey as a good source of microdata to directly analyse the question of whether poorer households travel more or less. Looks a good topic to come back to at some point.</p>
	<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/07/01/petrol-spend"> 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/DS9vX1BlKec" height="1"></a></div>