-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdesc_stats.Rmd
More file actions
64 lines (60 loc) · 1.89 KB
/
desc_stats.Rmd
File metadata and controls
64 lines (60 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---
title: "Descriptive statistics"
output:
pdf_document: default
html_notebook: default
---
```{r}
RM <- read.csv("finalData.csv",header=TRUE,sep = ";")
head(RM)
str(RM)
```
```{r}
library(lattice)
par(mfrow = c(2,2))
df <- unique(RM[c(6,8:17)])
df$DefaultedLoans <- as.numeric(df$DefaultedLoans)
head(df)
```
```{r}
var_list<- names(df)[2:11]
models <- lapply(var_list,
function(x)
{
mod = lm(substitute(DefaultedLoans ~ i, list(i = as.name(x))), data = df)
})
par(mfrow = c(2,2))
invisible(lapply(models,plot))
```
```{r}
library(ggplot2)
plots <- function(i){
ggplot(df, aes(x = df[i])) +
geom_histogram(aes(y = ..density..),colour = "black",
fill = "yellow",binwidth = 0.02) +
geom_density(alpha = 0.2, fill = "blue",linetype = "dashed") +
geom_vline(aes(xintercept=mean(df[i], na.rm = TRUE)),
color = "black",linetype = "dashed", size = 1) +
xlab(names(df)[i]) +
ggtitle(paste("Histogram plot of ",names(df)[i]))}
par(mfrow = c(2,2))
lapply(2:11,FUN = plots)
```
```{r}
library(s20x)
pairs(df,col="green",pch = 20)
pairs20x(df)
```
```{r}
library(stargazer)
library(doBy)
stargazer(df, type = "text", median = TRUE, digits = 2)
summaryBy(AddressLatitude ~ DefaultedLoans, data = RM, FUN = c(mean), na.rm =TRUE)
summaryBy(AddressLongitude ~ DefaultedLoans, data = RM, FUN = c(mean), na.rm =TRUE)
summaryBy(CreditRating ~ DefaultedLoans, data = RM, FUN = c(mean), na.rm =TRUE)
summaryBy(CreditRating ~ County, data = RM, FUN = c(mean), na.rm =TRUE)
```
```{r}
reg <- lm(df$DefaultedLoans~df$CreditRating+df$MortgageYears+df$CreditRatingMovement+df$LTV+df$LoanBalance+df$InterestIncome+df$PropertyValue+df$AnnualPYMT+df$AddressLatitude+df$AddressLongitude)
summary(reg)
```