STAT 221 lab2 - Using R for Regression and Correlation...

This preview shows page 1 - 3 out of 12 pages.

We have textbook solutions for you!
The document you are viewing contains questions related to this textbook.
Fundamental Statistics for the Behavioral Sciences
The document you are viewing contains questions related to this textbook.
Chapter 10 / Exercise 10.18
Fundamental Statistics for the Behavioral Sciences
Howell
Expert Verified
Using R for Regression and CorrelationPatricia Martinkova, Andrew McDavidApril 25, 2015In this lab you will learn commands to implement some of the concepts covered in Chapters 4 and 5 ofTheBasic Practice of Statistics (BPS5e): Scatterplots, Correlation and Linear Regression. We will use packagecontaining all datasets from the book (prepared as R package courtesy of JeffArnold). Please take advantageof this possibility and try to analyze more datasets as you read the book.First of all, navigate to RStudio server atwith a web browser and log inwith your netID.To use theRpackagebps5datawith the datasets, you first need to load it intoRusing the functionlibrary:library("bps5data")ScatterplotsLet’s create the plot in Example 4.5 ofBPS5th edition. This example considers data on the number of boatsregistered in Florida (in thousands) and the number of manatees killed by boats for the years 1977 to 2006.First, load the dataset that we will be using.data("ta04.01",package ="bps5data")This loads a data frame namedta04.01into the workspace. Look at the data either by typing the name ofthe dataset or using the functionView:View(ta04.01)The data frame has 30 observations and 3 variables:Year,Boats,Kills. You can also print the summary ofthe data:summary(ta04.01)##YearBoatsKills##Min.:1977Min.: 447Min.:13##1st Qu.:19841st Qu.: 5661st Qu.:33##Median :1992Median : 688Median :45##Mean:1992Mean: 710Mean:49##3rd Qu.:19993rd Qu.: 8253rd Qu.:68##Max.:2006Max.:1024Max.:95We want to create a scatterplot of the number of boats (in thousands, so 500 means 500,000 boats) registeredversus the Florida manatees killed by boats. Recall, that if one variable is thought of as a response and theother as explanatory (explaining the response), we plot the explanatory variable on x-axis and the responseon y-axis. In this case, boats are the proximate cause of the manatee deaths, so we put number of killedmanatees (response) on y-axis and number of boats (explanatory variable) on x-axis. We create scatterplotsusing the functionplot:1
We have textbook solutions for you!
The document you are viewing contains questions related to this textbook.
Fundamental Statistics for the Behavioral Sciences
The document you are viewing contains questions related to this textbook.
Chapter 10 / Exercise 10.18
Fundamental Statistics for the Behavioral Sciences
Howell
Expert Verified
plot(x =ta04.01$Boats,y =ta04.01$Kills)Recall that since the variablesKillsandBoatsare columns in the data frameta04.01, we need to use the$to refer to them.Check help to see what options does functionplotprovide:help(plot)In left bottom window, you can now see the manual for functionplot. Let’s make these changes:add labels to x-axis and y-axis using parametersxlabandylabadd main label using parametermainchange point symbol using parameterpchchange color of points using parametercolplot(x =ta04.01$Boats,y =ta04.01$Kills,xlab ="Boats (thousands)",ylab ="Kills",main ="Manatees killed by boats",pch =20,col ="darkblue")500600700800900100020406080Manatees killed by boatsBoats (thousands)KillsFigure 1: ScatterplotCorrelationThe functioncoris used to calculate the correlation between two variables. Using the manatee dataset inTable 4.1 ofBPS5e, let’s calculate the correlation between the number of boat registrations and the numberof manatees killed per year.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture