{"id":5186,"date":"2021-01-03T19:15:34","date_gmt":"2021-01-04T03:15:34","guid":{"rendered":"https:\/\/portasftpserver.com\/?p=5186"},"modified":"2022-09-16T14:33:00","modified_gmt":"2022-09-16T21:33:00","slug":"simple-linear-regression-models","status":"publish","type":"post","link":"https:\/\/portasftpserver.com\/simple-linear-regression-models\/","title":{"rendered":"Linear Regression Model &#8211; Part II"},"content":{"rendered":"\n<p class=\"sera-block-paragraph\">A <strong>simple linear regression model<\/strong> consists of one predictor variable and one dependent variable. The regression model formula is <\/p>\n\n\n\n<p class=\"sera-block-paragraph\">\\( \\hat{Y} \\) = <strong>intercept + slope \u22c5 x<\/strong> <\/p>\n\n\n\n<p class=\"sera-block-paragraph\">or if you would think in math \\(\\hat{Y} = b_{0} +  b_{1}x \\)<\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Do not be confused with the equation or the formula. The y-hat (\\( \\hat{y} \\)) is a predicted response variable from the predictor variable or x. The b0 is the intercept (value of y when x is zero). And the b1 is the slope or the rise over run in which a unit change in y based upon a unit change in x and these are referred to as regression coefficients.<\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Let\u2019s consider the following dataset for the monthly <strong>E-commerce sales<\/strong> (in $1000\u2019s) and online advertising costs (in $1000\u2019s).<\/p>\n\n\n\n<figure class=\"sera-block-table is-style-stripes\"><table><thead><tr><th>Store<\/th><th class=\"has-text-align-center\" data-align=\"center\">Monthly E-commerce Sales<br>(in $1000)<\/th><th>Online Advertising Cost<br>(in $1000)<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td class=\"has-text-align-center\" data-align=\"center\">370<\/td><td>2.3<\/td><\/tr><tr><td>2<\/td><td class=\"has-text-align-center\" data-align=\"center\">311<\/td><td>1.7<\/td><\/tr><tr><td>3<\/td><td class=\"has-text-align-center\" data-align=\"center\">620<\/td><td>3.0<\/td><\/tr><tr><td>4<\/td><td class=\"has-text-align-center\" data-align=\"center\">910<\/td><td>5<\/td><\/tr><tr><td>5<\/td><td class=\"has-text-align-center\" data-align=\"center\">500<\/td><td>2.9<\/td><\/tr><tr><td>6<\/td><td class=\"has-text-align-center\" data-align=\"center\">520<\/td><td>2.5<\/td><\/tr><tr><td>7<\/td><td class=\"has-text-align-center\" data-align=\"center\">600<\/td><td>3.4<\/td><\/tr><tr><td>8<\/td><td class=\"has-text-align-center\" data-align=\"center\">830<\/td><td>4.3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"sera-block-paragraph\">So if we execute the code<\/p>\n\n\n\n<pre class=\"sera-block-code\"><code lang=\"matlab\" class=\"language-matlab\">Sales&lt;-c(370, 311, 620, 910, 500, 520, 600, 830)\nAdvertising.Cost&lt;-c(2.3, 1.7, 3.0, 5, 2.9, 2.5, 3.4, 4.3) \nplot(Advertising.Cost, Sales, xlab=\"Advertising Cost (in $1000)\", ylab=\"Monthly E-commerce Sales (in $1000)\", ylim=c(200,1000), pch=16, cex=2, col=\"blue\") \nabline(lm(Sales~Advertising.Cost)) <\/code><\/pre>\n\n\n\n<p class=\"sera-block-paragraph\">As you would expect, the scatter plot below seems to just have linear data points that indicate and show a <strong>strong positive correlation<\/strong>. This makes sense and appropriate to use a simple linear regression model for the dataset.<\/p>\n\n\n\n<figure class=\"sera-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"847\" height=\"576\" src=\"https:\/\/portasftpserver.com\/sera-uploads\/2021\/01\/image-2.png\" alt=\"\" class=\"sera-image-5243\" srcset=\"https:\/\/portasftpserver.com\/sera-uploads\/2021\/01\/image-2.png 847w, https:\/\/portasftpserver.com\/sera-uploads\/2021\/01\/image-2-585x398.png 585w, https:\/\/portasftpserver.com\/sera-uploads\/2021\/01\/image-2-768x522.png 768w, https:\/\/portasftpserver.com\/sera-uploads\/2021\/01\/image-2-100x68.png 100w, https:\/\/portasftpserver.com\/sera-uploads\/2021\/01\/image-2-600x408.png 600w\" sizes=\"auto, (max-width: 847px) 100vw, 847px\" \/><\/figure>\n\n\n\n<p class=\"sera-block-paragraph\">It is so clear that when advertising costs go up it seems to carry the monthly E-commerce sales up as well. The orange linear regression line is what produce from the equation of a simple linear regression model. <\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><strong>By using R<\/strong><\/p>\n\n\n\n<pre class=\"sera-block-code\"><code lang=\"python\" class=\"language-python\">mod&lt;-lm(Sales~Advertising.Cost)\nsummary(mod)<\/code><\/pre>\n\n\n\n<figure class=\"sera-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/portasftpserver.com\/sera-uploads\/2021\/01\/image-3.png\" alt=\"\" class=\"sera-image-5245\" width=\"586\" height=\"302\" srcset=\"https:\/\/portasftpserver.com\/sera-uploads\/2021\/01\/image-3.png 529w, https:\/\/portasftpserver.com\/sera-uploads\/2021\/01\/image-3-100x52.png 100w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/figure>\n\n\n\n<p class=\"sera-block-paragraph\">The estimate simple linear regression equation is<\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><strong>\\( \\hat{y} \\)=-5.192 + 187.352x<\/strong><\/p>\n\n\n\n<p class=\"sera-block-paragraph\">3.33e-05 is the p-value which basically means that indicates that the advertising cost significantly affects the monthly E-commerce sales.<\/p>\n\n\n\n<figure class=\"sera-block-embed is-type-video is-provider-youtube sera-block-embed-youtube sera-embed-aspect-16-9 sera-has-aspect-ratio\"><div class=\"sera-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"P-value calculations: Understanding where the p-value comes from\" width=\"900\" height=\"506\" src=\"https:\/\/www.youtube.com\/embed\/0-fEKHSeRR0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"sera-block-paragraph\">References<\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Minitlab (Jul 1, 2013). <em>How to Interpret Regression Analysis Results: P-values and Coefficients<\/em>.<em> <\/em>Retrieved from <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.minitab.com\/blog\/adventures-in-statistics-2\/how-to-interpret-regression-analysis-results-p-values-and-coefficients#\" target=\"_blank\">https:\/\/blog.minitab.com\/blog\/adventures-in-statistics-2\/how-to-interpret-regression-analysis-results-p-values-and-coefficients#<\/a><\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Dr. Nic&#8217;s Maths and Stats(Feb 1, 2020). <em>Understanding where the p-value comes from<\/em> Retrieved from <a rel=\"noreferrer noopener\" href=\"https:\/\/www.youtube.com\/watch?v=0-fEKHSeRR0\" target=\"_blank\">https:\/\/www.youtube.com\/watch?v=0-fEKHSeRR0<\/a><\/p>\n\n\n\n<p class=\"sera-block-paragraph\">Brandon Foltz (Nov 23,2013). <em>Linear Regression, The Very Basic. <\/em>Retrieved from<em> <\/em><a href=\"https:\/\/youtu.be\/ZkjP5RJLQF4?list=PLIeGtxpvyG-LoKUpV0fSY8BGKIMIdmfCi&amp;t=218\">https:\/\/youtu.be\/ZkjP5RJLQF4?list=PLIeGtxpvyG-LoKUpV0fSY8BGKIMIdmfCi&amp;t=218<\/a><\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"sera-block-heading\">Want to refresh it?<\/h3>\n\n\n\n<p class=\"sera-block-paragraph\">Linear Regression <a rel=\"noreferrer noopener\" href=\"https:\/\/portasftpserver.com\/linear-regression-models\/\" data-type=\"URL\" data-id=\"https:\/\/portasftpserver.com\/linear-regression-models\/\" target=\"_blank\">Part I<\/a><br>Linear Regression <a rel=\"noreferrer noopener\" href=\"https:\/\/portasftpserver.com\/simple-linear-regression-models\/\" target=\"_blank\">Part II<\/a><\/p>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"sera-block-heading\"><strong>Otherwise let&#8217;s keep moving forward<\/strong><\/h3>\n\n\n\n<h3 class=\"sera-block-heading\">See you in <strong><a href=\"https:\/\/portasftpserver.com\/linear-regression-model-part-iii\" data-type=\"URL\" data-id=\"https:\/\/portasftpserver.com\/linear-regression-model-part-iii\">part III<\/a><\/strong><\/h3>\n\n\n\n<p class=\"sera-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A simple linear regression model consists of one predictor variable and one dependent variable. The regression model formula is = intercept + slope \u22c5 x or if you would think in math Do not be confused with the equation or the formula. The y-hat () is a predicted response variable from the predictor variable or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7747,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5186","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-software"],"_links":{"self":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts\/5186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/comments?post=5186"}],"version-history":[{"count":0,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/posts\/5186\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/media\/7747"}],"wp:attachment":[{"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/media?parent=5186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/categories?post=5186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/portasftpserver.com\/sera-json\/wp\/v2\/tags?post=5186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}