<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by dan derieg on Medium]]></title>
        <description><![CDATA[Stories by dan derieg on Medium]]></description>
        <link>https://medium.com/@danderieg?source=rss-521920197c66------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*J51VrcUmDbqOSEZn8OIHfw.jpeg</url>
            <title>Stories by dan derieg on Medium</title>
            <link>https://medium.com/@danderieg?source=rss-521920197c66------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:40:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danderieg/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Simple Linear Regression with r]]></title>
            <link>https://medium.com/@danderieg/simple-linear-regression-with-r-2fd05bbec4b8?source=rss-521920197c66------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fd05bbec4b8</guid>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[r]]></category>
            <dc:creator><![CDATA[dan derieg]]></dc:creator>
            <pubDate>Fri, 26 Jun 2020 00:32:16 GMT</pubDate>
            <atom:updated>2020-06-26T03:04:04.710Z</atom:updated>
            <content:encoded><![CDATA[<p>Simple linear regression is a statistical process that estimates the linear relationship between one explanatory variable (independent) and one response variable (dependent). The resulting relation ship is given through the equation of line Y=β0+β1x (1). Here Y is the response variable, β0 is the intercept and β1 is the slope. This tutorial will perform a simple linear regression step by step in r.</p><ul><li><strong>Load your data</strong> into your r workspace. We are using a csv (comma-separated values) file that contains a countries life expectancy and their countries happiness score (data from <a href="https://www.kaggle.com/unsdsn/world-happiness">https://www.kaggle.com/unsdsn/world-happiness</a>)</li></ul><pre>LE = read.csv(&quot;happiness_and_lifex1.csv&quot;, header = TRUE)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x1TeQ9F01Ht-LhLGhFFobA.png" /></figure><ul><li><strong>Run regression</strong>. R uses the lm() function to perform linear regression. Inputs for the lm function follow the form: lm(response variable ~ explanatory variable, data = data as data.frame).</li></ul><pre>LE_model = lm(Life.expectancy ~ Score, data = LE)</pre><p>To see the results of the regression we can use the summary() function.</p><pre>summary(LE_model)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*GJVGCX0l2wxODjxFL_vbAQ.png" /></figure><p>The summary function gives a very detailed analysis of the regression. The primary values for the regression line are the Estimate Std. values in the coefficients block. Here we see the values, 40.0832 and 5.8828, which are our β0 and β1 values for equation 1. Plugging those values in yields our fitted simple linear regression model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*w6j1EPznSquZkwf-dH7PuQ.png" /></figure><p>This equation can be interpreted directly. The β0 is the value when x is equal to zero. In this case a country with a happiness score of 0 would have a life expectancy of 40.0832. β1 represents the change in the mean life expectancy per 1 unit change in happiness. So for every increase in unit of happiness , the mean life expectancy increases by 5.8828.</p><p>To visually see the regression line we use the abline function in the form abline(slope, intercpt).</p><pre>plot(Life_Expectancy ~ Happiness_Score, data = LE)<br>abline(40.0832, 5.8828, col = &quot;red&quot;, lwd = 3 )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qgJ6Ly4npJDZQ-6s1J7bNQ.png" /></figure><p>That’s it, with just a few lines of code we are able to perform a detailed simple linear regression in r.</p><p>For further analysis we can look deeper into the summary(LE_model) results. The line that says Multiple R-squared gives us the amount of variation in life expectancy that is explained by the linear relationship with country happiness score. In this example 61.38% of variation is explained via the model. R squared is computed by taking the amount of variance explained through the regression and dividing it by the total amount of variation in the model (see decomposition of variance).</p><p>Another useful statistic shown in the summary is the p-value. If we were to run a null hypothesis test on this model, the p-values are calculated for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*pQdc6iqlvf4k57zpPQxJDQ.png" /></figure><p>In this model the p-values for the significance of regression and the coefficients are all &lt; 2.2e-16. This means at any alpha we would reject the null hypothesis concluding that the linear relationship of the model is significant and all the coefficients are also significant.</p><p>This was a brief demonstration of linear regression in r. Multilinear regression in r is just as easy and will be covered in the following tutorial.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fd05bbec4b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>