0% found this document useful (0 votes)
12 views4 pages

PRACTICAL5

This document discusses implementing linear regression, multiple regression, and prediction in R programming. It explains the concepts of linear regression using one predictor and response variable, defining the relationship with an equation. It describes using the lm() and predict() functions to create a regression model and predict new values. It also covers multiple regression using more than one predictor variable with the response variable, again using lm() to define the model and predict new values. The aim was to demonstrate these regression techniques in R programming.

Uploaded by

rasikakharche
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

PRACTICAL5

This document discusses implementing linear regression, multiple regression, and prediction in R programming. It explains the concepts of linear regression using one predictor and response variable, defining the relationship with an equation. It describes using the lm() and predict() functions to create a regression model and predict new values. It also covers multiple regression using more than one predictor variable with the response variable, again using lm() to define the model and predict new values. The aim was to demonstrate these regression techniques in R programming.

Uploaded by

rasikakharche
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PRACTICAL - 05

AIM : To implement Linear regression, Multiple regression, and Prediction in R Programming

PLATFORM USED: w3school.com

THEORY:

➢ Regression analysis is a very widely used statistical tool to establish a relationship model
between two variables.
➢ One of these variable is called predictor variable whose value is gathered through
experiments.
➢ The other variable is called response variable whose value is derived from the predictor
variable.
________________________________________________________________________________

1) Linear Regression

o In Linear Regression these two variables are related through an equation, where exponent
(power) of both these variables is 1. Mathematically a linear relationship represents a
straight line when plotted as a graph. A non-linear relationship where the exponent of any
variable is not equal to 1 creates a curve.

o The general mathematical equation for a linear regression is − y = ax + b

o Following is the description of the parameters used −


y is the response variable.
x is the predictor variable.
a and b are constants which are called the coefficients.

o The steps to create the relationship is −

i. Carry out the experiment of gathering a sample of observed values of height and
corresponding weight.
ii. Create a relationship model using the lm() functions in R.
iii. Find the coefficients from the model created and create the mathematical equation
using these
iv. Get a summary of the relationship model to know the average error in prediction.
Also called residuals.
v. To predict the weight of new persons, use the predict() function in R.
o Im() Function
i. This function creates the relationship model between the predictor and the
response variable.
ii. Syntax-The basic syntax for lm() function in linear regression is −
lm(formula,data)

2) predict() Function

o Syntax
The basic syntax for predict() in linear regression is − predict(object, newdata)

o Following is the description of the parameters used –


object is the formula which is already created using the lm() function.
newdata is the vector containing the new value for predictor variable.

Predict the weight of new persons


________________________________________________________________________________

3) Multiple Regression

o Multiple regression is an extension of linear regression into relationship between more


than two variables. In simple linear relation we have one predictor and one response
variable, but in multiple regression we have more than one predictor variable and one
response variable.

o The general mathematical equation for multiple regression is −


y = a + b1x1 + b2x2 +...bnxn

o Following is the description of the parameters used −


• y is the response variable.
• a, b1, b2...bn are the coefficients.
• x1, x2, ...xn are the predictor variables.

o We create the regression model using the lm() function in R. The model determines the
value of the coefficients using the input data. Next we can predict the value of the
response variable for a given set of predictor variables using these coefficients.

o lm() Function - This function creates the relationship model between the predictor and the
response variable.

o Syntax
The basic syntax for lm() function in multiple regression is − lm(y ~ x1+x2+x3...,data)

o Following is the description of the parameters used −


• formula is a symbol presenting the relation between the response variable and
predictor variables.
• data is the vector on which the formula will be applied.

CONCLUSION :
Hence successfully implemented Linear regression, Multiple regression, and Prediction in R
Programming

You might also like