<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/dont-buy-a-brand-new-porsche-911-or-audi-q7/"></div></div><div><a data-url="https://www.r-bloggers.com/dont-buy-a-brand-new-porsche-911-or-audi-q7/" data-counturl="https://www.r-bloggers.com/dont-buy-a-brand-new-porsche-911-or-audi-q7/" data-count="horizontal" data-text="Don’t buy a brand new Porsche 911 or Audi Q7!!" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://longhowlam.wordpress.com/2016/10/19/dont-buy-a-brand-new-porsche-911-or-audi-q7/"> R – Longhow Lam's Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><img alt="wp1" class="wp-image-2037" src="https://i0.wp.com/longhowlam.files.wordpress.com/2016/10/wp1.jpg?w=456&ssl=1" data-recalc-dims="1"></p>
<h2>Introduction</h2>
<p>Many people know that <strong>nasty feeling</strong> when buying a brand new car. The minute that you have left the dealer, your car has lost a substantial amount of value. Unfortunately this depreciation is inevitable, however, the amount depends heavily on the car make and model. A small analysis of data from (used) cars shows these differences.</p>
<h2>Car Data</h2>
<p>I have used Rvest to scrape data from <a target="_blank" rel="nofollow" href="http://www.gaspedaal.nl/">www.gaspedaal.nl</a>, a Dutch website that combines car for sales data from several other sites. The script to get the data is not that difficult, it can be found on my <a target="_blank" rel="nofollow" href="http://github.com/longhowlam/cardepreciation">GitHub</a>, together with my analysis script. There are around <strong>435,000 </strong>cars. The data for each car consists of: make, model, price, fuel type, transmission and age. There are many different car makes and models, the most occurring cars in my data set are:</p>
<div><img src="https://i2.wp.com/media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAjIAAAAJGJmNzJmZjAwLTBmODgtNDk1OC1hODk3LTczZjEyY2VjMjg4YQ.jpg?w=456&ssl=1" data-recalc-dims="1"></div>
<p> </p>
<h3><strong>Car age vs. Kilometers</strong></h3>
<p>Obviously, there is a clear relation between the age of a car and the amount of kilometers driven. An interesting pattern to see is that this relation depends on on the car make (and model). The following figure shows a few car brands.</p>
<div><img src="https://i1.wp.com/media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAlfAAAAJDhmZTM3YTdlLTNlZGMtNDA5NS05ZWJiLTYzYjMzOGFmZmExMg.jpg?w=456&ssl=1" data-recalc-dims="1"></div>
<p>Large differences in amount of driving between car types start after 18 months. On average, <strong>Jaguars </strong>are not made for driving, after 60 months only around <strong>83.000 KM</strong> are driven by its owners. While on the other hand, <strong>Mercedes-Benz </strong>owners have driven around <strong>120.000 KM</strong> after 60 months.</p>
<p>A more extreme difference is between the Volvo V50 and the Hyundai i10. Between six and ten years, a Volvo V50 has driven on average 178K kilometers while a Hyundai i10 has driven only 75K kilometers.</p>
<div><img src="https://i2.wp.com/media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAebAAAAJDkzOWUyOTMzLTM5ZTQtNDhiMi05MWRjLTAxY2QzYjNjNjBhYg.jpg?w=456&ssl=1" data-recalc-dims="1"></div>
<h2>Depreciation</h2>
<p>A simple depreciation model is just linear depreciation. Per car brand, model, and transmission type, I can fit a straight line through price and kilometers driven. The slope of the line is the depreciation for every kilometer driven. An elegant way to obtain the depreciation per car type is by using the <a target="_blank" rel="nofollow" href="http://cran.r-project.org/web/packages/purrr/index.html"><strong>purrr </strong></a>and <strong><a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/broom/index.html">broom </a></strong>packages.</p>
<p> </p>
<div><img src="https://i2.wp.com/media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAc1AAAAJDFmNWQ1NDM4LWI0MWMtNDRmYy05NDNhLTlkMzExZTQxODkxMg.jpg?w=456&ssl=1" data-recalc-dims="1"></div>
<p> </p>
<p>First, some outlying values are removed then only car types with <em>enough </em>data points are considered. Then I have grouped the data by brand, model and transmission type, so that for each group a simple linear regression model can be fitted:</p>
<p>Price = <em>Intercept</em> + <em>depreciation</em> * KM</p>
<p>The following table shows the results:</p>
<div><img src="https://i1.wp.com/media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAf8AAAAJGZjNDBhYTI4LTFkZTMtNGU0Yi05MDkzLTEyZDVkYjA5ZjJmZQ.jpg?w=456&ssl=1" data-recalc-dims="1"></div>
<p> </p>
<p>So, on average a new Porsche 911 costs <strong>117,278.60 Euro</strong>, and every kilometer you drive will cost you around <strong>49.75 cents</strong> in loss of value. The complete table with all car types can be found on <a target="_blank" rel="nofollow" href="http://rpubs.com/longhowlam/cardepreciation">RPubs</a>. Although, simple and easy to interpret parameters, a straight line model is not a realistic model as can be seen in the following figure:</p>
<div><img src="https://i2.wp.com/media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAh1AAAAJGMxMjJmMGMxLTg1NjgtNGNlZi1iNWIzLWNjZTRmYTczNDhkNQ.jpg?w=456&ssl=1" data-recalc-dims="1"></div>
<p> </p>
<p>A better model to fit would be a non linear depreciation model. For example, exponential depreciation or if you don’t want to specify a specific function, some kind of <strong><a target="_blank" rel="nofollow" href="http://en.wikipedia.org/wiki/Smoothing_spline">smoothing spline</a>. </strong>The R code only needs to be modified slightly, to code below fits a natural cubic splines per car type.</p>
<div><img src="https://i2.wp.com/media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAi9AAAAJDQzMjk3ZWY0LTBiMTMtNGMwYS05NzE3LWZhMTgzZTBiMTg4MA.jpg?w=456&ssl=1" data-recalc-dims="1"></div>
<p> </p>
<p>It is a better model (in terms of R-squared), it follows the non linear depreciation that we can see in the data. However, we do not have a single deprecation value. How much value a certain car will lose when driving 1 kilometer now depends on the amount of kilometers driven. It is the derivative of the fitted spline curve. For example, the spline curves fitted for a Renault Clio are given in the figure below. A Clio with automatic transmission hardly looses any value after 100,000 KM.</p>
<div><img src="https://i2.wp.com/media.licdn.com/mpr/mpr/AAEAAQAAAAAAAAjdAAAAJGVlZmNkNWYwLWExM2MtNDk5Zi04MGE2LWI5ZWM2YWFlMDNkNA.jpg?w=456&ssl=1" data-recalc-dims="1"></div>
<p> </p>
<p>I have created <a target="_blank" rel="nofollow" href="http://www.longhowlam.nl:3838/sample-apps/AutoPrijsApp/">a small shiny app</a> so that you can see the curves of all the car types.</p>
<h2>Conclusion</h2>
<p>Despite my data science exercise and beautiful natural cubic smoothing splines models, buying a brand new car involves a lot of <strong>emotion</strong>. My wife wants a blue Citroen C4 Picasso, no matter what cubic spline model and R-squared I show to her!</p>
<p>So just ignore my analysis and <strong>buy the car that feels good to you!!</strong> Cheers, Longhow.</p>
<p> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/longhowlam.wordpress.com/2035/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/longhowlam.wordpress.com/2035/" border="0"></a> <img alt="" src="https://i1.wp.com/pixel.wp.com/b.gif?resize=1%2C1&ssl=1" border="0" data-recalc-dims="1"></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/dont-buy-a-brand-new-porsche-911-or-audi-q7/"></div></div><div><a data-url="https://www.r-bloggers.com/dont-buy-a-brand-new-porsche-911-or-audi-q7/" data-counturl="https://www.r-bloggers.com/dont-buy-a-brand-new-porsche-911-or-audi-q7/" data-count="vertical" data-text="Don’t buy a brand new Porsche 911 or Audi Q7!!" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://longhowlam.wordpress.com/2016/10/19/dont-buy-a-brand-new-porsche-911-or-audi-q7/"> R – Longhow Lam's Blog</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/aZK1D3Ug6a8"></a></div>