{"id":832,"date":"2015-08-10T15:31:59","date_gmt":"2015-08-10T14:31:59","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=832"},"modified":"2025-07-04T21:55:31","modified_gmt":"2025-07-04T20:55:31","slug":"other-models","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/other-models\/","title":{"rendered":"Other Models"},"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. Data were also <a href=\"https:\/\/pcool.dyndns.org\/index.php\/interpolation\/\" data-type=\"page\" data-id=\"829\">extrapolated<\/a> and it was estimated that a tree with a diameter of 500 centimetres would have a mass of 1208 kilogram. However, one should be more cautious when extrapolating data as is illustrated below. The data set has been extended and the data of 104 trees can be found in <a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/trees.rda\" target=\"_blank\" rel=\"noreferrer noopener\">trees.rda<\/a>. The data is shown by:<\/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:#f40707\" class=\"has-inline-color\">ExtendedTreeGirthMass \n<\/mark><\/em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#2406f4\" class=\"has-inline-color\"><em>    Girth Mass\n1     205  251\n2     213  272\n.....<\/em>\n.....<em>\n103   522 2508\n104   527 2375<\/em><\/mark><\/code><\/pre>\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=ExtendedTreeGirthMass)<\/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 = ExtendedTreeGirthMass)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Coefficients:<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>(Intercept)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Girth &nbsp;<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp; -1225.413&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5.874&nbsp;<\/em><\/span><\/code><\/pre>\n\n\n\n<p>The equation of the line therefore is:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(Mass = 5.874 \\cdot Girth &#8211; 1225.413 \\)<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 class=\"is-style-text-annotation is-style-text-annotation--1\">Please note the equation of this line is <a href=\"https:\/\/pcool.dyndns.org\/index.php\/regression-coefficient\/\" data-type=\"page\" data-id=\"826\">different<\/a> from the one found when there were only 30 trees in the data set (Mass = 3.24\u00d7Girth -411.62).<\/p>\n\n\n\n<p>The correlation coefficient is found by:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">cor(ExtendedTreeGirthMass$Mass,ExtendedTreeGirthMass$Girth,method='pearson')<\/span><\/em>\n<span style=\"color: #0000ff;\">&#91;1] 0.916265<\/span><\/code><\/pre>\n\n\n\n<p>A correlation coefficient of 92% does appear very satisfactory. However, if we plot the data, the fit is perhaps somewhat disappointing:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>ggplot(<span style=\"color: #ff0000;\"><em>data=ExtendedTreeGirthMass,aes(x = Girth,y = Mass)<\/em><\/span>) + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_point() + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>ggtitle(label = \"Girth and Mass Trees\") + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>xlab(label = \"Girth &#91;cm]\") + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>ylab(label = \"Mass &#91;kg]\") + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_smooth(method = 'lm') + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>theme_bw() <\/em><\/span><\/code><\/pre>\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\/treesregression-1024x768.png\" alt=\"\" class=\"wp-image-3854\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treesregression-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treesregression-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treesregression-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treesregression.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Looking at the plot, it seems an exponential relation seems more appropriate. This would also fit our understanding of growth better. This is another example why it is always advisable to <a href=\"https:\/\/pcool.dyndns.org\/index.php\/scatterplot\/\" data-type=\"page\" data-id=\"541\">plot the data<\/a> and not only rely on descriptive values.<\/p>\n\n\n\n<p>To fit an exponential regression line to the data, use the equation:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(y = b \\cdot e^{a \\cdot {x}} \\)<\/div>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(Mass = b \\cdot e^{a \\cdot{Girth}} \\)<\/div>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\( log(Mass) = log(b \\cdot e^{a \\cdot {Girth}}) \\)<\/div>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(log(Mass) = log(b) + a \\cdot {Girth} \\)<\/div>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(log (Mass) = c + a \\cdot {Girth} \\)<\/div>\n\n\n\n<p>There are two ways to perform exponential curve fitting:<\/p>\n\n\n\n<p><strong>1 Transform the y axis to logarithmic scale:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>ggplot(<span style=\"color: #ff0000;\"><em>data=ExtendedTreeGirthMass, aes(x = Girth,y = Mass)<\/em><\/span>) + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_point() + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>ggtitle(label = \"Girth and Mass Trees\") + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>xlab(label = \"Girth &#91;cm]\") +<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>ylab(label = \"Mass &#91;kg]\") +<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_smooth(method = '<strong>loess<\/strong>') <strong>+<\/strong><\/em><\/span>\n<em style=\"color: rgb(255, 0, 0); font-weight: bold;\">coord_trans(y = <\/em>\"<em style=\"color: rgb(255, 0, 0); font-weight: bold;\">log10<\/em>\"<span style=\"color: #ff0000;\"><strong><em>)<\/em><\/strong><\/span> <span style=\"color: #ff0000;\"><em>+<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>theme_bw()<\/em><\/span><\/code><\/pre>\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\/treeregressionlogscale-1024x768.png\" alt=\"\" class=\"wp-image-3850\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treeregressionlogscale-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treeregressionlogscale-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treeregressionlogscale-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treeregressionlogscale.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The advantage of this method is that it is very straight forward and that the original values on the axes are maintained. However, it is difficult to obtain the equation of the logarithmic regression analysis and perform inter- or extrapolation. Furthermore, the linear model gives data out of range and therefore a loess (smooth) model is required (resulting in a line that is not straight).<\/p>\n\n\n\n<p class=\"is-style-text-annotation is-style-text-annotation--2\">Please note to use <strong>loess<\/strong> and not lm (linear model) as method!<\/p>\n\n\n\n<p><strong>2 Log tranformation:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>ggplot(<span style=\"color: #ff0000;\"><em>data=ExtendedTreeGirthMass, aes(x = Girth,y = log(Mass))<\/em><\/span>) + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_point() + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>ggtitle(label = \"Girth and Mass Trees\") +<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>xlab(label = \"Girth &#91;cm]\") +<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>ylab(label = \"log(Mass &#91;kg])\") +<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_smooth(method = 'lm') +<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>theme_bw()<\/em><\/span><\/code><\/pre>\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\/treeregressionlogtransform-1024x768.png\" alt=\"\" class=\"wp-image-3851\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treeregressionlogtransform-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treeregressionlogtransform-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treeregressionlogtransform-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/treeregressionlogtransform.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The original (untransformed) values are indicated on the x-axis, but transformed values on the y axis, making interpretation perhaps more difficult.<\/p>\n\n\n\n<p><strong>To find the equation of the logarithmic regression line:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>fit &lt;- lm(log(Mass)~Girth,data=ExtendedTreeGirthMass)<\/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 = log(Mass) ~ Girth, data = ExtendedTreeGirthMass)<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>Coefficients:<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>(Intercept)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Girth &nbsp;<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp;&nbsp; 4.33456&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.00649&nbsp;<\/em> <\/span><\/code><\/pre>\n\n\n\n<p>The formula of the logarithmic regression line therefore is:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(Log(Mass) = 0.00649 \\cdot Girth + 4.33456 \\)<\/div>\n\n\n\n<p><strong>Extrapolation with linear and log model<\/strong><\/p>\n\n\n\n<p>Using the linear model, a tree with a girth of 500 centimetres would have a mass of:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(Mass=5.874 \\cdot 500-1225.413 \\approx 1712 kg \\)<\/div>\n\n\n\n<p>However, using the log model:<\/p>\n\n\n\n<div class=\"wp-block-mathml-mathmlblock\">\\(Log(Mass)=0.00649 \\cdot 500 + 4.33456 =7.57956 \\)<\/div>\n\n\n\n<p><strong>Mass \u2248 1958 kg<\/strong><\/p>\n\n\n\n<p>The prediction with the logarithmic model fits the data much better.<\/p>\n\n\n\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As described, a regression line was fitted through 30 data points in the trees30.rda data set. Data were also extrapolated and it was estimated that a tree with a diameter of 500 centimetres would have a mass of 1208 kilogram. However, one should be more cautious when extrapolating data as is illustrated below. The data [&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-832","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/832","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=832"}],"version-history":[{"count":4,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/832\/revisions"}],"predecessor-version":[{"id":4929,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/832\/revisions\/4929"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}