Performing linear regression with R
Linear regression is a common technique to find the best fit straight line in a scatter plot. The resulting line can help in predictive analysis.
In this recipe, we will add trend lines to CO2 Emission graphs using R:
Getting ready
This recipe has a few prerequisites before it can be followed:
Install R. The R Project for Statistical Computing website is https://www.r-project.org/.
Optionally, install RStudio from https://www.rstudio.com/, which is an integrated environment for R.
Install the Rserve package by running the following in R:
install.packages("Rserve"); library(Rserve); run.Rserve();
You will get a message that says the connection is blocked:
Go to Help, and under Settings and Performance, select Manage External Service Connection...:
Type
localhost
for the Server:, and leave the Port/API Key: to 6311. Test the connection, and ensure you get a successful connection message before proceeding:
Once R is ready and connected, you may proceed with the...