Solution Manual For Modern Business Analytics, 1st Edition Matt Taddy and Leslie Hendrix and Matthew Harding Chapter 1-9
Chapter 1 Regression Problem 1.1 For this problem set, we will use 13,103 observations of hourly counts from 2011 to 2012 for bike rides (rentals) from the Capital Bikeshare system in Washington DC. The data are recorded for hours after 6am every day. (We omit earlier hours for convenience since they often include zero ride counts.) This dataset is adapted from data originally compiled by Fanaee and Gama in ‗Event labeling combining ensemble detectors and background knowledge‘ (2013). This data can be used for modeling system usage (ride counts). Such usage modeling is a key input for operational planning. bikeshare.csv contains:
dteday: date mnth: month (1 to 12) holiday: whether day is holiday or not weekday: day of the week, counting from 0:sunday. workingday: if day is either weekend or holiday is 0, otherwise is 1. weathersit: broad overall weather summary (clear, cloudy, wet) temp: Temperature, measured in Celsius hum: Humidity % windspeed: Wind speed, measured in km per hour cnt: count of total bike rentals that day
<bikeshare.csv> <bikeshareReadme.txt> Read the bikeshare.csv data into R. Plot the marginal distribution for the count of bike rentals and the conditional count distribution given the broad weather situation (weathersit).
a-1. Use a histogram to plot the marginal distribution for the count of bike rentals. What is the shape of the distribution? a. skewed left b. fairly symmetric
© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.
c. skewed right
Explanation/Solution The following code draws a histogram plotting the marginal distribution for the count of bike rentals: biketab <- read.csv("bikeshare.csv", strings=T) hist(biketab$cnt, xlab="daily ride count", freq=FALSE, main="")
a-2. If you haven‘t already, read the bikeshare.csv data into R and make sure to use the strings=T argument in the read.csv function Create side-by-side boxplots to show the conditional count distribution, given the broad weather situation (weathersit). What does the side-by-side boxplot look like? (The top image is correct.)
a.
© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.
b.
c. Explanation/Solution The following code draws side-by-side boxplots showing the conditional count distribution, given the broad weather situation: biketab <- read.csv("bikeshare.csv", strings=T) boxplot(cnt ~ weathersit, data = biketab, xlab="weather situation", ylab="daily ride count")
Problem 1.2 Read the bikeshare.csv data into R and make sure to use the strings=T argument in the read.csv function. Fit a regression for ride count as a function of the weather situation variable to answer the following questions. a. On wet days, is the expected ride count higher or lower compared to clear days?
© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.
On wet days, the expected ride count is lower by 3,073.5 +/-0.1
b. What is the SSE? 2467890819 (+/-1)
c. What is the R2? R2=0.1 (+/-0.01)
d. What is the estimate of the standard deviation of the residual errors? 1841 (+/-1) Explanation/Solution biketab <- read.csv("bikeshare.csv", strings=T) #read data in and make categorical variables factors using strings=T argument class(biketab$weathersit) #check to be sure weathersit is a factor [1] "factor"
If the result of the above says "character" instead of "factor" then use the code below to make weathersit a factor: biketab$weathersit <- factor(biketab$weathersit) levels(biketab$weathersit) [1] "clear" "cloudy" "wet"
Next, use GLM to regress the counts onto the weather situation variable. wsfit <- glm(cnt ~ weathersit, data=biketab) summary(wsfit) Call: glm(formula = cnt ~ weathersit, data = biketab) Deviance Residuals: Min 1Q −4445.8 −1254.8
Median −14.8
3Q 1400.7
Max 4326.1
Coefficients: Estimate Standard Error t value Pr(>|t|) (Intercept) 4876.79 85.57 56.994 < 2e-16 *** weathersitcloudy -840.92 145.07 -5.797 1.01e-08 ***
© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.
weathersitwet
Estimate Standard Error t value Pr(>|t|) -3073.50 410.79 -7.482 2.12e-13 ***
Significance codes:
0 „***‟ 0.001 „**‟ 0.01 „*‟ 0.05 „.‟ 0.1 „ ‟ 1
(Dispersion parameter for gaussian family taken to be 3389960) Null deviance: 2739535392 on 730 degrees of freedom Residual deviance: 2467890819 on 728 degrees of freedom AIC: 13071 Number of Fisher Scoring iterations: 2
a. We see that `weather situation ―clear‖ is the reference level, with an expected ride count of 4877 rides per hour. Wet days have an expected 3073.5 fewer rides per hour, so the expected ride count is lower. b. From the summary.glm output, the SSE is 2467890819. c. 1 - wsfit$deviance/wsfit$null.deviance d. The residual error variance is 3389960 (the ―dispersion parameter‖) so the standard error is around 1841. sqrt(wsfit$deviance/wsfit$df.residual)
Problem 1.3 If you haven‘t already, read the bikeshare.csv data into R and make sure to use the strings=T argument in the read.csv function. Run a linear regression using ride counts as the response and model the response from the weather variables weathersit, temp, hum, and windspeed.
For each 10-degree increase in the temperature, we expect ride count to increase/decrease by about 1560 (+/-1) Explanation/Solution biketab <- read.csv("bikeshare.csv", strings=T) #read data in and make categorical variables factors using strings=T argument
ridefit <- glm(cnt ~ weathersit + temp + hum + windspeed, data=biketab) coef(ridefit) (Intercept) weathersitcloudy
weathersitwet
3434.91953
-287.24322
-1824.47164
temp
hum
windspeed
© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.
155.97949
-19.05618
-58.97232
The coefficient on temp is 155.97949, and so a 10-degree increase in temperature corresponds to around 1560 expected extra rides per day.
Problem 1-4. If you haven‘t already, read the bikeshare.csv data into R and make sure to use the strings=T argument in the read.csv function. Run 2 separate regressions, one linear using ride counts as the response and another using log ride counts as the response. For both regressions, model the response from the weather variables weathersit, temp, hum, and windspeed, but add interactions between the continuous weather variables and the weathersit factor. a. Using the results from your linear regression, for each weather situation, determine the change in expected ride count per 10-degree increase in temperature. Use the following table to record your answers. Note: Round your answers to 3 decimal places. Weather Situation
Clear Cloudy Wet
Expected Change in Ride Count per 10-Degree Increase in Temperature 1481.851 (+/-0.1) 1780.467 (+/-0.1) 991.2182 (+/-0.1)
b. Now use the results of your log-linear regression to find the change in expected log ride count per 10-degree increase in temperature. Use the following table to record your answers. Note: Round your answers to 3 decimal places. Weather Situation Expected Change in Log Ride Count per 10-Degree Increase in Temperature Clear 1.502818 (+/-0.01) Cloudy 1.715866 (+/-0.01) Wet 1.424282 (+/-0.01) c. What is an advantage of the log model over the linear model? a. The log model will never predict a value lower than 0. b. Log models always make more accurate predictions. c. The linear model‘s predictions are interpreted as multiplicative effects.
© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.
d. The estimates from a log model are not biased. d. Plot the residuals from the linear and log models. Note that in the fitted object, the residuals are access as residuals and the fitted values as fitted.values. In this way, the fitted values from rideshare2 are ridefit2$fitted.values. Which of the following shows the plot from the log model? (The top image is correct.)
a.
b.
© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.
e. Using the residual plots for the linear and log ride count models, which model is overestimating ride counts on days when ride count is high? a. Both b. Neither c. Log model d. Linear model f. Find the predicted ride count for a clear, 25-degree day with 50% humidity and 5kmh winds using the linear and log-linear models. Use the following table to record your answers for each model. Note: Round your answers to 3 decimal places. Model
Expected Log Ride Count per 10Degree Increase in Temperature 5624.027 (+/-1) 5839.927 (+/-1)
Log Linear Explanation/Solution
biketab <- read.csv("bikeshare.csv", strings=T) #read data in and make categorical variables factors using strings=T argument
a. ridefit2 <- glm(cnt ~ weathersit*(temp + hum + windspeed), data=biketab) coef(ridefit2) (Intercept)
weathersitcloudy
2800.249154
1626.013771
weathersitwet
temp
-1931.128533
148.185109
hum
windspeed
-9.361672
-39.373256
weathersitcloudy:temp
weathersitwet:temp
29.861582
-49.063285
weathersitcloudy:hum
weathersitwet:hum
-28.504855
13.886794
weathersitcloudy:windspeed
weathersitwet:windspeed
-46.717599
-34.933447
© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.