r2 - Math 127B, Basic R, Lecture 2 Mrinal Raghupathi...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Math 127B, Basic R, Lecture 2 Mrinal Raghupathi Wednesday, April 6, 2011 Administrivia Today we will learn about R’s basic plotting features, basic list operations, and how to create our own commands. Reminders 1. Homework 9 is due Thursday, 4/7 in recitation. 2. Quiz in recitation over chapter 28 on 4/27. 1 Basic plots Let’s begin by creating some data to work with. We will create two sets of data. You can copy and paste the data from the file on the website called cigarette.txt. The first list is the tar content in mg for 25 brands of cigarette. The second list is the nicotine content for the same 25 brands. Let’s create two lists and give them the names tar and nic . What is the average and sd of the two lists? 1.1 Are tar and nicotine content related? A good way to answer a question like this, is to use a scatter plot. The command plot allows us to plot two lists. Type plot(tar, nic) . Does the resulting plot indicate a relationship between the two variables? One way to check the strength of a relationship is to use the find the SD line and the coefficient of correlation r . The command cor computes the coefficient of correlation between the two variables. Type cor(tar, nic) . What is the value of the coefficient of correlation? What happens if you type cor(nic, tar) . 1 1.2 Histograms We can use R to produce a histogram. The command is called hist . Typing hist(tar) will produce a histogram of the tar variable. You can increase the number of bins by typing using the breaks option. So hist(tar, breaks = 12) will produce a plot with more intervals....
View Full Document

This document was uploaded on 10/29/2011 for the course MATH 127B at Vanderbilt.

Page1 / 5

r2 - Math 127B, Basic R, Lecture 2 Mrinal Raghupathi...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online