0% found this document useful (0 votes)
7 views

DS EXP5

The document outlines the procedure for writing an R program to perform Linear Regression, Test of Significance, and Residual Analysis. It includes steps for understanding data, defining variables, coding, testing, and optimizing the program. The source code provided demonstrates the implementation of a linear model using salary data and visualizes the results with a plot.

Uploaded by

LIGHTNING BOLT
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)
7 views

DS EXP5

The document outlines the procedure for writing an R program to perform Linear Regression, Test of Significance, and Residual Analysis. It includes steps for understanding data, defining variables, coding, testing, and optimizing the program. The source code provided demonstrates the implementation of a linear model using salary data and visualizes the results with a plot.

Uploaded by

LIGHTNING BOLT
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/ 2

Ex.

No: 5
Linear Regression, Test of significance and
DATE:
Residual Analysis

Aim:
To write the R program for Linear Regression, Test of Significance and Residual
Analysis
Procedure:
Step 1: Understand the input, output, and constraints.
Step 2: Break the problem into small steps logically.
Step 3: Define variables to store input and output.
Step 4: Use loops or conditionals to process the data.
Step 5: Write the code to implement the logic step by step.
Step 6: Test the program with sample inputs and verify outputs.
Step 7: Optimize and clean up the code for readability.
DataSet:

Source code:
library(ggplot2)
dataset <- salary_data
head(dataset)
model <- lm(Salary ~ Experience, data = dataset)
summary(model)
actual <- dataset$Salary
predicted <- predict(model)
sse_value <- sum((actual - predicted)^2)
sst_value <- sum((actual - mean(actual))^2)
rmse_value <- sqrt(mean((actual - predicted)^2))

ARJUN SUDHEER (71812201021)


r_squared <- summary(model)$r.squared
cat("● SSE (Sum of Squared Errors) =", round(sse_value, 2))
cat("● SST (Total Sum of Squares) =", round(sst_value, 2))
cat("● RMSE (Root Mean Squared Error) =", round(rmse_value, 2))
cat("● R² =", round(r_squared, 4))
new_experience <- data.frame(Experience = c(5, 10, 15))
predicted_salaries <- predict(model, newdata = new_experience)
print(predicted_salaries)
ggplot(dataset, aes(x = Experience, y = Salary)) +
geom_point(color = "blue") +
geom_smooth(method = "lm", col = "red") +
labs(title = "Salary vs Experience", x = "Years of Experience", y = "Salary")
Output:

Result:
Thus, to write the R program for Linear Regression, Test of Significance and Residual
Analysis was successfully verified.

ARJUN SUDHEER (71812201021)

You might also like