Last active
December 17, 2015 08:09
-
-
Save fgregg/5578318 to your computer and use it in GitHub Desktop.
This file contains 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
# Read in the data | |
days <- read.csv('all_years.csv') | |
# Plot all the data | |
plot(total_count ~ temp_max, days, col=rgb(0,0,0, .3)) | |
# Fit a cubic polynomial to the data | |
m1 <- lm(total_count ~ temp_max + I(temp_max^2) + I(temp_max^3), days) | |
# Extract the coefficents | |
b_0 <- coef(m1)[1] | |
b_1 <- coef(m1)[2] | |
b_2 <- coef(m1)[3] | |
b_3 <- coef(m1)[4] | |
# Plot the curve | |
curve(b_0 + b_1*x + b_2*x^2 + b_3*x^3, | |
min(days$temp_max), | |
max(days$temp_max), | |
add=TRUE, | |
col="red") | |
# Output as a png | |
pdf("crime_vs_temp.png") | |
plot(total_count ~ temp_max, days, col=rgb(0,0,0, .3)) | |
curve(b_0 + b_1*x + b_2*x^2 + b_3*x^3, | |
min(days$temp_max), | |
max(days$temp_max), | |
add=TRUE, | |
col="red") | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The decline in crime at higher temperatures is much smaller.
Also notice that instead of one cloud of points it looks like there's two. This calls out for more investigation.