Real World (Almost) Regression
Real World Regression
Preface
This is a “real world” example of a regression analysis, from beginning to end. Generally, write-ups will look something like this for papers, theses, dissertations, etc. (though those will often be longer). I’m doing this both because I think it’s easier to see what analysis “looks like” when someone actually engages in it, but also to provide a sort of “template” for your write ups. I’m doing some (as little as possible) fancy coding to get tables to come out well, and while you may need to use it for this class for clarity’s sake, you’ll probably build most of your tables in Excel or Word when you’re doing your own writing (unless you end up liking R!).
I’m going beyond what I’ve covered so far in class in this, so you’re going to run into concepts that are unfamiliar. Don’t worry so much about it, though I’ve tried to explain what I’m doing in-text. Additionally, there are things that are not covered here, which we will use when we do multiple regression (e.g. F-tests). Some write-up examples will include this information (and it’s good practice), but I wanted to draw your attention to the interpretation we’re interested in for bi-variate regression. We will get to multiple regression next.
Introduction
This is an analysis examining the question of the impact of assaults on homicides within neighborhoods in Toronto, Canada. The data were retreived from https://opendata.arcgis.com/datasets/af500b5abb7240399853b35a2362d0c0_0.csv?outSR=%7B%22latestWkid%22%3A26717%2C%22wkid%22%3A26717%7D, and imported directly into R. The dataset includes not only information on homicide and assault from 2014-2019, but also on a variety of other crime types. For purposes of this analysis, the variables of interest are Assault_AVG and Homicide_AVG, which are the average rates of the respective crimes across all years - by neighborhood within Toronto (n = 140). A table with descriptive statistics for the relevant variables is below.
| Homicide_AVG | Assault_AVG | |
|---|---|---|
| Min. :0.0000 | Min. : 18.50 | |
| 1st Qu.:0.2000 | 1st Qu.: 59.42 | |
| Median :0.3000 | Median : 96.50 | |
| Mean :0.5136 | Mean :132.65 | |
| 3rd Qu.:0.7250 | 3rd Qu.:160.20 | |
| Max. :2.5000 | Max. :851.80 |
As we can see in the table above, the mean rate of homicide is relatively low (\(\bar{x} = .51\)) across neighborhoods. We can see that the mean rate of assault is also reasonably low (\(\bar{x} = 132.65\)), though quite a bit higher than for homicide. The range of each variable is telling, with homicides ranging from 0 to 2.5 and assaults ranging from 18.5 to 851. These can be seen in the histograms, below.
Both variables have a negative skew, with most neighborhoods having lower levels of assault and homicide. While neither is normally distributed, this is not of significant concern because of the number of cases available for analysis (n = 140).
Examining the correlation between the two variables in the plot below, it seems there is a strong positive relationship, particularly in areas with less than 400 assaults.
Statistical Methods
While correlation tests can be important for understanding the relationship between homicides and assaults, bi-variate regression can give us similar information with additional granularity. Moreover, we can estimate what the average levels of homicides may be for a specific level of assault. This will allow us to not only predict levels of homicde, but also to determine how accurate our estimates of homicide levels are within this dataset.
The model is straightforward: \(homicide = intercept + \beta(assaults)\)
| Dependent variable: | |
| Homicides | |
| Assault_AVG | 0.003*** (0.0003) |
| Constant | 0.178*** (0.049) |
| Observations | 140 |
| R2 | 0.397 |
| Adjusted R2 | 0.392 |
| Residual Std. Error | 0.404 (df = 138) |
| F Statistic | 90.696*** (df = 1; 138) |
| Note: | p<0.1; p<0.05; p<0.01 |
Examining the model output in Table 2, above, we can see that the Assault_AVG is statistically significant (\(p\) < .000). This indicates that there is a statistically significant relationship between assaults and homicides within neighborhoods. Additionally, we can see that there is an increase of .003 homicides for each additional assault. While small, given the low average number of homicides within neighborhoods, it is clear that this relationship is real. Additionally, with an \(Adj. R^2\) of .392, it is clear that the relationship is moderately strong with 39% of homicide being explained by the level of assault within neighborhoods.
Prediction
While understanding the relationship between assaults and homicides within neighborhoods is important, being able to estimate the level of homicide given a level of assault can eb helpful for planning. For instance, what might we expect if the level of assaults was 1000 (~ 200 over the current high)? Regression allows us to make this estimation:
\(\hat{homicide} = .1781410 + .0025288(1000)\)
## [1] "With assault levels at 1000, the predicted level of homicide is 2.70689713414363"
From here we can see that with 1000 assaults, we would see that homicides would likely be roughly 2.7, which would exceed the highest current level (as expected.) We can get a sense of this by visualizing the relationship between the variables (as we did above) and including the regression line.
Based on the trajectory of the line, we can see that our estimate is consistent with what we would expect if assaults moved to 1000.
Checking the model
In addition to predicting, however, we can also see how well our model performs based on a full set of predictions. More specifically, since we have developed the model, we can predict for each actual value of assaults, and then compare that with the observed value. The difference between these two (the predicted and observed values of \(\hat{y}\)), is one of the ways we can get a sense of how much error is in the model. This, in turn, can be vizualized using a qqplot.
If our model predicted perfectly, all of the points would fall directly on the line - there would be no error (the line represents the 0-point across both axes). As it stands, there is error in the model, though it is not terrible, given the non-normality of the variables. Additionally, because regression is robust to violation of its assumptions, this is not of particular concern.
In the figure above, we have a second way to check on our model’s accuracy. This is a plot of the predicted values of \(\hat{y}\) (in this case homicide) against the “residuals” from the regression (which is the distances from the regression line for each point). In a world in which the model fit perfectly, we would see a completely random distribution of points around 0. As it stands, we see them clustering towards the bottom of the predicted values - which again is not surprising. This suggests we may have an issue with another model assumption - homoskedasticity. Again however, regression is generally robust, and given the low numbers of values on the right hand side of the graph, it looks like the problem is not widespread.
Additional Tests
While the above gives some information in terms of both model accuracy and predictive value, there are other tests that can be examined. For instance, we could look at the outliers and examine whether they’re driving parts of the analysis. Along the same lines, we can look for influential cases. These are important in full analyses, but given the constraints of this particular analysis, the above seems sufficient to justify the overall model results.
Conclusion
From the above analysis, it is clear that there is a strong, positive relationship between assaults and homicides within neighborhoods. Additionally, about 39% of the variation across neighborhoods in terms of homicides can be explained by assault. This could have policy implications in that if assaults are successfully addressed, it may have a positive impact on the rate of homicides within neighborhoods. Moreover, if there are increases in assaults within neigborhoods, there is a predicted increase of homicides, allowing the estimations of homicide levels - perhaps ahead of their arrival.
Comments
Post a Comment