---
title: "Linear_Regressions"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
theme: flatly
social: menu
source_code: embed
color: blue
---
```{r setup, include=FALSE}
library(flexdashboard)
library(flexdashboard)
library(MASS)
library(lattice)
library(dplyr)
library(ggplot2)
library(shiny)
library(DT)
```
# Dataset Description
## View of dataset
```{r}
cls <- read.csv("/cloud/project/8725922/class12-2023.csv")
datatable(cls, extensions = "Buttons",options=list(dom='Bfrtip',Buttons=c('copy','csv','print','pdf')))
```
# About
## Structure of the dataset
### Structure of the dataset
```{r}
str(cls)
```
# Summary
## Summary
### Summary
```{r}
summary(cls)
```
### Tail
```{r}
tail(cls)
```
### Head
```{r}
head(cls)
```
### Checking missing values
```{r}
print(sum(is.na(cls)))
```
# EDA
## Histogram
### Histogram for Government Insitution
```{r}
ggplot(cls ,aes(x = GOVT)) +
geom_histogram(fill = "lightblue", color = "black") +
geom_vline(aes(xintercept = mean(GOVT)), color = "red", lwd = 1) +
labs(title = "Histogram of Government", x = "government")
```
### Histogram for KV Insitution
```{r}
ggplot(cls ,aes(x = KV)) +
geom_histogram(fill = "lightblue", color = "black") +
geom_vline(aes(xintercept = mean(KV)), color = "red", lwd = 1) +
labs(title = "Histogram of Government", x = "government")
```
### Histogram for Government aided Insitution
```{r}
ggplot(cls ,aes(x = `GOVT.AIDED`)) +
geom_histogram(fill = "lightblue", color = "black") +
geom_vline(aes(xintercept = mean(`GOVT.AIDED`)), color = "red", lwd = 1) +
labs(title = "Histogram of Government Aided", x = "government aided")
```
### Histogram for JNV Insitution
```{r}
ggplot(cls ,aes(x = JNV)) +
geom_histogram(fill = "lightblue", color = "black") +
geom_vline(aes(xintercept = mean(JNV)), color = "red", lwd = 1) +
labs(title = "Histogram of JNV Insitution", x = "JNV Insitution")
```
### Histogram for INDEPENDENT Insitution
```{r}
ggplot(cls ,aes(x = INDEPENDENT)) +
geom_histogram(fill = "lightblue", color = "black") +
geom_vline(aes(xintercept = mean(INDEPENDENT)), color = "red", lwd = 1) +
labs(title = "Histogram of INDEPENDENT Insitution", x = "INDEPENDENT Insitution")
```
## Box plot
### Box Plot for GOVT
```{r}
boxplot(cls$GOVT)
```
### Box Plot for GOVT AIDED
```{r}
boxplot(cls$`GOVT.AIDED`)
```
### Box Plot for KV Insitution
```{r}
boxplot(cls$KV)
```
### Box Plot for Independent Insitution
```{r}
boxplot(cls$INDEPENDENT)
```
### Box Plot for JNV Insitution
```{r}
boxplot(cls$JNV)
```
## Scatter plot
### Scater plot GOVERNMENT vs GOVERNMENT AIDED
```{r}
ggplot(cls, aes(x = GOVT, y = `GOVT.AIDED`)) +
geom_point() +
labs(title = "Scatter plot of GOVT vs. GOVT AIDED")
```
### Scater plot for GOVT vs INDEPENDENT
```{r}
ggplot(cls, aes(x = GOVT, y = INDEPENDENT)) +
geom_point() +
labs(title = "Scatter plot of GOVT vs. INDEPENDENT")
```
### Scater plot for GOVT AIDED vs KV
```{r}
ggplot(cls, aes(x = `GOVT.AIDED`, y = KV)) +
geom_point() +
labs(title = "Scatter plot of GOVT AIDED vs. KV")
```
### Scater plot for KV vs JNV INSITUTION
```{r}
ggplot(cls, aes(x = KV, y =JNV)) +
geom_point() +
labs(title = "Scatter plot of KV vs. JNV")
```
### Scater plot for GOVT vs INDEPENDENT
```{r}
ggplot(cls, aes(x = GOVT, y =INDEPENDENT)) +
geom_point() +
labs(title = "Scatter plot of GOVT vs. INDEPENDENT")
```
# Linear Regression
### Visualize the data: GOVT vs INDEPENDENT
```{r}
ggplot(cls, aes(x = GOVT, y =`GOVT.AIDED`)) +
geom_point(color = "blue") +
ggtitle("Scatter Plot of GOVT vs GOVT AIDED Insituttion") +
xlab("GOVT Schools") +
ylab("GOVT AIDED Insitution")
```
### Fit Linear Regression Model
```{r}
model <- lm(`GOVT.AIDED` ~ GOVT, data = cls)
summary(model)
predicted <- predict(model, cls)
```
# Evaluate the Model
### Mean Squared Error (MSE)
```{r}
mse <- mean((cls$`GOVT.AIDED` - predicted) ^ 2)
cat("Mean Squared Error (MSE):", mse, "\n")
```
### Root Mean Squared Error (RMSE)
```{r}
rmse <- sqrt(mse)
cat("Root Mean Squared Error (RMSE):", rmse, "\n")
```
# Visualize the regression line
```{r}
ggplot(cls, aes(x = GOVT, y = `GOVT.AIDED`)) +
geom_point(color = "blue") +
geom_smooth(method = "lm", color = "red") +
ggtitle("Linear Regression: GOVT vs INDEPENDENT Schools") +
xlab("GOVT Schools") +
ylab("INDEPENDENT Schools")
```