R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Loan <- read.csv("C:/Users/vj/Desktop/Loan.csv")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggthemes)
library(ggrepel)
library(broom)
library(lindia)
library(car)
## Loading required package: carData
## 
## Attaching package: 'car'
## 
## The following object is masked from 'package:dplyr':
## 
##     recode
## 
## The following object is masked from 'package:purrr':
## 
##     some
library(ggplot2)

Building a linear regression model for response variable Loan Amount and explanatory variables Income and Property value.

linear_model <- lm(loan_amount ~ income + property_value, data = Loan)


coef(linear_model)
##    (Intercept)         income property_value 
##   1.302058e+05   6.984195e+00   3.079428e-01
summary(linear_model)
## 
## Call:
## lm(formula = loan_amount ~ income + property_value, data = Loan)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1839918   -64793    -7505    64753   903870 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    1.302e+05  2.946e+03   44.20   <2e-16 ***
## income         6.984e+00  2.903e-01   24.06   <2e-16 ***
## property_value 3.079e-01  4.818e-03   63.91   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 118200 on 5614 degrees of freedom
## Multiple R-squared:  0.5602, Adjusted R-squared:   0.56 
## F-statistic:  3576 on 2 and 5614 DF,  p-value: < 2.2e-16

Interpreting the co-efficients:

(Intercept): The intercept represents the value of ‘loan_amount’ when both ‘income’ and ‘property_value’ are equal to zero. In this context, it might not have a direct practical interpretation since it’s highly unlikely for ‘income’ and ‘property_value’ to be zero in real-world scenarios.

income: The coefficient for ‘income’ is approximately 6.984195. This means that for each one-unit increase in ‘income,’ the ‘loan_amount’ is expected to increase by approximately 6.984195 units, assuming that ‘property_value’ remains constant. In other words, as ‘income’ increases, ‘loan_amount’ tends to increase by approximately 6.984195 units. The positive coefficient suggests a positive relationship between ‘income’ and ‘loan_amount.’

property_value: The coefficient for ‘property_value’ is approximately 0.3079428. This means that for each one-unit increase in ‘property_value,’ the ‘loan_amount’ is expected to increase by approximately 0.3079428 units, assuming that ‘income’ remains constant. In other words, as ‘property_value’ increases, ‘loan_amount’ tends to increase by approximately 0.3079428 units. The positive coefficient suggests a positive relationship between ‘property_value’ and ‘loan_amount.’

#Filtering my dataset with condition of Loantype = type2 to get more clear understanding of relationship between the variables.
new_dataset <- subset(Loan, loan_type == 'type2')

#Plotting scatter plot for Loan amount  
ggplot(new_dataset, aes(x = loan_amount, y = property_value)) +
  geom_point() +
  geom_smooth(method = 'lm', color = 'gray', linetype = 'dashed',
              se = FALSE) +
  geom_smooth(se = FALSE) +
  labs(y = "Property Value", x = "Loan Amount") + 
  ggtitle("Scatter Plot: Loan Amount vs. Property Value") +
  theme_classic()
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

The scatter plot shows that as ‘Property Value’ increases, ‘Loan Amount’ also tends to increase in a relatively linear manner. This suggests that there is a strong linear association between the two variables.

 ggplot(Loan, aes(x = loan_amount, y = income)) +
  geom_point() +
  geom_smooth(method = 'lm', color = 'gray', linetype = 'dashed',
              se = FALSE) +
  geom_smooth(se = FALSE) +
  labs(y = "income", x = "Loan Amount") + 
  ggtitle("Scatter Plot: Loan Amount vs. income")+
  theme_classic() 
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

The scatter plot shows that as ‘income’ increases, ‘Loan Amount’ also tends to increase in a relatively linear manner. This suggests that there is a strong linear association between the two variables.

plot(linear_model)

Interpreting the coefficients of Income

# Coefficients summary
coeff_summary <- summary(linear_model)

# Interpret the coefficient for 'income'
income_coeff <- coeff_summary$coefficients["income", "Estimate"]
p_value_income <- coeff_summary$coefficients["income", "Pr(>|t|)"]

cat("Coefficient for income: ", income_coeff, "\n")
## Coefficient for income:  6.984195
cat("p-value for income: ", p_value_income, "\n")
## p-value for income:  7.866248e-122

Coefficient for Income (6.984195): This means that, all else being equal, for each one-unit increase in the ‘income’ variable, the ‘loan_amount’ is expected to increase by approximately 6.984195 units. In my specific dataset, this suggests that as individuals’ income increases, the amount they are eligible to borrow as a loan also tends to increase. This relationship appears to be statistically significant.

P-value for Income (7.866248e-122): The extremely small p-value indicates that the coefficient for ‘income’ is highly statistically significant. In practical terms, this means that the relationship between ‘income’ and ‘loan_amount’ is not likely due to random chance. There is strong evidence to suggest that ‘income’ is an important predictor of ‘loan_amount’ in my model.