Need only R-code Problem 1. (40 points) This exercise consists of a complete set
ID: 3251597 • Letter: N
Question
Need only R-code
Problem 1. (40 points) This exercise consists of a complete set of data analysis steps using linear regression modeling implemented on the Cars93 dataset. The main problem of interest is to find the predictors for fuel efficiency of cars. This dataset is a part of the DAAG package that needs to be installed using the command, install.packages(“DAAG”) in R and loaded by the command, library(DAAG).
1) (5 points) Create the variable of interest by averaging the MPG city and MPG highway.
2) (5 points) In this step we start the model-building method of forward selection/ backward elimination of covariates. Begin fitting the models one covariate at the time (forward selection).
3) (5 points) Begin building the multivariate model by keeping the most significant covariate from step 2 and adding a second covariate one at a time (forward selection).
4) (5 points) If the covariate from step 3 attenuates the significance of the initially selected covariate from step 2, the latter covariate is removed from the model (backward elimination). If not, keep both variables in the model and continue with next.
5) (5 points) Repeat steps 2, 3 and 4 until the set of variables is exhausted.
6) (5 points) By now we have all the significant main effects into the model. Begin adding all meaningful 2-way interactions (there are many possible ones).
7) (5 points) Use the R-squared, adjusted R-squared statistics and all graphing diagnostic/goodness-of-fit tools to assess the appropriateness of the selected model.
8) (5 points) Write a hypothetical methods and results sections of a paper titled “Predictors of the fuel efficiency of cars”.
Explanation / Answer
I give the r command
library(MASS)
y=Cars93
y1=y[,7]
y2=y[,8]
ay=(y1+y2)/2
Z=y[,4:22]
A<- lm (ay~., data=Z)
step(A, data=Cars93, direction="both")
> step(A, data=Z, direction="both")
Start: AIC=-5344.34
ay ~ MPG.city + MPG.highway + AirBags + DriveTrain + Cylinders +
EngineSize + Horsepower + RPM + Rev.per.mile + Man.trans.avail +
Fuel.tank.capacity + Passengers + Length + Wheelbase + Width +
Turn.circle + Rear.seat.room + Luggage.room + Weight
Df Sum of Sq RSS AIC
- Cylinders 4 0.000 0.000 -5351.7
- DriveTrain 2 0.000 0.000 -5347.3
- Wheelbase 1 0.000 0.000 -5346.3
- Luggage.room 1 0.000 0.000 -5346.3
- Man.trans.avail 1 0.000 0.000 -5346.3
- Horsepower 1 0.000 0.000 -5346.2
- EngineSize 1 0.000 0.000 -5346.1
- Rear.seat.room 1 0.000 0.000 -5346.0
- Weight 1 0.000 0.000 -5345.4
- Length 1 0.000 0.000 -5345.2
- Turn.circle 1 0.000 0.000 -5345.1
- Width 1 0.000 0.000 -5344.5
- Passengers 1 0.000 0.000 -5344.5
<none> 0.000 -5344.3
- Rev.per.mile 1 0.000 0.000 -5343.7
- RPM 1 0.000 0.000 -5343.6
- Fuel.tank.capacity 1 0.000 0.000 -5342.2
- AirBags 2 0.000 0.000 -5341.8
- MPG.city 1 30.851 30.851 -32.2
- MPG.highway 1 33.529 33.529 -25.3
Step: AIC=-5351.75
ay ~ MPG.city + MPG.highway + AirBags + DriveTrain + EngineSize +
Horsepower + RPM + Rev.per.mile + Man.trans.avail + Fuel.tank.capacity +
Passengers + Length + Wheelbase + Width + Turn.circle + Rear.seat.room +
Luggage.room + Weight
Df Sum of Sq RSS AIC
- DriveTrain 2 0.000 0.000 -5354.6
- Wheelbase 1 0.000 0.000 -5353.7
- Luggage.room 1 0.000 0.000 -5353.7
- EngineSize 1 0.000 0.000 -5353.6
- Man.trans.avail 1 0.000 0.000 -5353.6
- Horsepower 1 0.000 0.000 -5353.5
- Rear.seat.room 1 0.000 0.000 -5353.3
- Weight 1 0.000 0.000 -5352.8
- Length 1 0.000 0.000 -5352.5
- Turn.circle 1 0.000 0.000 -5352.2
- Width 1 0.000 0.000 -5351.8
<none> 0.000 -5351.7
- Passengers 1 0.000 0.000 -5351.7
- Rev.per.mile 1 0.000 0.000 -5351.3
- RPM 1 0.000 0.000 -5350.6
- Fuel.tank.capacity 1 0.000 0.000 -5350.0
- AirBags 2 0.000 0.000 -5349.4
+ Cylinders 4 0.000 0.000 -5344.3
- MPG.city 1 33.850 33.850 -32.6
- MPG.highway 1 36.297 36.297 -26.8
Step: AIC=-5354.57
ay ~ MPG.city + MPG.highway + AirBags + EngineSize + Horsepower +
RPM + Rev.per.mile + Man.trans.avail + Fuel.tank.capacity +
Passengers + Length + Wheelbase + Width + Turn.circle + Rear.seat.room +
Luggage.room + Weight
Df Sum of Sq RSS AIC
- Wheelbase 1 0.000 0.000 -5356.5
- Luggage.room 1 0.000 0.000 -5356.5
- Man.trans.avail 1 0.000 0.000 -5356.3
- EngineSize 1 0.000 0.000 -5356.1
- Horsepower 1 0.000 0.000 -5356.0
- Rear.seat.room 1 0.000 0.000 -5355.9
- Length 1 0.000 0.000 -5355.7
- Turn.circle 1 0.000 0.000 -5355.5
- Weight 1 0.000 0.000 -5355.5
- Passengers 1 0.000 0.000 -5355.2
- Width 1 0.000 0.000 -5354.7
<none> 0.000 -5354.6
- Rev.per.mile 1 0.000 0.000 -5354.0
- RPM 1 0.000 0.000 -5353.5
- Fuel.tank.capacity 1 0.000 0.000 -5352.9
- AirBags 2 0.000 0.000 -5352.5
+ DriveTrain 2 0.000 0.000 -5351.7
+ Cylinders 4 0.000 0.000 -5347.3
- MPG.city 1 34.939 34.939 -34.0
- MPG.highway 1 37.082 37.082 -29.1
Step: AIC=-5356.51
ay ~ MPG.city + MPG.highway + AirBags + EngineSize + Horsepower +
RPM + Rev.per.mile + Man.trans.avail + Fuel.tank.capacity +
Passengers + Length + Width + Turn.circle + Rear.seat.room +
Luggage.room + Weight
Df Sum of Sq RSS AIC
- Luggage.room 1 0.000 0.000 -5358.4
- Man.trans.avail 1 0.000 0.000 -5358.2
- EngineSize 1 0.000 0.000 -5358.0
- Horsepower 1 0.000 0.000 -5357.9
- Rear.seat.room 1 0.000 0.000 -5357.9
- Length 1 0.000 0.000 -5357.7
- Turn.circle 1 0.000 0.000 -5357.5
- Weight 1 0.000 0.000 -5357.2
- Passengers 1 0.000 0.000 -5357.1
- Width 1 0.000 0.000 -5356.5
<none> 0.000 -5356.5
- Rev.per.mile 1 0.000 0.000 -5355.9
- RPM 1 0.000 0.000 -5355.3
- Fuel.tank.capacity 1 0.000 0.000 -5354.9
+ Wheelbase 1 0.000 0.000 -5354.6
- AirBags 2 0.000 0.000 -5354.5
+ DriveTrain 2 0.000 0.000 -5353.7
+ Cylinders 4 0.000 0.000 -5349.3
- MPG.city 1 35.071 35.071 -35.6
- MPG.highway 1 38.280 38.280 -28.5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.