Question

Answer the following question by showing the codes in R2. Consider the dataset mtcars and suppose we are interested in modeling the mpg of a vehicle based on a single variable presented in the dataset. a) Use the cor ) function in R, apply it to only numerical variables in the dataset. Identify the numerical variable that shows the most significant correlation, and generate a scatterplot between this variable and mpg. b) Use the 1m() function in R to build a simple regression model using the formula mpg x, where x is the variable you identified from a). Interpret the coefficient generated by the model by calling summary on the model object. Plot the model residuals on a histogram, what do you notice?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

10 15 20 25 30using the cor(t(mtcars)) the following is the correlation table among the variables and found that

since there are N=32 observations( number of cars)

so the significant correlation coefficient=0.349 at two tailed alpha=0.05 with n-2=32-2=30. therefore all the variables significantly correlated to mpg, as the all the absolute correlation coefficient is more than 0.349 ( please look critical r on standard book or internet). But the wt is most significant correlated(negative).

the scatter plot mpg(x1) and wt( x6) is given as

mpg cyl disp hp drat wt qsec vs am gear carb
mpg 1.0000 -0.8522 -0.8476 -0.7762 0.6812 -0.8677 0.4187 0.6640 0.5998 0.4803 -0.5509
cyl -0.8522 1.0000 0.9020 0.8324 -0.6999 0.7825 -0.5912 -0.8108 -0.5226 -0.4927 0.5270
disp -0.8476 0.9020 1.0000 0.7909 -0.7102 0.8880 -0.4337 -0.7104 -0.5912 -0.5556 0.3950
hp -0.7762 0.8324 0.7909 1.0000 -0.4488 0.6587 -0.7082 -0.7231 -0.2432 -0.1257 0.7498
drat 0.6812 -0.6999 -0.7102 -0.4488 1.0000 -0.7124 0.0912 0.4403 0.7127 0.6996 -0.0908
wt -0.8677 0.7825 0.8880 0.6587 -0.7124 1.0000 -0.1747 -0.5549 -0.6925 -0.5833 0.4276
qsec 0.4187 -0.5912 -0.4337 -0.7082 0.0912 -0.1747 1.0000 0.7445 -0.2299 -0.2127 -0.6562
vs 0.6640 -0.8108 -0.7104 -0.7231 0.4403 -0.5549 0.7445 1.0000 0.1683 0.2060 -0.5696
am 0.5998 -0.5226 -0.5912 -0.2432 0.7127 -0.6925 -0.2299 0.1683 1.0000 0.7941 0.0575
gear 0.4803 -0.4927 -0.5556 -0.1257 0.6996 -0.5833 -0.2127 0.2060 0.7941 1.0000 0.2741
carb -0.5509 0.5270 0.3950 0.7498 -0.0908 0.4276 -0.6562 -0.5696 0.0575 0.2741 1.0000

(b) the regression analysis shows the independent variable wt is significantly explaining the dependent variable mpg as the p-value is less than the typical value of alpha=0.05

following are the R-ouput

> lm(mpg~wt)

Call:
lm(formula = mpg ~ wt)

Coefficients:
(Intercept) wt  
37.285 -5.344  

> summary(lm(mpg~wt))

Call:
lm(formula = mpg ~ wt)

Residuals:
Min 1Q Median 3Q Max
-4.5432 -2.3647 -0.1252 1.4096 6.8727

Coefficients:
Estimate Std. Error t value Pr(>|t|)   
(Intercept) 37.2851 1.8776 19.858 < 2e-16 ***
wt -5.3445 0.5591 -9.559 1.29e-10 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.046 on 30 degrees of freedom
Multiple R-squared: 0.7528, Adjusted R-squared: 0.7446
F-statistic: 91.38 on 1 and 30 DF, p-value: 1.294e-10

Add a comment
Know the answer?
Add Answer to:
Answer the following question by showing the codes in R 2. Consider the dataset mtcars and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT