An Introduction to R POL 51 October 13, 2008 Malcolm Easton Office hours: Thursday 3:30-5:30 in Rm 245 1.

Slides:



Advertisements
Similar presentations
Summary Statistics/Simple Graphs in SAS/EXCEL/JMP.
Advertisements

HS 67 - Intro Health Statistics Describing Distributions with Numbers
Data in R. General form of data ID numberSexWeightLengthDiseased… 112m … 256f3.61 NA1… 3……………… 4……………… n91m5.1711… NOTE: A DATASET IS NOT A MATRIX!
Basics of Using R Xiao He 1. AGENDA 1.What is R? 2.Basic operations 3.Different types of data objects 4.Importing data 5.Basic data manipulation 2.
Gateway Program Go to along the left side, in the third section, click on The Gateway.
Introduction to GTECH 201 Session 13. What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming.
Operations Management Dr. Ron Lembke
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
CS1100: Computer Science and Its Applications Creating Graphs and Charts in Excel.
Introduction to Excel 2007 Part 1: Basics and Descriptive Statistics Psych 209.
How to Use the R Programming Language for Statistical Analyses Part I: An Introduction to R Jennifer Urbano Blackford, Ph.D. Department of Psychiatry Kennedy.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Excel For MATH 125 Computing Statistics. Useful link Surfstat: (an online text in introductory Statistics)
UDM MSC COURSE IN EDUCATION & DEVELOPMENT 2013 –
3. Functions and Arguments. Writing in R is like writing in English Jump three times forward Action Modifiers.
Advanced Tables Lesson 9. Objectives Creating a Custom Table When a table template doesn’t suit your needs, you can create a custom table in Design view.
CIS*1000*DE – Databases Microsoft Access (Part 2).
Basic R Programming for Life Science Undergraduate Students Introductory Workshop (Session 1) 1.
Assignments  1. Grade graphs and conclusions.  2. Introduction to Reaction Time.  3. Begin Pre-Lab of Reaction Time.
HS 115 Unit Four Seminar Amber Krasny, MBA, CPC, CMRS.
May 28, 2008Stat Lecture 3 - Numerical Summaries 1 Exploring Data Numerical Summaries of One Variable Statistics Lecture 3.
UNLOCKING THE SECRETS HIDDEN IN YOUR DATA
Entering survey results into excel Assumed knowledge – use of outlines, cell adjustments and formatting and basic functionality Griffith High School PLT.
Hands-on Introduction to R. Outline R : A powerful Platform for Statistical Analysis Why bother learning R ? Data, data, data, I cannot make bricks without.
MATH125 Chapter 3 topics ANALYZING DATA NUMERICALLY.
XP 1 Excel Tables Purpose of tables – Process data in a group – Used to facilitate calculations – Used to enhance readability of output Types of tables.
UNLOCKING THE SECRETS HIDDEN IN YOUR DATA Data Analysis.
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
1 Performing Spreadsheet What-If Analysis Applications of Spreadsheets.
Ecomdash Ecomdash Academy Lesson Plan Creating a Amazon listing 1:08 / 4:27.
Data Objects in R Vector1 dimensionAll elements have the same data types Data types: numeric, character logic, factor Matrix2 dimensions Array2 or more.
Piotr Wolski Introduction to R. Topics What is R? Sample session How to install R? Minimum you have to know to work in R Data objects in R and how to.
MATLAB FUNDAMENTALS: MATRIX/ARRAY FUNCTIONS THE COLON MATRIX/ARRAY MANIPULATION INPUT/OUTPUT HP 100 – MATLAB Wednesday, 9/3/2014
Incorporating Dynamic Time Warping (DTW) in the SeqRec.m File Presented by: Clay McCreary, MSEE.
ABINIT INPUT MAKER By Simon Pesant and BenjaminTardif 29/01/2007.
R Programming Yang, Yufei. Normal distribution.
Microsoft Access 2007 Tutorial (Part II) CIS*1000*DE.
Outline Comparison of Excel and R R Coding Example – RStudio Environment – Getting Help – Enter Data – Calculate Mean – Basic Plots – Save a Coding Script.
TUTORIAL 8 INSTRUCTOR: HANIF ULLAH ID: OFFICE #: 2029 DATE: 15/04/2012 Introduction to MS Project 2007.
Introduction to Programming in R Department of Statistical Sciences and Operations Research Computation Seminar Series Speaker: Edward Boone
Analyses using SPSS version 19
Excel Basics This is a row. Rows are represented by numbers along the side of the sheet. This is a column. Columns are represented by letters across the.
XP. Objectives Sort data and filter data Summarize an Excel table Insert subtotals into a range of data Outline buttons to show or hide details Create.
June 21, Objectives  Enable the Data Analysis Add-In  Quickly calculate descriptive statistics using the Data Analysis Add-In  Create a histogram.
Introduction to R Carol Bult The Jackson Laboratory Functional Genomics (BMB550) Spring 2011.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
Remember…  Please do not…  Change the background.  Change the icons.  Change the font. Use Times New Roman (size 12 font).  Use color. We cannot print.
Ecomdash Ecomdash Academy Lesson Plan Creating a Rakuten listing 1:08 / 4:27.
Statistical Analysis with Excel. Learning Objectives Be able to use the Dial Caliper to measure Be able to use Microsoft Excel to –Calculate mean, median,
LOGIN PAGE Login Page Support CRM:
Probability and Statistics 12/11/2015. Statistics Review/ Excel: Objectives Be able to find the mean, median, mode and standard deviation for a set of.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
The NCCS Data Web: An Introduction The National Center for Charitable Statistics at the Urban Institute January.
Working with data in R 2 Fish 552: Lecture 3. Recommended Reading An Introduction to R (R Development Core Team) –
This is only an introduction!!
Welcome to Week 03 College Statistics
Probability and Statistics
MATLAB – More Script Files
Introduction to Excel 2007 January 29, 2008.
Analyzing Data with Excel
Microsoft Office Illustrated
Performing What-if Analysis
Python I/O.
Minitab Instructions Covered
Code is on the Website Outline Comparison of Excel and R
Basics of R, Ch Functions Help Managing your Objects
Topic 7: Visualization Lesson 1 – Creating Charts in Excel
Introduction to Excel 2007 Part 1: Basics and Descriptive Statistics Psych 209.
Assignment resource Working with Excel Tables, PivotTables, and Pivot Charts Fairhurst pp The commands on these slides work with the Week 2 Excel.
Presentation transcript:

An Introduction to R POL 51 October 13, 2008 Malcolm Easton Office hours: Thursday 3:30-5:30 in Rm

Section Outline What is R? Presentation of some R basics Set of exercises done in class if time permits 2

What can R do? R can act as an overgrown calculator R can run some very high end statistical models 3

Loading R Go to Class website: l2008.html Follow instructions to load R 4

Why R is so user-friendly R is an object oriented environment! Everything is an object. You write code to create objects or variables and then define how these objects relate to each other. xbar<-mean(x) xbar=mean(x) You create a variable name (xbar) and then you describe its “value”, in this case the mean of whatever x is. 5

Inputting data manually It is easy! weight<-c(60, 72, 57, 90, 95, 72) c(…) is used to define a vector of numbers. You can generate a matrix (two-dimensional array of numbers—rows and columns) by binding two vectors together. height<-c(6, 5, 7, 5, 7, 5) 6

cbind and rbind You can now “glue” both of these vectors together either as two columns with the variable name on top or two rows with the variable names on the left hand side. xmat1<-cbind(weight, height) xmat2<-rbind(weight, height) 7

This is what it looks like xmat1=cbind(weight, height) xmat1 weight height [1,] 60 6 [2,] 72 5 [3,] 57 7 [4,] 90 5 [5,] 95 7 [6,] 72 5 xmat2=rbind(weight, height) xmat2 [,1] [,2] [,3] [,4] [,5] [,6] weight height

How to ask for help What if you want to use data that is provided on the website? Specifically the Congressional Control Pricing data in excel format. You have to “read” the data into R. Well, if you are a beginner just ask R how to read in data. Ex: ?read.table If you cannot be specific (why did he write.table?) you can use a built-in search by typing help.search(“table”) 9

Ok, now this is how you read a.csv file into R General code: data.set<-read.table(“C:/file name.ext”, header=TRUE) Note another oddity about R, you must use forward slashes. congress<-read.csv("C:/Documents and Settings/Malcolm Easton/Desktop/Pol 51/congressprice.csv", header=TRUE) Also notice that header=TRUE is just telling R that the first line is a header containing the names of variables in the file. 10

Now you can play with summary statistics! summary(congress$rhdsprice) Or if writing all of that is a pain you can choose to assign that path to an object. price1<-congress$rhdsprice summary(price1) Or easier still, just “attach” your data set which tells R to look for objects among the variables in a given data frame. 11

Attaching a data frame If you type attach(congress) you can now summarize your data by typing summary(rhdsprice) 12

More fun with summary stats The summary() function gives you some basic summary stats, but you can get more specific if you like. Mean: mean(rhdsprice) Median: median(rhdsprice) Maximum: max(rhdsprice) Minimum: min(rhdsprice) 13

Is that all R can do? No, that is just the tip of the iceberg. You can code functions into R or use a large number of pre-coded functions. You can use R to calculate the variance, and standard deviation of a variable as well as a slew of graphical options as well. Built in code: var(rhdsprice) Manually coding: n=length(rhdsprice) Manual.var=(1/(n-1))*sum((rhdsprice- mean(rhdsprice))^2) 14