{"id":829,"date":"2015-08-10T15:31:11","date_gmt":"2015-08-10T14:31:11","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=829"},"modified":"2025-07-04T21:18:17","modified_gmt":"2025-07-04T20:18:17","slug":"interpolation","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/interpolation\/","title":{"rendered":"Interpolation"},"content":{"rendered":"\n<p><a href=\"https:\/\/pcool.dyndns.org\/index.php\/regression-coefficient\/\" data-type=\"page\" data-id=\"826\">As described<\/a>, a regression line was fitted through 30 data points in the <a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/trees30.rda\" target=\"_blank\" rel=\"noreferrer noopener\">trees30.rda<\/a> data set.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/trees30regression-1024x768.png\" alt=\"\" class=\"wp-image-3853\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/trees30regression-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/trees30regression-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/trees30regression-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/trees30regression.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The formula of the line is found by:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>fit&lt;-lm(Mass~Girth,data=TreeGirthMass)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>fit<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Call:<\/em><\/span>\n<span style=\"color: #0000ff;\"> <em>lm(formula = Mass ~ Girth, data = TreeGirthMass)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Coefficients:<\/em><\/span>\n<span style=\"color: #0000ff;\"> <em>(Intercept)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Girth \u00a0<\/em><\/span>\n<span style=\"color: #0000ff;\"> <em>\u00a0\u00a0\u00a0 -411.62\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3.24\u00a0<\/em><\/span><\/code><\/pre>\n\n\n\n<p>Therefore the equation of the regression line is:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(Mass = 3.24 \\cdot Girth -411.62 \\)<script src=\"https:\/\/pcool.dyndns.org\/wp-includes\/js\/dist\/hooks.min.js?ver=dd5603f07f9220ed27f1\" id=\"wp-hooks-js\"><\/script>\n<script src=\"https:\/\/pcool.dyndns.org\/wp-includes\/js\/dist\/i18n.min.js?ver=c26c3dc7bed366793375\" id=\"wp-i18n-js\"><\/script>\n<script id=\"wp-i18n-js-after\">\nwp.i18n.setLocaleData( { 'text direction\\u0004ltr': [ 'ltr' ] } );\n\/\/# sourceURL=wp-i18n-js-after\n<\/script>\n<script  async src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/mathjax\/2.7.7\/MathJax.js?config=TeX-MML-AM_CHTML\" id=\"mathjax-js\"><\/script>\n<\/div>\n\n\n\n<p>This is the equation of the line showing the relation between girth and mass of a tree. In the example, the tree had to be chopped down to measure its mass. It would be nice to estimate the mass of a tree by only measuring its girth (without chopping it down; so the profit margin could be estimated). From the equation we can estimate the mass of a tree with a girth of 280 centimetres:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(Mass = 3.24 \\cdot 280 &#8211; 411.62 = 495.58 kg \\)<\/div>\n\n\n\n<p>The estimation we made is <strong><em>within the range we have measured<\/em><\/strong>. This process is called <strong>interpolation<\/strong>. Of course, it is also possible to let R do this directly using the predict function. The predict function takes the model (fit) as first argument and a data frame with the value(s) of the Girth:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>predict(fit, data.frame(Girth = 280))<\/em><\/span>\n<span style=\"color: #0000ff;\"><em> 1 <\/em><\/span>\n<span style=\"color: #0000ff;\"><em>495.7158<\/em><\/span><\/code><\/pre>\n\n\n\n<p class=\"is-style-text-annotation is-style-text-annotation--1\">The difference with the manual method above is due to rounding error.<\/p>\n\n\n\n<p>Similarly, we can estimate the mass of a tree <strong><em>outside the range we have measured<\/em><\/strong>. This process is called <strong>extrapolation<\/strong>. For example, to estimate the mass of a tree with a girth of 500 cm:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(Mass = 3.24 \\cdot 500 &#8211; 411.62 = 1208.38 kg \\)<\/div>\n\n\n\n<p>Or in R:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>predict(fit, data.frame(Girth = 500))<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>1 <\/em><\/span>\n<span style=\"color: #0000ff;\"><em>1208.622 <\/em><\/span><\/code><\/pre>\n\n\n\n<p>Obviously, one has to be far <a href=\"https:\/\/pcool.dyndns.org\/index.php\/other-models\/\" data-type=\"page\" data-id=\"832\">more cautious with estimations found by means of extrapolation<\/a> than with interpolation.<\/p>\n\n\n\n<p>It is also possible to predict a range of value in R:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f40606\" class=\"has-inline-color\">predict(fit, data.frame(Girth = c(280, 500)))\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#3c05f5\" class=\"has-inline-color\">        1         2 \n 495.7158 1208.6223 <\/mark><\/em><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As described, a regression line was fitted through 30 data points in the trees30.rda data set. The formula of the line is found by: Therefore the equation of the regression line is: This is the equation of the line showing the relation between girth and mass of a tree. In the example, the tree had [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-829","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/comments?post=829"}],"version-history":[{"count":1,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/829\/revisions"}],"predecessor-version":[{"id":4924,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/829\/revisions\/4924"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}