AM Regression
Question 8.1
Describe a situation or problem from your job, everyday life, current events, etc., for which a linear
regression model would be appropriate. List some (up to 5) predictors that you might use.
Solution:
I have a little company that sells pipe hookah tobacco and we can use a linear regression model to
understand the correlation between the amount of money we spend for advertising and revenue. We
can fit a simple linear regression model with one predictor variable – Ads spending and the revenue as
the response variable.
We are using the ads spending as predictor because that is the effect we want to study; but in general,
revenue can have many other predictors such as price, number of competitors, unemployment rate.
Question 8.2
Using crime data from http://www.statsci.org/data/general/uscrime.txt (file uscrime.txt, description at
http://www.statsci.org/data/general/uscrime.html ), use regression (a useful R function is lm or glm)
to predict the observed crime rate in a city with the following data:
M = 14.0
So = 0
Ed = 10.0
Po1 = 12.0
Po2 = 15.5
LF = 0.640
M.F = 94.0
Pop = 150
NW = 1.1
U1 = 0.120
U2 = 3.6
Wealth = 3200
Ineq = 20.1
Prob = 0.04
Time = 39.0
about:bl 1
, 10/15/24, 9:18 Homew ork 5 - Basic
AM Regression
Show your model (factors used and their coefficients), the software output, and the quality of fit.
Note that because there are only 47 data points and 15 predictors, you’ll probably notice some
overfitting. We’ll see ways of dealing with this sort of problem later in the course.
Solution:
To approach this problem, we first fitted a regression model (Model1) using all the 47 data
points. Since we have a small data set, we decided not to split the data into train-test.
After we fitted and analyzed “Model1” output, we noted that predictors like “Mean years of schooling
of the population aged 25 years or over”(Ed) and “Income inequality: percentage of families earning
below half the median income”(Ineq) have less impact on the model since their coefficients are below
or equal to 0.001. So, we decided to create another model (Model2) without “Ed” and “Ineq” predictors
to see if we get a better-quality model.
However, after computing and comparing the sum of squared error for both models, we found that
“Model1” has the least sum of squared error - Model1 sum of squared error= 1354946, Model2 sum of
squared error= 2038089. Also looking at the Adjusted R-squared values, we see that “Model1” has
greater R-squared (which mean that Model1 accounted more for the variability in the data).
So, in sum, we ended up working with “Model1” to predict the test city crime based on data
provided above and we got a crime rate of 155 per 100000 population.
Below is the output details of Model1:
lm(formula = Crime ~ ., data = uscrimeData)
Residuals:
Min 1Q Median 3Q Max
-395.74 -98.09 -6.69 112.99 512.67
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -5.984e+03 M 1.628e+03 -3.675 0.000893 ***
4.171e+01 2.106 0.043443 *
8.783e+01 1.488e+02 -0.026 0.979765
So -3.803e+00
Ed 6.209e+01 3.033 0.004861 **
1.883e+02
Po1 1.061e+02 1.817 0.078892 .
1.175e+02 -0.931 0.358830
1.928e+02 1.470e+03 -0.452 0.654654
Po2 -1.094e+02 2.035e+01 0.855 0.398995
LF -6.638e+02
M.F
1.741e+01
Pop -7.330e-01 1.290e+00 -0.568 0.573845
NW 6.481e+00 0.649 0.521279
4.210e+03 -1.384 0.176238
4.204e+00 8.234e+01 2.038 0.050161 .
U1 -5.827e+03
U2
1.678e+02
Wealth 9.617e-02 1.037e-01 0.928 0.360754
Ineq 7.067e+0 2.272e+01 3.111 0.003983 **
1
Prob -4.855e+03 2.272e+03 -2.137 0.040627 *
Time -3.479e+00 7.165e+00 -0.486 0.630708
about:bl 2