Practical 05: MULTIPLE REGRESSION MODEL
AIM: MULTIPLE REGRESSION MODEL Apply multiple regressions, if data have a continuous
independent variable.
Multiple Regression model:
Multiple Linear Regression is a statistical technique that models the relationship between one
dependent variable and two or more independent variables.It helps answer questions like:
Description:
In this project, we use a small custom housing dataset to understand the relationship
between house prices and other influencing factors. The dependent variable is MEDV
(median home value), and independent variables are:
RM — Average number of rooms
LSTAT — Percentage of low-income population
PTRATIO — Pupil-teacher ratio
In this project, we use a small custom housing dataset to understand the relationship
between house prices and other influencing factors. The dependent variable is MEDV
(median home value), and independent variables are:
RM — Average number of rooms
LSTAT — Percentage of low-income population
PTRATIO — Pupil-teacher ratio
A) Multiple regression:
Code:
# Step 1: Create the dataset
price <- c(24, 21, 34, 19, 28, 23, 17, 31, 26, 22)
rooms <- c(6.5, 5.8, 7.0, 5.3, 6.8, 6.1, 5.5, 7.2, 6.3, 5.9)
low_income <- c(12.0, 15.5, 5.0, 20.0, 8.5, 13.0, 22.0, 6.0, 10.0, 14.0)
ptratio <- c(18.0, 20.0, 16.5, 21.0, 17.0, 19.5, 22.0, 16.0, 18.5, 20.0)
# Step 2: Combine into a dataframe
housing <- data.frame(
MEDV = price,
RM = rooms,
LSTAT = low_income,
PTRATIO = ptratio
# Step 3: Build the multiple linear regression model
model <- lm(MEDV ~ RM + LSTAT + PTRATIO, data = housing)
# Step 4: Summary of the model
summary(model)
# Step 5: Plotting
# Plot 1: RM vs MEDV with regression line
plot(housing$RM, housing$MEDV, main="Rooms vs Price",
xlab="Average Number of Rooms", ylab="Price (MEDV)", pch=19, col="blue")
abline(lm(MEDV ~ RM, data = housing), col="red", lwd=2)
# Plot 2: LSTAT vs MEDV
plot(housing$LSTAT, housing$MEDV, main="% Low Income vs Price",
xlab="% Lower Status Population", ylab="Price (MEDV)", pch=19, col="darkgreen")
# Plot 3: PTRATIO vs MEDV
plot(housing$PTRATIO, housing$MEDV, main="Pupil-Teacher Ratio vs Price",
xlab="PTRATIO", ylab="Price (MEDV)", pch=19, col="purple")
# Plot 4: Residuals plot
plot(model$residuals, main="Residuals Plot", ylab="Residuals", pch=19, col="orange")
abline(h=0, col="red", lty=2)
OUTPUT:
✅ Learnings
Through this project, I learned how to apply multiple linear regression in R to predict
outcomes using multiple variables. I gained hands-on experience with data creation, model
fitting using lm(), and result interpretation using R output. I also learned how to visualize
relationships and residuals to evaluate model performance. Lastly, I understood how each
independent variable uniquely influences the dependent variable in a multivariate context.