Skip to content

Instantly share code, notes, and snippets.

@rshyam1
Created May 1, 2016 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rshyam1/1c841264a26708d32ebd66b7c7df594a to your computer and use it in GitHub Desktop.
Save rshyam1/1c841264a26708d32ebd66b7c7df594a to your computer and use it in GitHub Desktop.
##Calculating monthly default rate from April 2005 to September 2005
default_rate=vector(length=6)
names(default_rate)= c("April 2005","May 2005","June 2005","July 2005","August 2005","September 2005")
c("April 2005","May 2005","June 2005","July 2005","August 2005","September 2005")
default_rate[6]= percent(nrow(filter(credi_tbl_temp,PAY_0 > 2 ))/total_rows)
default_rate[5]= percent(nrow(filter(credi_tbl_temp,PAY_2 > 2 ))/total_rows)
default_rate[4]= percent(nrow(filter(credi_tbl_temp,PAY_3 > 2 ))/total_rows)
default_rate[3]= percent(nrow(filter(credi_tbl_temp,PAY_4 > 2 ))/total_rows)
default_rate[2]= percent(nrow(filter(credi_tbl_temp,PAY_5 > 2 ))/total_rows)
default_rate[1]= percent(nrow(filter(credi_tbl_temp,PAY_6 > 2 ))/total_rows)
#Separating months names
months_name=names(default_rate)
names(default_rate)= c("04-2005","05-2005","06-2005","07-2005","08-2005","09-2005")
#c("April 2005","May 2005","June 2005","July 2005","August 2005","September 2005")
# Plot of Default(rate)=default > 60 days vs months
data_rate = data.frame(months=months_name, default_rate=default_rate)
d=ggplot(data=data_rate,aes(x=months, y=default_rate))
d1=d+geom_point()+ggtitle("Default rate(default payment > 2 months) Vs. Months")+
xlab("Months")+ylab("Default Rate")
d1
d2=d1+geom_point()+geom_line()
d2
d3=ggplot(data=data_rate,aes(x=months, y=default_rate))+ geom_smooth(aes( se = FALSE))
d3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment