Home » R20 June 2017

R: Linear Regression – Predicting Future Data

This article shows how we can predict future data with Linear Regression using R programming language.

Regression Analysis builds a relationship model between two variables.

The general mathematical equation for linear regression is:

y = ax + b


y = response variable (value we need to find out using predictor variable)
x = predictor variable (value that we know/gather through experiments)
a = constant (regression coefficient)
b = constant (regression coefficient)

For this example, we have two variables: height and weight. These variables have some values and they have a relation. In the below example data: 60kg of weight has 150cm in height, 70kg in weight has 160cm in height, and so on.

For linear regression analysis, at first we need to create a relationship model between two variables using the lm() function. After that, we can use the predict() function to predict value. The summary of the relationship can be fetched using summary() function.

We now insert new value to height. As you can see below that we have added 170 to the height variable. So, now we have to predict the weight for this new height value. For this, we use the relation created through lm function in above code.

The prediction of weight is 73.63518kg for the height of 170cm.

Plotting the scatter graph of height and weight data.

Hope this helps. Thanks.


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed

Comments are closed.