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:
credit_data = read.csv(("/Users/tbs/Downloads/Data Sets 'R'/credit_data.csv"))
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#Question 1 Response variable is the output or outcome being studies and modeled. It is the y-variable. Explanatory variables are the inputs or predictors that influence the response variable. They are the x-variable we use to explain changes in the response.
credit_data$Total_Debt <- credit_data$'Number.of.Existing.Loans' * credit_data$'Loan.Amount'
View(credit_data)
credit_data$Monthly_Payment <- credit_data$`Loan.Amount` / credit_data$`Loan.Tenure`
View(credit_data)
credit_data$Income_to_Loan_Ratio <- credit_data$Income / credit_data$`Loan.Amount`
View(credit_data)
Data_set_1 <- credit_data[, c('Total_Debt', 'Income', 'Credit.Score', 'LTV.Ratio')]
View(Data_set_1)
Data_set_2 <- credit_data[, c('Income_to_Loan_Ratio', 'Profile.Score', 'Credit.Score', 'Loan.Amount')]
View(Data_set_2)
Data_set_3 <- credit_data[, c('Monthly_Payment', 'LTV.Ratio', 'Credit.Score', 'Age')]
View(Data_set_3)
#Question 2:- Plot a visualization for each response-explanatory relationship, and draw some conclusions based on the plot Use what we’ve covered so far in class to scrutinize the plot (e.g., are there any outliers?
ggplot(Data_set_1, aes(x = Income, y = Total_Debt)) +
geom_point(aes(colour=Income) , size = 2) +
scale_color_gradient(low = "green", high = "orange")+
labs(x = "Income", y = "Total_Debt") +
ggtitle("Scatterplot of Income vs.Total_Debt ")
#Insight for Above plot (Income vs Total Debt):- 1) There appears to be
a moderate positive correlation between Income and Total Debt. As
individuals’ incomes increase, their total debts tend to increase as
well. This suggests that individuals with higher incomes may be more
likely to incur higher levels of debt. 2) There may be outliers in the
data where individuals with lower incomes have unexpectedly high total
debts. These outliers could indicate potential financial risk for those
borrowers, as they are carrying significant debt burdens relative to
their incomes.
ggplot(Data_set_2, aes(x = Profile.Score, y = Income_to_Loan_Ratio)) +
geom_point(aes(colour=Profile.Score) , size = 3) +
scale_color_gradient(low = "blue", high = "red")+
labs(x = "Profile.Score", y = "Income_to_Loan_Ratio") +
ggtitle("Scatterplot of Profile.Score vs.Income_to_Loan_Ratio ")
#Insight for Above plot (Profile.Score vs. Income_to_Loan_Ratio):- The
scatterplot shows Profile.Score vs. Income_to_Loan_Ratio with a color
gradient indicating different Profile.Score levels. There is no clear
linear trend, suggesting a weak linear correlation. Data points are
spread across various Profile.Score and Income_to_Loan_Ratio values, and
potential outliers exists.
ggplot(Data_set_3, aes(x = LTV.Ratio, y = Monthly_Payment)) +
geom_point(aes(colour=LTV.Ratio) , size = 2) +
scale_color_gradient(low = "red", high = "yellow")+
labs(x = "LTV.Ratio", y = "Monthly_Payment") +
ggtitle("Scatterplot of LTV vs.Total_Debt ")
#Insight for Above plot (LTV.Ratio and Monthly_Payment):- The
scatterplot illustrates the relationship between LTV.Ratio and
Monthly_Payment, using a color gradient to differentiate LTV.Ratio
values. There is no clear linear trend between these two variables,
indicating a weak linear correlation. Data points are spread across
various LTV.Ratio and Monthly_Payment values, with possible
outliers.
#Question 3:-
# Calculate the correlation coefficient
correlation_set_1 <- cor(Data_set_1$Income, Data_set_1$Total_Debt, use = "complete.obs")
# Interpret the correlation coefficient
cat("Correlation coefficient for Set 1 ( Income vs. Total_Debt):", correlation_set_1, "\n")
## Correlation coefficient for Set 1 ( Income vs. Total_Debt): 0.3595267
The correlation coefficient for Income vs. Total_Debt provides insight into the direction and strength of the linear relationship between these two variables. A positive correlation coefficient indicates that as Income increases, Total_Debt tends to increase as well. The closer the coefficient is to 1, the stronger the positive correlation.
# Calculate the correlation coefficient
correlation_set_2 <- cor(Data_set_2$Profile.Score, Data_set_2$Income_to_Loan_Ratio, use = "complete.obs")
# Interpret the correlation coefficient
cat("Correlation coefficient for Set 2 (Profile.Score vs. Income_to_Loan_Ratio):", correlation_set_2, "\n")
## Correlation coefficient for Set 2 (Profile.Score vs. Income_to_Loan_Ratio): 0.1143106
The correlation coefficient for Profile.Score vs. Income_to_Loan_Ratio reveals the strength and direction of the linear association between these variables. A positive coefficient suggests that as Profile.Score increases, Income_to_Loan_Ratio tends to increase. A coefficient closer to 1 indicates a stronger positive correlation.
# Calculate the correlation coefficient
correlation_set_3 <- cor(Data_set_3$LTV.Ratio, Data_set_3$Monthly_Payment, use = "complete.obs")
# Interpret the correlation coefficient
cat("Correlation coefficient for Set 3 (LTV.Ratio vs. Monthly_Payment):", correlation_set_3, "\n")
## Correlation coefficient for Set 3 (LTV.Ratio vs. Monthly_Payment): 0.1526242
The correlation coefficient for LTV.Ratio vs. Monthly_Payment informs about the linear relationship between these two variables. A positive coefficient implies that as LTV.Ratio increases, Monthly_Payment tends to increase. A coefficient closer to 1 signifies a stronger positive correlation.
#Question 4:-
# Sample dataset (replace with your actual dataset)
response_variable <-credit_data$Total_Debt
# Calculate sample mean and standard error
sample_mean <- mean(response_variable)
sample_sd <- sd(response_variable)
n <- length(response_variable)
z <- qnorm(0.975) # 95% confidence interval (two-tailed)
# Calculate confidence interval
margin_of_error <- z * (sample_sd / sqrt(n))
lower_bound <- sample_mean - margin_of_error
upper_bound <- sample_mean + margin_of_error
# Print the confidence interval
cat("95% Confidence Interval for Total_Debt:", "[", lower_bound, ",", upper_bound, "]\n")
## 95% Confidence Interval for Total_Debt: [ 506081.3 , 509034.3 ]
Interpretation: The 95% confidence interval for the population mean of ‘Total_Debt’ is provided as [ 506081.3 , 509034.3 ]. This means that we are 95% confident that the true population mean of ‘Total_Debt’ falls within this interval.
Conclusion:
Based on the confidence interval, you can conclude that you are 95% confident that the true average ‘Total_Debt’ for the population falls within the calculated range.
# Sample dataset (replace with your actual dataset)
response_variable <-credit_data$Income_to_Loan_Ratio
# Calculate sample mean and standard error
sample_mean <- mean(response_variable)
sample_sd <- sd(response_variable)
n <- length(response_variable)
z <- qnorm(0.975) # 95% confidence interval (two-tailed)
# Calculate confidence interval
margin_of_error <- z * (sample_sd / sqrt(n))
lower_bound <- sample_mean - margin_of_error
upper_bound <- sample_mean + margin_of_error
# Print the confidence interval
cat("95% Confidence Interval for Income_to_Loan_Ratio:", "[", lower_bound, ",", upper_bound, "]\n")
## 95% Confidence Interval for Income_to_Loan_Ratio: [ 0.7931107 , 0.7966303 ]
The 95% confidence interval for “Income_to_Loan_Ratio” suggests, with 95% confidence, that the true population mean of this variable falls within the interval [ 0.7931107 , 0.7966303]. This interval provides a range of likely values for the population mean, based on the sample data and associated uncertainty.
# Sample dataset (replace with your actual dataset)
response_variable <-credit_data$Monthly_Payment
# Calculate sample mean and standard error
sample_mean <- mean(response_variable)
sample_sd <- sd(response_variable)
n <- length(response_variable)
z <- qnorm(0.975) # 95% confidence interval (two-tailed)
# Calculate confidence interval
margin_of_error <- z * (sample_sd / sqrt(n))
lower_bound <- sample_mean - margin_of_error
upper_bound <- sample_mean + margin_of_error
# Print the confidence interval
cat("95% Confidence Interval for Monthly_Payment:", "[", lower_bound, ",", upper_bound, "]\n")
## 95% Confidence Interval for Monthly_Payment: [ 1489.035 , 1501.556 ]
The 95% confidence interval provides a range of values within which the true population mean is likely to fall with 95% confidence. Specifically:
The interval [ 1489.035 , 1501.556 ] represents the range of credit scores within which we can be reasonably confident that the true average credit score for the population lies.