Learn Before
Example of Linear Regression Using R
Here is an example of using R to do a simple linear regression.
#MASS package is a very large collection of data sets and #functions library(MASS) #ISLR package includes the data sets associated with this #book library(ISLR) lm.fit=lm(medv∼lstat,data=Boston) # medv as a response, lstat as a predictor summary(lm.fit) # gives us pvalues and standard errors for the coefficients, as well as the R2 statistic and F-statistic for the model confint(lm.fit) # obtain a confidence interval predict (lm.fit ,data.frame(lstat=c(5,10,15)), interval="confidence") #prediction in confidence intervals predict (lm.fit ,data.frame(lstat=c(5,10,15)), interval="prediction") #prediction in prediction intervals attach(Boston) # attach data to Boston plot(lstat ,medv) abline(lm.fit ,lwd=3,col="red") # draw out the regression line
Expected output (plot and abline only):

0
2
Contributors are:
Who are from:
Tags
Data Science
Related
Types of linear regression
Logistic Regression
When is a model considered linear?
Linear Regression and Linear Models Videos
Example of Linear Regression Using R
Training or Fitting a linear regression model
Assessing the accuracy of linear regression
Comparison of Linear Regression with K-Nearest Neighbors
Assumptions of Linear Regression
Regression Coefficient
Linear regression vs. nonlinear regression
Popular Regularization Techniques in Deep Learning
Polynomial Future Transformation
Locally Weighted Linear Regression
Linear Regression Dataset Notation
History of Linear Regression
Linear Regression One-Dimensional Fit
Squared Error Loss
Linear Regression Conditional Mean Assumption
Linear Regression Weight Parameters
Linear Regression Bias Parameter
Linear Regression as a Neural Network
Synthetic Data Generation for Linear Regression