{"id":78637,"date":"2020-05-16T13:11:46","date_gmt":"2020-05-16T07:41:46","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=78637"},"modified":"2020-05-16T13:11:46","modified_gmt":"2020-05-16T07:41:46","slug":"linear-regression-in-r","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/","title":{"rendered":"Linear Regression in R using lm() Function"},"content":{"rendered":"<p>In the <a href=\"https:\/\/techvidvan.com\/tutorials\/r-generalized-linear-models\/\">generalized linear models tutorial<\/a>, we learned about various GLM\u2019s like linear regression, logistic regression, etc.. In this tutorial of the TechVidvan\u2019s R tutorial series, we are going to look at <strong>linear regression in R<\/strong> in detail. We will learn what is R linear regression and how to implement it in R. We will look at the least square estimation method and will also learn how to check the accuracy of the model.<\/p>\n<p>So, without any further ado, let\u2019s get started!<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Linear-Regression-in-R.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78726\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Linear-Regression-in-R.jpg\" alt=\"Linear Regression in R\" width=\"802\" height=\"420\" \/><\/a><\/p>\n<h2>Linear Regression in R<\/h2>\n<p>Linear regression in R is a method used to predict the value of a variable using the value(s) of one or more input predictor variables. The goal of linear regression is to establish a linear relationship between the desired output variable and the input predictors.<\/p>\n<p>To model a continuous variable Y as a function of one or more input predictor variables Xi, so that the function can be used to predict the value of Y when only the values of Xi are known. The general form of such a linear relationship is:<\/p>\n<p><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Y=?0+?1 X<\/strong><\/p>\n<p>Here, ?0 is the intercept<br \/>\nand ?1 is the slope.<\/p>\n<h2>Types of Linear Regression in R<\/h2>\n<p>There are two types of R linear regression:<\/p>\n<ul>\n<li>Simple Linear Regression<\/li>\n<li>Multiple Linear Regression<\/li>\n<\/ul>\n<p>Let\u2019s take a look at these one-by-one.<\/p>\n<h2>Simple Linear Regression in R<\/h2>\n<p>Simple linear regression is aimed at finding a linear relationship between two continuous variables. It is important to note that the relationship is statistical in nature and not deterministic.<\/p>\n<p>A deterministic relationship is one where the value of one variable can be found accurately by using the value of the other variable. An example of a deterministic relationship is the one between kilometers and miles. Using the kilometer value, we can accurately find the distance in miles. A statistical relationship is not accurate and always has a prediction error. For example, given enough data, we can find a relationship between the height and the weight of a person, but there will always be a margin of error and exceptional cases will exist.<\/p>\n<p>The idea behind simple linear regression is to find a line that best fits the given values of both variables. This line can then help us find the values of the dependent variable when they are missing.<\/p>\n<p>Let us study this with the help of an example. We have a dataset consisting of the heights and weights of 500 people. Our aim here is to build a linear regression model that formulates the relationship between height and weight, such that when we give height(Y) as input to the model it may give weight(X) in return to us with minimum margin or error.<\/p>\n<p><strong> \u00a0 \u00a0 \u00a0 Y=b0+b1X<\/strong><\/p>\n<p>The values of b0 and b1 should be chosen so that they minimize the margin of error. The error metric can be used to measure the accuracy of the model.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78732\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq1.png\" alt=\"Error metric in r\" width=\"419\" height=\"104\" \/><\/a><\/p>\n<p>We can calculate the slope or the co-efficient as:<br \/>\n<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78733\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq2.png\" alt=\"Coefficient of error metric in R\" width=\"270\" height=\"108\" \/><\/a><br \/>\nThe value of b1 gives us insight into the nature of the relationship between the dependent and the independent variables.<\/p>\n<ul>\n<li>If b1 &gt; 0, then the variables have a <strong>positive relationship<\/strong> i.e. increase in x will result in an increase in y.<\/li>\n<li>If b1 &lt; 0, then the variables have a <strong>negative relationship<\/strong> i.e. increase in x will result in a decrease in y.<\/li>\n<\/ul>\n<p>The value of b0 or intercept can be calculated as follows:<br \/>\n<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78734\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq3.png\" alt=\"Intercept in r\" width=\"274\" height=\"77\" \/><\/a>The value of b0 can also give a lot of information about the model and vice-versa.<\/p>\n<p>If the model does not include x=0, then the prediction is meaningless without b1. For the model to only have b0 and not b1 in it at any point, the value of x has to be 0 at that point. In cases such as height, x cannot be 0 and a person\u2019s height cannot be 0. Therefore, such a model is meaningless with only b0.<\/p>\n<p>If the b0 term is missing then the model will pass through the origin, which will mean that the prediction and the regression coefficient(slope) will be biased.<\/p>\n<h2>Multiple Linear Regression in R<\/h2>\n<p>Multiple linear regression is an extension of simple linear regression. In multiple linear regression, we aim to create a linear model that can predict the value of the target variable using the values of multiple predictor variables. The general form of such a function is as follows:<\/p>\n<p><strong>Y=b0+b1X1+b2X2+&#8230;+bnXn<\/strong><\/p>\n<h2>Assessing the Accuracy of the Model<\/h2>\n<p>There are various methods to assess the quality and accuracy of the model. Let\u2019s take a look at some of these methods one at a time.<\/p>\n<h3>1. R-Squared<\/h3>\n<p>The real information in data is the variance conveyed in it. R-squared tells us the proportion of variation in the target variable (y) explained by the model. We can find the R-squared measure of a model using the following formula:<br \/>\n<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-78735 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq4.png\" alt=\"R squared linear regression analysis in R\" width=\"265\" height=\"98\" \/><\/a><br \/>\nWhere,<\/p>\n<ul>\n<li>yi is the fitted value of y for observation i<\/li>\n<li>y is the mean of Y.<\/li>\n<\/ul>\n<p>A lower value of R-squared signifies a lower accuracy of the model. However, the R-squared measure is not necessarily a final deciding factor.<\/p>\n<h3>2. Adjusted R-Squared<\/h3>\n<p>As the number of variables increases in the model, the <a href=\"https:\/\/www.investopedia.com\/terms\/r\/r-squared.asp\">R-squared value<\/a> increases as well. This also causes errors in the variation explained by the newly added variables. Therefore, we adjust the formula for R square for multiple variables.<br \/>\n<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Eq5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78736\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Eq5.png\" alt=\"Adjusted R squared analysis in r\" width=\"240\" height=\"62\" \/><\/a>Here, the MSE stands for <strong>Mean Standard Error<\/strong> which is:<br \/>\n<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Eq6-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78737\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Eq6-1.png\" alt=\"Mean Standard Error in R\" width=\"265\" height=\"93\" \/><\/a><br \/>\nAnd MST stands for<strong> Mean Standard Total<\/strong> which is given by:<br \/>\n<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Eq7-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78738\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Eq7-1.png\" alt=\"Mean Standard Total in R\" width=\"228\" height=\"95\" \/><\/a><br \/>\nWhere, n is the number of observations and q is the number of coefficients.<\/p>\n<p>The relationship between R-squared and adjusted R-squared is:<br \/>\n<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Eq8-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78739\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/Eq8-1.png\" alt=\"relationship between R-squared and adjusted R-squared\" width=\"254\" height=\"78\" \/><\/a><\/p>\n<h3>3. Standard Error and F-Statistic<\/h3>\n<p>The standard error and the F-statistic are both measures of the quality of the fit of a model. The formulae for standard error and F-statistic are:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq9-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78740\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq9-1.png\" alt=\"Standard Error and F-Statistic in R\" width=\"420\" height=\"135\" \/><\/a><\/p>\n<p>Where MSR stands for <strong>Mean Square Regression<\/strong><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq10-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78741\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/eq10-1.png\" alt=\"Mean Square Regression in R\" width=\"240\" height=\"121\" \/><\/a><\/p>\n<h3>4. AIC and BIC<\/h3>\n<p><strong>Akaike\u2019s Information Criterion<\/strong> and<a href=\"https:\/\/www.statisticshowto.com\/bayesian-information-criterion\/\"> Bayesian Information Criterion<\/a> are measures of the quality of the fit of statistical models. They can also be used as criteria for the selection of a model.<\/p>\n<p><strong>AIC=(-2)*ln(L)+2*k<\/strong><br \/>\n<strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 BIC=(-2)*ln(L)+k*ln(n)<\/strong><\/p>\n<p>Where,<\/p>\n<ul>\n<li>L is the likelihood function,<\/li>\n<li>k is the number of model parameters,<\/li>\n<li>n is the sample size.<\/li>\n<\/ul>\n<h2>lm function in R<\/h2>\n<p>The <strong>lm() function<\/strong> of R fits linear models. It can carry out regression, and analysis of variance and covariance. The syntax of the lm function is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">lm(formula, data, subset, weights, na.action,\nmethod = \"qr\", model = TRUE, x = FALSE, y = FALSE, qr = TRUE,\nsingular.ok = TRUE, offset, \u2026)<\/pre>\n<p>Where,<\/p>\n<ul>\n<li><strong>formula<\/strong> is an object of class \u201cformula\u201d and is a symbolic representation of the model to fit,<\/li>\n<li><strong>data<\/strong> is the data frame or list that contains the variables in the formula(data is an optional argument. If it is missing, the function picks up the variables from the environment),<\/li>\n<li><strong>subset<\/strong> is an optional vector containing a subset of observations that are to be used in the fitting process,<\/li>\n<li><strong>weights<\/strong> is an optional vector that specifies the weights to be used in the fitting process,<\/li>\n<li><strong>na.action<\/strong> is a function that shows what should happen when NA\u2019s are encountered in the data,<\/li>\n<li><strong>method<\/strong> signifies the method for fitting the model,<\/li>\n<li><strong>model, x, y, and qr<\/strong> are logicals that control whether corresponding values should be returned with the output or not. These values are:<\/li>\n<li><strong>model<\/strong>: the model frame<\/li>\n<li><strong>x:<\/strong> the model matrix<\/li>\n<li><strong>y<\/strong>: the response<\/li>\n<li><strong>qr<\/strong>: the qr decomposition<\/li>\n<li><strong>singular.ok<\/strong> is a logical that control whether singular fits are allowed or not,<\/li>\n<li><strong>offset<\/strong> is a priorly known predictor that should be used in the model,<\/li>\n<li><strong>. . .<\/strong> are additional arguments to be passed to the lower level regression functions.<\/li>\n<\/ul>\n<h2>Practical Example of Linear Regression in R<\/h2>\n<p>That is enough theory for now. Let us take a look at how to implement all this. We are going to fit a linear model using linear regression in R with the help of the lm() function. We will also check the quality of fit of the model afterward. Let\u2019s use the cars dataset which is provided by default in the base R package.<\/p>\n<p>1. Let us start with a graphical analysis of the dataset to get more familiar with it. To do that we will draw a scatter plot and check what it tells us about the data.<\/p>\n<p>We can use <strong>scatter.smooth() function<\/strong> to create a scatter plot for the dataset.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">scatter.smooth(x=cars$speed,y=cars$dist,main=\"TechVidvan Dist ~ Speed\")<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/1.linear-regression-in-r-scatter-plot.jpeg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78728\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/1.linear-regression-in-r-scatter-plot.jpeg\" alt=\"Scatter Plot in r\" width=\"638\" height=\"398\" \/><\/a><\/p>\n<p>The scatter plot shows us a positive correlation between distance and speed. It suggests a linearly increasing relationship between the two variables. This makes the data suitable for linear regression as a linear relationship is a basic assumption for fitting a linear model on data.<\/p>\n<p>2. Now that we have verified that linear regression is suitable for the data, we can use the lm() function to fit a linear model to it.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Linear_model &lt;- lm(dist~speed,data=cars)\nprint(Linear_model)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/2.linear-model-in-r-lm-function.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78729\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/2.linear-model-in-r-lm-function.png\" alt=\"lm function in R\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<p>The output of the<strong> lm() function<\/strong> shows us the intercept and the coefficient of speed. Thus defining the linear relationship between distance and speed as:<\/p>\n<p><strong>Distance=Intercept+coefficient*speed<\/strong><\/p>\n<p><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Distance=-17.579+3.932*speed<\/strong><\/p>\n<p>3. Now that we have fitted a model let us check the quality or goodness of the fit. Let us start by checking the summary of the linear model by using the <strong>summary() function.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">summary(Linear_model)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/3.linear-regression-in-r-summary-of-the-model.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78730\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/3.linear-regression-in-r-summary-of-the-model.png\" alt=\"R Linear Regression\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<p>The summary() function gives us a few important measures to help diagnose the fit of the model. The p-value is an important measure of the goodness of the fit of a model. A model is said to not be fit if the p-value is more than a pre-determined statistical significance level which is ideally 0.05.<\/p>\n<p>The summary also provides us with the t-value. The more the t-value the better fit the model is.<br \/>\nWe can also find the AIC and BIC by using the AIC() and the BIC() functions.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">AIC(Linear_model)\nBIC(Linear_model)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/4.linear-regression-in-r-aic-and-bic-functions.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-78731 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/05\/4.linear-regression-in-r-aic-and-bic-functions.png\" alt=\"aic and bic functions in R - Linear regression in R\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<p>The model which results in the lowest AIC and BIC scores is the most preferred.<\/p>\n<h2>Summary<\/h2>\n<p>In this chapter of the TechVidvan\u2019s R tutorial series, we learned about linear regression. We learned about simple linear regression and multiple linear regression. Then we studied various measures to assess the quality or accuracy of the model, like the R2, adjusted R2, standard error, F-statistics, AIC, and BIC. We then learned how to implement linear regression in R. We then checked the quality of the fit of the model in R.<\/p>\n<p>Do share your rating on <a href=\"https:\/\/g.page\/techvidvan?gm\">Google <\/a>if you liked the Linear Regression tutorial.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the generalized linear models tutorial, we learned about various GLM\u2019s like linear regression, logistic regression, etc.. In this tutorial of the TechVidvan\u2019s R tutorial series, we are going to look at linear regression&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":78726,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1020],"tags":[2639,2640,2641,2642,2643],"class_list":["post-78637","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-linear-regression-in-r","tag-multiple-linear-regression-in-r","tag-r-linear-regression","tag-r-linear-regression-tutorial","tag-simple-linear-regression-in-r"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Linear Regression in R using lm() Function - TechVidvan<\/title>\n<meta name=\"description\" content=\"Linear Regression in R - What is R linear regression, its implementation and types - simple and multiple, R Square, adjusted R square, standard error, F-statistics, AIC,BIC\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linear Regression in R using lm() Function - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Linear Regression in R - What is R linear regression, its implementation and types - simple and multiple, R Square, adjusted R square, standard error, F-statistics, AIC,BIC\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-16T07:41:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Linear-Regression-in-R.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linear Regression in R using lm() Function - TechVidvan","description":"Linear Regression in R - What is R linear regression, its implementation and types - simple and multiple, R Square, adjusted R square, standard error, F-statistics, AIC,BIC","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/","og_locale":"en_US","og_type":"article","og_title":"Linear Regression in R using lm() Function - TechVidvan","og_description":"Linear Regression in R - What is R linear regression, its implementation and types - simple and multiple, R Square, adjusted R square, standard error, F-statistics, AIC,BIC","og_url":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-05-16T07:41:46+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Linear-Regression-in-R.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Linear Regression in R using lm() Function","datePublished":"2020-05-16T07:41:46+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/"},"wordCount":1711,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Linear-Regression-in-R.jpg","keywords":["Linear regression in R","Multiple linear regression in R","R linear Regression","R Linear Regression Tutorial","Simple Linear Regression in R"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/","url":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/","name":"Linear Regression in R using lm() Function - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Linear-Regression-in-R.jpg","datePublished":"2020-05-16T07:41:46+00:00","description":"Linear Regression in R - What is R linear regression, its implementation and types - simple and multiple, R Square, adjusted R square, standard error, F-statistics, AIC,BIC","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Linear-Regression-in-R.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/05\/Linear-Regression-in-R.jpg","width":802,"height":420,"caption":"Linear Regression in R"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/linear-regression-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Linear Regression in R using lm() Function"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/78637","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=78637"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/78637\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/78726"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=78637"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=78637"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=78637"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}