QuestionQuestion

In this exercise you will use the built in “mtcars” data set in R to demonstrate your understanding of R basics. Make an R script and complete the tasks below. Use comments in the script at the top to add your name and the purpose of the script, as well as label each section using the number of the task you are completing. Submit that script as well as this worksheet with the questions answered.

1.) Use the head and summary functions to examine the “mtcars” dataset. What are the attributes in the data set? Which ones are nominal, discrete, continuous?

2.) Indexing is an important part of working with data in R. Using numeric indices, find the horsepower (hp, the forth attribute) of a Datsun 710 (the third car). Also show how you could find this information if you knew only the labels for the object (Datsun 710) and the attribute (hp). What is the horsepower for a Datsun 710?

3.) Let’s examine the attribute “mpg” in more detail. Store the attribute in a vector named “MPG for easy reference. Find the mean, variance, and standard deviation of MPG, and make a boxplot for the variable. Make sure this graph and all future graphs are appropriately labeled! Based on the boxplot, are there any outliers?

4.) Now, let’s look at a histogram for MPG, but use an R library. Install and load the MASS library (include the command to install MASS, even if you have it installed already). Use the truehist function to make a histogram for MPG, using 10 bins for the data. You can use help(truehist) or ?truehist for more information on the function. Based on the histogram, is the data symmetric or skewed? If it is skewed, does it skew left or right?

5.) Now, let’s examine the relationship between Miles per Gallon and Horsepower. Store hp into a vector named HP. Use the plot function the graph HP vs MPG. Do the variables appear to be positively, negatively, or un-correlated?

6.) There appears to be a relationship between MPG and HP, but it does not appear to be linear. Try plotting HP vs the log(MPG). Does this relationship look more linear?

7.) For your final task, perform a simple linear regression using HP and log(MPG). This is not something we covered in class, so you will have to do some research. Make a scatterplot using the variables and add the regression line to it. Change the plotting symbol and color from the defaults for the scatterplot, as well as the color of the line. You may use whatever colors and symbols you want, as long as the graph is still easy to read. Finally, answer the following questions:

a. Is the relationship between HP and MPG significant at alpha = 0.05?
b. What is the regression equation?
c. Do you see any outliers in the data?

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

# 1.
head(mtcars)
summary(mtcars)
# attributes are:
# "mpg" "cyl" "disp" "hp"   "drat" "wt"   "qsec" "vs"   "am"   "gear" "carb"
# vs and am are nominal taking only 0 or 1.
# cyl, gear, and carb are discrete count.
# mpg, disp, hp, drat, wt, and qsec are continuous.

# 2.
mtcars[3, 4]
# [1] 93
mtcars["Datsun 710", "hp"]
# [1] 93

# 3.
MPG <- mtcars$mpg
avg <- mean(MPG)
# [1] 20.09062
variance <- var(MPG)
# [1] 36.3241
std <- sd(MPG)
# [1] 6.026948...

By purchasing this solution you'll be able to access the following files:
Solution.Rmd.

50% discount

Hours
Minutes
Seconds
$24.75 $12.38
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Statistics-R Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats