{"id":1194,"date":"2015-08-27T10:36:47","date_gmt":"2015-08-27T09:36:47","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=1194"},"modified":"2025-06-24T23:02:12","modified_gmt":"2025-06-24T22:02:12","slug":"answers-curve-fitting","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/answers-curve-fitting\/","title":{"rendered":"Answers Curve Fitting"},"content":{"rendered":"\n<p>&nbsp;<\/p>\n\n\n\n<p>The data is also provided in <a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/Q8-1.rda\" target=\"_blank\" rel=\"noreferrer noopener\">Q8-1.rda <\/a>(the data frame is called Q8). To call the data in the console:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>Q8<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp; x&nbsp;&nbsp;&nbsp; y<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>1 3 1.20<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>2 4 1.40<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>3 5 1.60<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>4 6 1.75<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>5 7 1.85<\/em><\/span><\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Plot the data, draw the regression line and estimate the equation of the line:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">ggplot() + <\/span><\/em>\n<em><span style=\"color: #ff0000;\">geom_point(aes(x = x,y = y), data=Q8) + <\/span><\/em>\n<em><span style=\"color: #ff0000;\">geom_smooth(aes(x = x,y = y),data=Q8,method = 'lm') + <\/span><\/em>\n<em><span style=\"color: #ff0000;\">theme_bw()<\/span><\/em><\/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\/Q8-1-1024x768.png\" alt=\"\" class=\"wp-image-3487\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-1-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-1-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-1-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-1.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Fit the regression line:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>fit&lt;-lm(y~x,data=Q8)<\/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 = y ~ x, data = Q8)<\/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;&nbsp;&nbsp;&nbsp;&nbsp; x &nbsp;<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.735&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.165&nbsp;<\/em> <\/span><\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The equation of the regression line therefore is:<\/p>\n\n\n\n<p><strong>y = 0.735 + 0.165 \u00d7 x<\/strong><\/p>\n\n\n\n<p>2. What is the correlation coefficient?<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>cor(Q8$x,Q8$y,method='pearson')<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#91;1] 0.9913889<\/em><\/span><\/code><\/pre>\n\n\n\n<p>The correlation coefficient therefore is 99%.<\/p>\n\n\n\n<p>3. Interpolate the y-value for x = 5.5<\/p>\n\n\n\n<p>y(x = 5.5) = 0.735 + 0.165 \u00d7<strong> 5.5<\/strong> = <strong>1.6425<\/strong><\/p>\n\n\n\n<p>4. Extrapolate the y-values for x = 0.1 and x = 15<\/p>\n\n\n\n<p>y(x = 0.1) = 0.735 + 0.165 \u00d7<strong> 0.1<\/strong> = <strong>0.7515<\/strong><\/p>\n\n\n\n<p>y(x = 15) = 0.735 + 0.165 \u00d7<strong> 15<\/strong> = <strong>3.21<\/strong><\/p>\n\n\n\n<p>The data is also provided in <a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/Q8-2.rda\" target=\"_blank\" rel=\"noreferrer noopener\">Q8-2.rda <\/a>(the data frame is called Q8Extended). To call the data in the console:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>Q8Extended<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x&nbsp;&nbsp;&nbsp;&nbsp; y<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>1&nbsp;&nbsp; 0.1 -1.25<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>2&nbsp;&nbsp; 0.2 -0.70<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>3&nbsp;&nbsp; 1.0&nbsp; 0.40<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>4&nbsp;&nbsp; 2.0&nbsp; 0.90<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>5&nbsp;&nbsp; 3.0&nbsp; 1.20<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>6&nbsp;&nbsp; 4.0&nbsp; 1.40<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>7&nbsp;&nbsp; 5.0&nbsp; 1.60<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>8&nbsp;&nbsp; 6.0&nbsp; 1.75<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>9&nbsp;&nbsp; 7.0&nbsp; 1.85<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>10&nbsp; 8.0&nbsp; 1.95<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>11&nbsp; 9.0&nbsp; 2.05<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>12 10.0&nbsp; 2.10<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>13 12.0&nbsp; 2.25<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>14 14.0&nbsp; 2.35<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>15 15.0&nbsp; 2.40&nbsp;<\/em><\/span><\/code><\/pre>\n\n\n\n<p>5. Plot these data in a graph.<\/p>\n\n\n\n<p>To create a <a href=\"https:\/\/pcool.dyndns.org\/index.php\/scatterplot\/\" data-type=\"page\" data-id=\"541\">scatterplot<\/a> to evaluate the relation between the two variables (without a regression line):<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>ggplot() + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_point(aes(x = x,y = y),data=Q8Extended) + <\/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\/Q8-2-1024x768.png\" alt=\"\" class=\"wp-image-3488\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-2-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-2-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-2-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-2.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>6. What is the relation between x and y and what is the value of the correlation coefficient?<\/p>\n\n\n\n<p>A linear regression is clearly hopeless:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>ggplot() + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_point(aes(x = x,y = y),data=Q8Extended) + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_smooth(aes(x = x,y = y),data=Q8Extended,method = 'lm') + 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\/Q8-3-1024x768.png\" alt=\"\" class=\"wp-image-3489\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-3-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-3-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-3-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-3.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>x and y appear to have a logarithmic relation and the general equation of the regression line is:<\/p>\n\n\n\n<p>y = b + a \u00d7 log(x)<\/p>\n\n\n\n<p>or:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">ggplot() + <\/span><\/em>\n<em><span style=\"color: #ff0000;\">geom_point(aes(x = <strong>log<\/strong>(x),y = y),data=Q8Extended) + <\/span><\/em>\n<em><span style=\"color: #ff0000;\">geom_smooth(aes(x = <strong>log<\/strong>(x),y = y),data=Q8Extended,method = 'lm') + theme_bw()<\/span><\/em><\/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\/Q8-4-1024x768.png\" alt=\"\" class=\"wp-image-3490\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-4-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-4-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-4-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/Q8-4.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The equation of the regression line is:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>fit&lt;-lm(y~log(x),data=Q8Extended)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>fit<\/em><\/span>\n<em><span style=\"color: #0000ff;\">Call:<\/span><\/em>\n<em><span style=\"color: #0000ff;\">lm(formula = y ~ log(x), data = Q8Extended)<\/span><\/em>\n<em><span style=\"color: #0000ff;\">\nCoefficients:\n(Intercept)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; log(x)\n0.4271&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.7276&nbsp; <\/span> <\/em><\/code><\/pre>\n\n\n\n<p>Or:<\/p>\n\n\n\n<p><strong>y = 0.4271 + 0.7276 \u00d7 log(x)<\/strong><\/p>\n\n\n\n<p class=\"is-style-default\">Alternatively, you could plot the data on a logarithmic x axis:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f10303\" class=\"has-inline-color\"><em>ggplot(data=Q8Extended, aes(x=x, y=y)) + <\/em>\n<em>geom_point() + <\/em>\n<em>coord_trans(x = \"log10\") + <\/em>\n<em>theme_bw()<\/em><\/mark><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/log_scale-1024x1024.jpeg\" alt=\"\" class=\"wp-image-4383\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/log_scale-1024x1024.jpeg 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/log_scale-300x300.jpeg 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/log_scale-150x150.jpeg 150w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/log_scale-768x768.jpeg 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/log_scale-1536x1536.jpeg 1536w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/log_scale-2048x2048.jpeg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>To find the value of the correlation coefficient:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>cor(log(Q8Extended$x),Q8Extended$y,method='pearson')<\/em><\/span>\n<em><span style=\"color: #0000ff;\">&#91;1] 0.9997933<\/span><\/em><\/code><\/pre>\n\n\n\n<p>7. What are the y-values for x = 0.1 and x = 15?<\/p>\n\n\n\n<p>As described under 6, the equation of the regression line is:<\/p>\n\n\n\n<p>y = 0.4271 + 0.7276 \u00d7 log(x)<\/p>\n\n\n\n<p>Therefore,<\/p>\n\n\n\n<p>y(x = 0.1) =&nbsp;0.4271 + 0.7276 \u00d7 <strong>log(0.1)<\/strong> \u2248 <strong>-1.25<\/strong><\/p>\n\n\n\n<p>y(x = 15) =&nbsp;0.4271 + 0.7276 \u00d7 <strong>log(15)<\/strong> \u2248 <strong>2.40<\/strong><\/p>\n\n\n\n<p>This question illustrates again the danger of extrapolating data!<\/p>\n\n\n\n<p>8. The scatterplot and line x=y can be created with the following command in the R console:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>ggplot() + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_point(aes(x = Lafayette,y = iPhone),data=goniometer) + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>theme_bw() + <\/em><\/span>\n<span style=\"color: #ff0000;\"><em>geom_abline(data=goniometer, intercept = 0.0,slope = 1.0,<\/em><\/span>\n  <span style=\"color: #ff0000;\"><em>colour = '#339900', linetype = 2)<\/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\/iccquestion-1024x768.png\" alt=\"\" class=\"wp-image-3220\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/iccquestion-1024x768.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/iccquestion-300x225.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/iccquestion-768x576.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/iccquestion.png 1355w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>9. To calculate the Pearson correlation coefficient:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>cor(goniometer$Lafayette,goniometer$iPhone,method=\"pearson\")<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#91;1] 0.9473263<\/em><\/span><\/code><\/pre>\n\n\n\n<p>Therefore, Pearson&#8217;s correlation coefficient is 95%.<\/p>\n\n\n\n<p>10. To calculate the ICC:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">library(irr)<\/span><\/em>\n<em><span style=\"color: #ff0000;\">icc(goniometer,model=\"twoway\",type=\"agreement\")<\/span><\/em>\n<em><span style=\"color: #0000ff;\">&nbsp;Single Score Intraclass Correlation<\/span><\/em>\n<em><span style=\"color: #0000ff;\">&nbsp;&nbsp; Model: twoway <\/span><\/em>\n<em><span style=\"color: #0000ff;\">&nbsp;&nbsp; Type : agreement <\/span><\/em>\n<em><span style=\"color: #0000ff;\">&nbsp;&nbsp; Subjects = 60 <\/span><\/em>\n<em><span style=\"color: #0000ff;\">&nbsp;&nbsp;&nbsp;&nbsp; Raters = 2 <\/span><\/em>\n<em><span style=\"color: #0000ff;\">&nbsp;&nbsp; <strong>ICC(A,1) = 0.948<\/strong><\/span><\/em>\n<em><span style=\"color: #0000ff;\">&nbsp;F-Test, H0: r0 = 0 ; H1: r0 &gt; 0 <\/span><\/em>\n<em><span style=\"color: #0000ff;\">&nbsp;F(59,59.8) = 37 , p = 1.6e-31 <\/span><\/em>\n<em><span style=\"color: #0000ff;\">&nbsp;95%-Confidence Interval for ICC Population Values:<\/span><\/em>\n<em><span style=\"color: #0000ff;\">&nbsp; 0.914 &lt; ICC &lt; 0.968<\/span><\/em><\/code><\/pre>\n\n\n\n<p>Therefore, the ICC is 95%.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; The data is also provided in Q8-1.rda (the data frame is called Q8). To call the data in the console: Fit the regression line: The equation of the regression line therefore is: y = 0.735 + 0.165 \u00d7 x 2. What is the correlation coefficient? The correlation coefficient therefore is 99%. 3. Interpolate the [&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-1194","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1194","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=1194"}],"version-history":[{"count":4,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1194\/revisions"}],"predecessor-version":[{"id":4385,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1194\/revisions\/4385"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=1194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}