One-Way ANOVA in R

Given the data set Cars93 in R, how do we break down some of the variables and start determining where some of the salient differences are in our data?

In R, open the data set with the following prompt:

>data()
>Cars93

The first step is going to be to display the data so that we can understand the nature of the variables that were are working with.

>View(Cars93)

screen-shot-2017-01-19-at-1-43-23-pm
Given this view of the variables, we are able to start to think about the questions we want to ask about our data.  If we want to better understand the relationship between Tpye of
automobile and the Gas Mileage, the following prompt will give us a visual of the data:

> boxplot(Cars93$MPG.highway ~ Cars93$Type)

 

screen-shot-2017-01-19-at-1-40-18-pmViewing this Box Plot gives us a look at the Median differences between groups and the distance between the lowest 25th percentile and the highest 25th percentile in our groups.  Running a One-Way ANOVA will identify if significant differences between groups exist (which, it appears there might be).

> aggregate(MPG.highway ~ Type, FUN = mean)

screen-shot-2017-01-19-at-2-14-47-pm

The aggregate function filters the groups and their means to help us further identify differences between Type and highway gas mileage:

 

And using a One-Way ANOVA will test for significant differences between groups:

> anova.table <- aov(Cars93$MPG.highway ~ Cars93$Type)
> summary(anova.table)

 

screen-shot-2017-01-19-at-2-09-12-pm

This one-way ANOVA shows that the average MPG differs significantly based on Type of automobile (e.g., Compact, Van, etc; F(5,87) = 24.09, p > 0.001).  Post-hoc comparisons will be needed to determine where the significant differences exist (e.g., between Small size cars and Vans).

 

 

Advertisements

About dwmaasberg

Memories are physical connections between neurons. I think that is pretty cool!
This entry was posted in ANOVA, R, Statistics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s