3 pages word document Raw Data Analysis

profileZGR
TermProjectExample.pdf

Better Mileage–Automatic or Manual? Lorem Ipsum

February 4, 2019

Research Question

Since the dawn of time, humans have argued about their automobiles. One of the questions that has been a particular sore spot is the issue of transmission type and gas mileage. Early cave paintings from the Loire Valley in France suggest that some felt strongly that automatic transmissions offered greater fuel efficiency whereas others insisted that the manual, or standard, variety was better. This debate festered for centuries and finally boiled over in the 1500s with the outbreak of hostilities in the War of Eastern Provo. Unfortunately that conflict did not bring about a peaceful resolution and the debate lingers. The purpose of this report is to settle this conundrum conclusively. The data for this project is/are taken from the “mtcars” dataset which is included in the base package of R. The first step is to look at a summary of the data:

## mpg cyl disp hp ## Min. :10.40 Min. :4.000 Min. : 71.1 Min. : 52.0 ## 1st Qu.:15.43 1st Qu.:4.000 1st Qu.:120.8 1st Qu.: 96.5 ## Median :19.20 Median :6.000 Median :196.3 Median :123.0 ## Mean :20.09 Mean :6.188 Mean :230.7 Mean :146.7 ## 3rd Qu.:22.80 3rd Qu.:8.000 3rd Qu.:326.0 3rd Qu.:180.0 ## Max. :33.90 Max. :8.000 Max. :472.0 Max. :335.0 ## drat wt qsec vs ## Min. :2.760 Min. :1.513 Min. :14.50 Min. :0.0000 ## 1st Qu.:3.080 1st Qu.:2.581 1st Qu.:16.89 1st Qu.:0.0000 ## Median :3.695 Median :3.325 Median :17.71 Median :0.0000 ## Mean :3.597 Mean :3.217 Mean :17.85 Mean :0.4375 ## 3rd Qu.:3.920 3rd Qu.:3.610 3rd Qu.:18.90 3rd Qu.:1.0000 ## Max. :4.930 Max. :5.424 Max. :22.90 Max. :1.0000 ## am gear carb ## Min. :0.0000 Min. :3.000 Min. :1.000 ## 1st Qu.:0.0000 1st Qu.:3.000 1st Qu.:2.000 ## Median :0.0000 Median :4.000 Median :2.000 ## Mean :0.4062 Mean :3.688 Mean :2.812 ## 3rd Qu.:1.0000 3rd Qu.:4.000 3rd Qu.:4.000 ## Max. :1.0000 Max. :5.000 Max. :8.000

Including Plots

Plotting the data is an excellent way for getting to know the relationship between the variables. R offers three approaches to doing this: base graphics, Lattice package, and the ggplot2 package. The base graphics option is probably the easiest to learn. It can produce high quality images but is somewaht limited. The Lattice package is used primarily in scientific research and publication so we’ll leave that for another day. The ggplot2 (gg stands for grammar of graphics) approach has a bit of learning curve but offers greater flexibility in producing great images. The following code shows you how to create a scatter plot in the base package and in ggplot. We’ll keep it simple by plotting “miles per gallon” on the y-axis and engine displacement on the x-axis.

1

100 200 300 400

1 0

1 5

2 0

2 5

3 0

Scatterplot

Engine Displacement

M ile

s p

e r

G a

llo n

And now for the ggplot2 equivalent. Notice it’s a little more complicated but you end up with more flexibility in creating your graphics.

10

15

20

25

30

35

100 200 300 400

Engine Displacement

M ile

s p

e r

G a

llo n

Scatterplot

Another good visualization when comparing the means of two groups is the boxplot. Here’s a boxplot in ggplot2. The code is found in the R Markdown document. Please feel free to steal it.

2

10

15

20

25

30

35

M ile

s p

e r

G a

llo n

Automatic

Manual

Miles per Gallon by Transmission Type

3

Regression Analysis

The point of this exercise is to analyze whether there is a difference. As we’ll learn later this semester, linear regression is a great tool for looking at these types of problems. Although the details aren’t discussed here, the results are given in the table below.

Table 1: Regression Analysis of MPG by Transmission Type

Dependent variable: mpg

disp −0.014 (0.009)

hp −0.041∗∗∗ (0.014)

am 3.796∗∗ (1.424)

Constant 27.866∗∗∗ (1.620)

Observations 32 R2 0.799 Adjusted R2 0.778 Residual Std. Error 2.842 (df = 28) F Statistic 37.149∗∗∗ (df = 3; 28)

Note: ∗p<0.1; ∗∗p<0.05; ∗∗∗p<0.01

This analysis shows that, on average, a manual transmission gets about 3.796 more miles to the gallon than an automatic. This is model omits several important variables (like number of cylinders) so it shouldn’t be taken too seriously. Hopefully this brief document gives you an idea as to how to do the term project. You are under no obligation to use R Markdown but I would recommend it if you are thinking about “leveling up” your analytics skills.

4

  • Research Question
  • Including Plots
  • Regression Analysis