This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get Montgomery County geocode first to get the map for it | |
montgomery_county_gc <- geocode("Montgomery County, MD") | |
# Now, get the actual map | |
montgomery_county_map <- get_map(location = c(montgomery_county_gc$lon, montgomery_county_gc$lat)) | |
# Showing shades of colors using an abs function | |
alldata$circadian <- abs(alldata$hour_of_day - 12) | |
# Using default colors | |
ggmap(montgomery_county_map) + geom_point(data=sampledata, aes(longitude, latitude, color=circadian)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get Montgomery County geocode first to get the map for it | |
45 montgomery_county_gc <- geocode("Montgomery County, MD") | |
46 | |
47 # Now, get the actual map | |
48 montgomery_county_map <- get_map(location = c(montgomery_county_gc$lon, montgomery_county_gc$lat)) | |
49 | |
50 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
execute sp_execute_external_script | |
@language = N'R', | |
@script = N' | |
OutputDataSet <- InputDataSet; | |
inputData <- InputDataSet; | |
names(inputData) <- tolower(names(inputData)); | |
resultTree <- violation_count_tree <- rxDTree(violations ~ commercial_vehicle + alcohol + work_zone + state + | |
vehicletype + year + make + model + color + race + gender + | |
driver_city + driver_state + drivers_license_state + | |
month_of_year + day_of_week + hour_of_day, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The ctree from the party library did not finish at all! | |
cran_violation_count_tree <- ctree(data=rxViolations, formula=violations ~ commercial_vehicle + alcohol + work_zone + state + | |
vehicletype + year + make + model + color + race + gender + | |
driver_city + driver_state + drivers_license_state + | |
month_of_year + day_of_week + hour_of_day) | |
# I was pleasantly surprised that the rxDTree function finished in slightly less than 60 seconds | |
violation_count_tree <- rxDTree(violations ~ commercial_vehicle + alcohol + work_zone + state + | |
vehicletype + year + make + model + color + race + gender + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bymonth <- sqldf("select num_month_of_year, sum(frequency) as frequency from res group by num_month_of_year") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
res <- sqlQuery(conn, "select [Date Of Stop] as date_of_stop, num_month_of_year, num_day_of_week, hour_of_day, count([Date Of Stop]) as frequency from Montgomery_County_MD_Traffic_Violations group by [Date Of Stop], num_month_of_year, num_day_of_week, hour_of_day order by [Date Of Stop]") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
res <- sqlQuery(conn, "select [Date Of Stop] as date_of_stop, num_month_of_year, num_day_of_week, hour_of_day, count([Date Of Stop]) as frequency from Montgomery_County_MD_Traffic_Violations group by [Date Of Stop], num_month_of_year, num_day_of_week, hour_of_day order by [Date Of Stop]") |