Lab 1 Introductions to R Sean Potter.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

© by Pearson Education, Inc. All Rights Reserved.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Create slices and hotspots Create links in Web pages Create rollovers from slices Create basic animation Add tweening symbol instances to create animation.
CIS101 Introduction to Computing Week 09 Spring 2004.
Introduction to SPSS Short Courses Last created (Feb, 2008) Kentaka Aruga.
Introduction to R Statistical Software Anthony (Tony) R. Olsen USEPA ORD NHEERL Western Ecology Division Corvallis, OR (541)
Panorama High School E.G.P./ Training to Put Students’ Grades on the Website Wednesday, September 29,
A First Program Using C#
Microsoft Excel 2007 © Wiley Publishing All Rights Reserved. The L Line The Express Line to Learning L Line.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
IE 411/511: Visual Programming for Industrial Applications
Introduction to R Part 2. Working Directory The working directory is where you are currently saving data in R. What is the current working directory?
Teacher’s Assessment Assistant Worksheet Builder Starting the Program
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files.
Hands-on Introduction to R. We live in oceans of data. Computers are essential to record and help analyse it. Competent scientists speak C/C++, Java,
Introduction to SPSS. Object of the class About the windows in SPSS The basics of managing data files The basic analysis in SPSS.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
A Simple Guide to Using SPSS ( Statistical Package for the Social Sciences) for Windows.
Introduction to R Introductions What is R? RStudio Layout Summary Statistics Your First R Graph 17 September 2014 Sherubtse Training.
Performing statistical analyses using the Rshell processor Original material by Peter Li, University of Birmingham, UK Adapted by Norman.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files 8/10/ :35 PM.
PHP Form Processing * referenced from
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
Chris Knight Beginners’ workshop.
Editing and Debugging Mumps with VistA and the Eclipse IDE Joel L. Ivey, Ph.D. Dept. of Veteran Affairs OI&T, Veterans Health IT Infrastructure & Security.
Dive Into® Visual Basic 2010 Express
Block 1: Introduction to R
Intro to WordPress (Using XAMPP)
Dreamweaver – Setting up a Site and Page Layouts
Development Environment
Release Numbers MATLAB is updated regularly
Lecture 2: Introduction to R
Performing statistical analyses using the Rshell processor
Getting Started with R.
By Dr. Madhukar H. Dalvi Nagindas Khandwala college
An introduction to programming Created by Dr. Randy Pausch
DEPARTMENT OF COMPUTER SCIENCE
Introduction to R Studio
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Bomgar Remote support software
Intro to PHP & Variables
Boeing Supply Chain Platform (BSCP) Detailed Training
Central Document Library Quick Reference User Guide View User Guide
MATLAB DENC 2533 ECADD LAB 9.
ECONOMETRICS ii – spring 2018
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Chapter 1: Introduction to SAS
Instructor: Raul Cruz-Cano
Lecture 1: Introduction
An introduction to data analysis using R
UNITY TEAM PROJECT TOPICS: [1]. Unity Collaborate
How to Run a Java Program
Use of Mathematics using Technology (Maltlab)
T. Jumana Abu Shmais – AOU - Riyadh
Installing Packages Introduction to R, Part II
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Running a Java Program using Blue Jay.
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Approving Time in Kronos Manager/Supervisor Reference Guide
Carthage ios 8 onwards Dependency manager that streamlines the process of integrating the libraries into the project.
Web Programming and Design
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Training Document Accessing Reports in VinCENT.
A brief introduction to the nutrient tool-kit, getting R Studio to work and checking the data Martyn Kelly
Selenium IDE Installation and Use.
Exploring Microsoft Excel 2003
Presentation transcript:

Lab 1 Introductions to R Sean Potter

Today’s Agenda: Lab Overview Intro to R Importing data to R Creating simple graphs using R Assignment & Questions

Overall Lab Purpose Provide hands-on instruction and practice with the analyses and techniques learned in lecture. Develop template codes for you to use in the future.

Assignments Homework will be R data analysis activities and some computational problems (including some problems from Howell) Due at the beginning of the next class Many assignments will require the turning in of syntax and/or output. These will be specifically requested and be uploaded to the assignment folder in Canvas Start early so any questions or issues can be addressed before due date!

Introduction to R

What is R? Why R? Programming language (like C#, Python, Java, etc.) Similar to using SAS, SPSS syntax Open-source (don’t have to pay $$$ license fees!) Increasingly popular in academia, industry Updated functions constantly being provided Easily produces customizable, journal-quality graphics Why R?

What is RStudio? IDE (Integrated Development Environment) User-friendly interface when using R Also open source

Installing R on Own Computer Install R Open an internet browser and go to www.r-project.org. Click the "download R" link in the middle of the page under "Getting Started." Select a CRAN location (a mirror site) and click the corresponding link. Click on the "Download R for (Mac) OS X" link at the top of the page. Click on the file containing the latest version of R under "Files." Save the .pkg file, double-click it to open, and follow the installation instructions. Install R Studio Go to www.rstudio.com and click on the "Download RStudio" button. Click on "Download RStudio Desktop." Click on the version recommended for your system, or the latest Mac version, save the .dmg file on your computer, double-click it to open, and then drag and drop it to your applications folder.

First Taste of R We’ll do a overview of R, and then review it again next week Follow along Later play with R following the slides on your own Go to “Start,” then “All programs,” then “RStudio”

Starting Out Select new R Script

Run whole Script or highlighted section The editor is where you can write R code that can be saved and reran. Press CTRL + Enter to run highlighted code Environment tab shows all active objects. History tab shows list of commands used so far. Files tab shows files and folders in your current workspace. Plots tab shows all your graphs. Packages tab shows available packages to run certain functions. Help tab provides additional info. Viewer tab is built-in browser. The console is where you see output and can also type R code.

Data structure Two helpful slogans to understand R computations Anything that exists is an object Dataset The results of a t-test Graph Anything that happens is a function call R has up to 6 atomic classes (types of data values) You’ll likely deal with these three mostly Type Example Character “A”, “b”, “Portland, OR” Numeric 2, 15.5 Logical TRUE, FALSE

Data Structures Vector Values of all same data type Numeric Character 1 2 3 M F

Data Structures Factor Collection of values that have fixed set of possible values Similar to vector Represents categorical variables M F

Data Structures Matrices Two-dimensional collection of values of same type Array can extend this to more than two dimensions 1 7 9 4 2 3

Data Structures Data frames Collection of vectors that all have same length Columns can have different data types Array can extend this to more than two dimensions 1 2 3 M F a b c

Data Structures Lists Similar to data frame, but columns can have varying lengths 1 2 3 M a b

Program Editor (Cont.) Color codes are helpful, watch out for red R functions and commands – blue Options, data, variable names, ect. – black Comments and text in quotation – green (put # to start comment on line) Error and warnings – red Will appear in the console after running code Color scheme can be customized under Tools <- global options

Log with errors vs. no errors Error indicated in red, explains cause of error Be careful, an error when changing object will result in object remaining the same as before

Things to Note When Writing Code Syntax is case-sensitive Typing in “data” to call an object named “Data” is wrong Object names consist of letters, numbers, underscores “_” and periods “.” You can use either ‘<-’ or ‘=‘ to assign objects value a <- c(1,2,3) a = c(1,2,3) Functions can stand on their own or be an object 1 + 2 a <- 1 + 2 Important to consider later on when we do analyses

Let’s Practice! Input data directly into R Create the dataset (below) and view generated dataset Input data directly into R Run R Script

How To Import Data ? Syntax Import Dataset option

Importing Data Using Syntax Example .csv import

Import dataset from text file Import Data Option Import dataset from text file

Set if headers part of dataset Import Data Option Set object name Set if headers part of dataset *Note: can’t read in .xlsx files

Check Frequencies Often check frequencies with variables. Especially useful for categorical variables (sex, race) R provides ‘table’ function to check frequencies Doesn’t include missing values Need to install ‘plyr’ package to access ‘count’ function

Set where package installed from, usually CRAN Installing Packages Select Install Set where package installed from, usually CRAN Type out package name

Loading Packages R doesn’t automatically load all available packages Need to load additional packages into session Two approaches Find package in under package tab and check its box Use library function

Load & Check Data First, load up the example1 dataset included in module Includes four variables Employee ID (Employee) Performance (Perf) Conscientiousness (Conscale) Sex Use the ‘str’ command to check what the computer understands to be the contents of your data-this matters when you analyze (‘factor’ plots and adds differently than ‘integer’ or ‘number’)

Time to Plot Stuff! The plot and hist functions present users with options to customize their graphs I’ll show the basic graphs first Then show the graphs with additional options I set

Plot with added Options Basic Plot R plots easily customized Use help() on any function to learn about its options Plot with added Options

Plot Numeric Frequencies Can’t use plot function again Will make a scatter plot of variable by each observation’s index (position in dataset) instead Will require use of hist function instead

Plot with added Options Basic Plot Plot with added Options

Make a Scatterplot We’ll use plot function again Plot follows format of plot(x, y) by default First object will go on x axis Second object will go on y axis You can specifically define the x and y variables however

Plot with added Options Basic Plot Plot with added Options

Plot by sex Include legend

Assignment 1 Importing Excel and Text data files to R Create very simple graphs and interpret them. Not intended to be tricky or complicated In Canvas  Assignments  Homework 1 Upload your clean R files to Canvas. Turn in hardcopy of your answer for question 3, 4 and 5.