HW5
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.
I believe that linear regression could be used to predict home buying trends. Predictors that can be used
are: average sales in the last 3 years, the average age of the buyer, first time home owners, home size, and
by average income. We could use these predictors to project what home buying trends will be like in the
next 12 months.
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 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.
Answer:
set.seed(1)
data <- read.delim("~/Desktop/data 2.2 2/uscrime.txt", header=TRUE)
head(data)
## M So Ed Po1 Po2 LF M.F Pop NW U1 U2 Wealth Ineq Prob
## 1 15.1 1 9.1 5.8 5.6 0.510 95.0 33 30.1 0.108 4.1 3940 26.1 0.084602
## 2 14.3 0 11.3 10.3 9.5 0.583 101.2 13 10.2 0.096 3.6 5570 19.4 0.029599
## 3 14.2 1 8.9 4.5 4.4 0.533 96.9 18 21.9 0.094 3.3 3180 25.0 0.083401
## 4 13.6 0 12.1 14.9 14.1 0.577 99.4 157 8.0 0.102 3.9 6730 16.7 0.015801
## 5 14.1 0 12.1 10.9 10.1 0.591 98.5 18 3.0 0.091 2.0 5780 17.4 0.041399
## 6 12.1 0 11.0 11.8 11.5 0.547 96.4 25 4.4 0.084 2.9 6890 12.6 0.034201
## Time Crime
## 1 26.2011 791
## 2 25.2999 1635
## 3 24.3006 578
## 4 29.9012 1969
## 5 21.2998 1234
## 6 20.9995 682
Fist model fits the entire data set
1