Learn Before
Code
Example of Multiple Linear Regression Using R
Here is an example of multiple linear regression using R:
library(MASS) # MASS package is a very large collection of data sets and functions library(ISLR) # ISLR package includes the data sets associated with this book lm.fit=lm(medv∼lstat+age,data=Boston)# medv as a response, lstat and age as two predictors summary(lm.fit) # gives us p-values and standard errors for the coefficients, as well as the R2 statistic and F-statistic for the model #The syntax lm(y∼x1+x2+x3) is used to fit a model with three predictors, #x1, x2, andx3. The summary() function now outputs the regression #coefficients for all the predictors. #We can also make a regression using all predictors with the following code: lm.fit=lm(medv∼.,data=Boston)
0
3
Updated 2021-04-16
Contributors are:
Who are from:
Tags
Data Science