Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. setwd("~/Desktop/Statistics")
  2. library(ggplot2)
  3. bostondata = read.csv("311_cases_exercise.csv")
  4.  
  5. #Most common request
  6. summary(bostondata$TYPE)
  7.  
  8. #Potholes
  9. potholes = bostondata[which(bostondata$TYPE=="Request for Pothole Repair"),]
  10. july2017potholes = potholes[which(substr(as.character(potholes$open_dt),6,7)=="07"),]
  11. length(july2017potholes)
  12.  
  13. #% of graffiti requests still open and overdue
  14. summary(bostondata$TYPE)
  15. graffiti = bostondata[which(bostondata$TYPE=="Graffiti Removal"),]
  16. openoverduegraffiti = graffiti[which(graffiti$CASE_STATUS == "Open" & graffiti$OnTime_Status == "OVERDUE"),]
  17. length(openoverduegraffiti$TYPE)/length(graffiti$TYPE)
  18.  
  19. #request most likely to have a submitted photo be in hyde park
  20. unique(bostondata$TYPE)
  21. dframe <-data.frame(matrix(0, ncol = length(unique(bostondata$TYPE)), nrow = 4))
  22. names(dframe) <- unique(bostondata$TYPE)
  23. hydeanalysis = dframe
  24. max = 0;
  25. for(index in 1:length(unique(bostondata$TYPE))) {
  26. #all in category
  27. hydeanalysis[1,index] = nrow(bostondata[which(bostondata$TYPE == unique(bostondata$TYPE)[index]),])
  28. #all that submitted a photo
  29. hydeanalysis[2,index] = nrow(bostondata[which(bostondata$TYPE == unique(bostondata$TYPE)[index] & (bostondata$SubmittedPhoto != "NULL")),])
  30. #all that submitted a photo AND is in hyde park
  31. hydeanalysis[3,index] = nrow(bostondata[which(bostondata$TYPE == unique(bostondata$TYPE)[index] & (bostondata$SubmittedPhoto != "NULL") & bostondata$neighborhood == "Hyde Park"),])
  32. #ratio of photos in hyde park
  33. hydeanalysis[4,index] = hydeanalysis[3,index]/hydeanalysis[2,index]
  34. if(!is.nan(hydeanalysis[4,index])) {
  35. if(hydeanalysis[4,index] > max) {
  36. max = hydeanalysis[4,index];
  37. }
  38. }
  39. }
  40. max
  41. colnames(hydeanalysis)[which(hydeanalysis[4,] == max)]
  42.  
  43. #Open Analysis of Boston data - responsiveness by district
  44. summary(bostondata$city_council_district)
  45. modifiedbostondata = bostondata[which((bostondata$city_council_district)%in%c(1:9)),]
  46. summary(modifiedbostondata$city_council_district)
  47. dframe <-data.frame(matrix(0, ncol = 10, nrow=9))
  48. colnames(dframe) <- c("DistrictNumber", "TotalRequests", "CitizensApp%", "WorkerApp%", "Call%", "Other%", "Open%", "Closed%","OntimeClosed%","LateClosed%")
  49. districtanalysis <- dframe;
  50. for(index in 1:9) {
  51. relevantdata = modifiedbostondata[which(modifiedbostondata$city_council_district == index),]
  52. dframe[index,1] = index;
  53. dframe[index,2] = nrow(relevantdata)
  54. dframe[index,3] = nrow(relevantdata[which(relevantdata$Source == "Citizens Connect App"),])/dframe[index,2]
  55. dframe[index,4] = nrow(relevantdata[which(relevantdata$Source == "City Worker App"),])/dframe[index,2]
  56. dframe[index,5] = nrow(relevantdata[which(relevantdata$Source == "Constituent Call"),])/dframe[index,2]
  57. dframe[index,6] = nrow(relevantdata[-which(relevantdata$Source%in%c("Citizens Connect App", "City Worker App","Constituent Call")),])/dframe[index,2]
  58. dframe[index,7] = nrow(relevantdata[which(relevantdata$CASE_STATUS == "Open"),])/dframe[index,2]
  59. dframe[index,8] = nrow(relevantdata[which(relevantdata$CASE_STATUS == "Closed"),])/dframe[index,2]
  60. dframe[index,9] = nrow(relevantdata[which(relevantdata$CASE_STATUS == "Closed" & relevantdata$OnTime_Status == "ONTIME"),])/nrow(relevantdata[which(relevantdata$CASE_STATUS == "Closed"),])
  61. dframe[index,10] = nrow(relevantdata[which(relevantdata$CASE_STATUS == "Closed" & relevantdata$OnTime_Status == "OVERDUE"),])/nrow(relevantdata[which(relevantdata$CASE_STATUS == "Closed"),])
  62. }
  63. print(dframe)
  64. ggplot(data=modifiedbostondata,aes(x= city_council_district, fill=Source)) + geom_bar(stat="count") + ggtitle("Constituent 311 Requests Analysis") + xlab("City district") + ylab("# Requests")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement