Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Load the dataset mtcars from R. (a) Filter out observations whose weight is more

ID: 2907945 • Letter: L

Question

Load the dataset mtcars from R. (a) Filter out observations whose weight is more than 5 units. (b) Using the remaining observations, fit a simple linear regression model using MPG as the response variable and weight as the explanatory variable (c) Report the estimated regression coefficient and interpret its meaning (d) Report predicted value of MPG when weights are 3 and 5.260 units? (e) Now fit a simple linear regression model using all 32 values of MPG and weight. Report the predicted value of MPG when weights are 3 and 5.260 units

Explanation / Answer

SolutonA:

Rcode:

dim(mtcars)
# 32 rows 11 columns
names(mtcars)
names(mtcars)
View(mtcars)
mtcars1 <- mtcars%>% filter(mtcars, wt > 5)

output is:

mpg cyl disp hp drat wt qsec vs am gear carb
Cadillac Fleetwood 10.4 8 472 205 2.93 5.250 17.98 0 0 3 4
Lincoln Continental 10.4 8 460 215 3.00 5.424 17.82 0 0 3 4
Chrysler Imperial 14.7 8 440 230 3.23 5.345 17.42 0 0 3 4

Solutionb:

Exclude the rows that satisy wt>5

Rocde:

mtcars1<-mtcars[!(mtcars$wt >5),]
dim(mtcars1)

[1] 29 11

Build a linear regression model using lm function .

Rcode is:

regmod =lm(mpg~wt,data=mtcars1)
coefficients(regmod)

(Intercept) wt
41.392930 -6.821287

Regression equation is

mpg=41.392930-6.821287*wt

Solutionc:

slope=-6.821287

intrepretation:

For unit increase in weight,mpg decreases by 6.821287 units.

y intercept=41.392930

Intrepretaion:

for weight equal zero mpg is 41.392930

y intercept intrepretation is not meaningful

Solutiond:

Rcodde:


new.weights <- data.frame( wt = c(3, 5.260))

predict(regmod, newdata = new.weights)

Ouptut:

1 2
20.929068 5.512959

For wt =3 predicted mpg=20.929068

for wt=5.2600 predicted mpg=5.512959

Solutione:

Rcode is

regmod2 <- lm(mpg~wt,data=mtcars)
coefficients(regmod2)


(Intercept) wt
37.285126 -5.344472

Estimated regression equation is

mpg=37.285126-5.344472*wt

For new weights

Rcode is:
predict(regmod2, newdata = new.weights)

1 2
21.251711 9.173206

For wt=3 ,predicted mpg=21.251711

For wt=5.2600, predicted mpg=9.173206

Entire R code is:

mtcars1<-mtcars[!(mtcars$wt >5),]
dim(mtcars1)
regmod =lm(mpg~wt,data=mtcars1)
coefficients(regmod)

new.weights <- data.frame(
wt = c(3, 5.260)
)


predict(regmod, newdata = new.weights)

regmod2 <- lm(mpg~wt,data=mtcars)
coefficients(regmod2)


predict(regmod2, newdata = new.weights)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote