Author: Barnabás Piller
The data set used in this analysis originally contained information on roughly 670000 loans funded through the Kiva platform, but I have chosen to focus on only the 835 loans issued on January 31, 2017 to allow for more meaningful visualizations. Kiva is an international nonprofit organization that offers financial services to individuals in developing countries who otherwise would not have access to banking. Whether it is a farmer investing in new equipment, or someone trying to start their own business, they can apply for a microloan through Kiva. The loans are then financed with the help of crowdfunding, where people can lend as little as $25 to their beneficiary of choice.
The csv file containing the data has been uploaded to Kaggle by Kiva with the goal of inviting participants to help Kiva build models for assessing borrower welfare levels.
The data set originally contained 20 variables, but for the purpose of this analysis, I have decided to include the following:
The variables id, loan_amount, term_in_months, and lender_count are numeric, date is a date, and the variables sector, country, and currency are factors.
I start off by importing the data into R and making the necessary adjustments:
kiva <- read.csv("C:/WU/BBE/Sixth Semester/Applied Data Analysis with R/Homework 1/Kiva/kiva_loans.csv", header = T, sep = ",")
kiva <- kiva[,-c(2,4,6,7,9,11,12,13,14,17,18,19)]
kiva$date <- as.Date(kiva$date)
kiva <- kiva %>% filter(format(kiva$date, "%Y-%m-%d") == "2017-01-31") # dplyr
kiva$country <- as.factor(kiva$country)
kiva$sector <- as.factor(kiva$sector)
kiva$currency <- as.factor(kiva$currency)
Next, let us have a preview of the data set:
head(kiva)
## id loan_amount sector country currency term_in_months
## 1 1229662 575 Agriculture Kenya KES 11
## 2 1230022 500 Education Kenya KES 39
## 3 1229994 1450 Food Bolivia BOB 27
## 4 1229565 500 Clothing Kenya KES 8
## 5 1229466 225 Food Philippines PHP 8
## 6 1229583 250 Food Philippines PHP 11
## lender_count date
## 1 19 2017-01-31
## 2 20 2017-01-31
## 3 46 2017-01-31
## 4 5 2017-01-31
## 5 2 2017-01-31
## 6 6 2017-01-31
The descriptive statistics for the numeric variables are calculated using the describe() function from the psych package:
describe(kiva[,-c(1,3,4,5,8)])
## vars n mean sd median trimmed mad min max range skew
## loan_amount 1 835 686.32 829.17 500 516.70 407.71 100 8000 7900 3.86
## term_in_months 2 835 14.83 8.89 14 13.07 4.45 5 93 88 3.38
## lender_count 3 835 16.20 20.97 11 12.10 8.90 0 212 212 4.63
## kurtosis se
## loan_amount 19.79 28.69
## term_in_months 17.95 0.31
## lender_count 30.39 0.73
In the table above, we can see many interesting things about our data. For instance, the average size of the loans financed through Kiva is $686.32. Furthermore, the maximum number of lenders that have contributed to a single loan is 212. Lastly, the standard deviation of the term structure of the loans in months is 8.89, which means approximately 68.27% of the loans were disbursed for a duration between 5.94 and 23.72 months.
To examine the categorical variables in our data, we can use the table() function:
table(kiva$sector)
##
## Agriculture Arts Clothing Construction Education
## 251 25 32 11 70
## Entertainment Food Health Housing Manufacturing
## 2 172 10 25 9
## Personal Use Retail Services Transportation Wholesale
## 54 108 47 16 3
The most popular sector among the people looking for loans on Kiva seems to be agriculture, while only two borrowers operate in the entertainment sector.
table(kiva$country)
##
## Armenia Bolivia
## 10 2
## Brazil Burkina Faso
## 1 4
## Cambodia Cameroon
## 55 4
## Colombia Costa Rica
## 1 1
## Ecuador Egypt
## 43 19
## El Salvador Guatemala
## 66 21
## Honduras India
## 22 43
## Indonesia Israel
## 12 2
## Jordan Kenya
## 5 138
## Kosovo Kyrgyzstan
## 6 7
## Lebanon Liberia
## 1 14
## Madagascar Mali
## 8 13
## Moldova Myanmar (Burma)
## 1 19
## Nicaragua Pakistan
## 4 24
## Palestine Paraguay
## 17 4
## Peru Philippines
## 2 155
## Rwanda Sierra Leone
## 3 4
## Tajikistan Tanzania
## 43 14
## The Democratic Republic of the Congo Togo
## 5 12
## Turkey Uganda
## 2 12
## United States Yemen
## 8 3
## Zambia Zimbabwe
## 1 4
max(table(kiva$country))
## [1] 155
After a quick glance, we can see that the highest number of loans has been disbursed to people located in the Philippines, followed by Kenya and El Salvador.
table(kiva$currency)
##
## AMD BOB BRL COP CRC EGP EUR GTQ HNL IDR ILS INR JOD KES KGS KHR LBP LRD MDL MGA
## 10 2 1 1 1 19 6 21 22 12 2 43 5 138 5 53 1 14 1 8
## MMK NIO PEN PHP PKR PYG RWF SLL TJS TRY TZS UGX USD XAF XOF YER ZMW
## 19 4 2 155 24 4 3 4 43 2 14 12 147 4 29 3 1
max(table(kiva$currency))
## [1] 155
The most popular currency for the disbursement of loans has been the Philippine peso (PHP), followed by the United States Dollar (USD) and the Kenyan Shilling (KES).
In this last section, my goal is to investigate the relationships of the variables using plotting functions.
First, I draw a scatterplot using the ‘car’ package to examine the relationship of the loan amounts and the number of lenders:
scatterplot(y = kiva$loan_amount, x = kiva$lender_count,
ylab = "Loan amount ($)", xlab = "Lender count", smooth = F,
pch = 16)
As we can see from the fitted regression line, there is a positive relationship between the two variables. The box plots also reveal that both variables are heavily skewed to the right.
Next, the relationship of the loan amount and the term duration is investigated:
scatterplot(y = kiva$loan_amount, x = kiva$term_in_months,
ylab = "Loan amount ($)", xlab = "Term duration in months", smooth = F, pch = 16)
In this case, there appears to be only a slight positive correlation between the amount of the loan and the duration for which it is disbursed.
Lastly, I will examine the sizes of the loans in the different sectors in which the borrowers operate:
ggplot(kiva, aes(x = sector, y = loan_amount, fill = sector)) +
geom_boxplot() +
scale_x_discrete(guide = guide_axis(n.dodge=3)) +
labs(x = "Sector", y = "Loan amount ($)", title = "Size of loans by sector") +
theme_minimal() +
theme(legend.position = "none",
plot.title = element_text(face = "bold", size = 18),
axis.title = element_text(size = 12))
It can be observed that the largest loan of $8000 went to the agricultural sector, while the highest median amount was in the entertainment sector. As expected, loans provided for personal use seem to be the smallest in size.