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.

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

Writing functions in R Some handy advice for creating your own functions.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Developing an Excel Application
Tutorial 8: Developing an Excel Application
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Basics of R, Ch  Functions  Help  Managing your Objects  Getting Data into R  Getting Results out of R 1 © Fall 2004 Don Edwards and the University.
 Statistics package  Graphics package  Programming language  Can be used to share/reproduce analyses  Many new packages being created - can be downloaded.
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.
Introduction to GTECH 201 Session 13. What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming.
Using Visual Basic 6.0 to Create Web-Based Database Applications
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Alternative text for elementary statistics –Elementary Concepts –Basic Statistics.
Lecture 2 LISAM. Statistical software.. LISAM What is LISAM? Social network for Creating personal pages Creating courses  Storing course materials (lectures,
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Introduction to R: The Basics Rosales de Veliz L., David S.L., McElhiney D., Price E., & Brooks G. Contributions from Ragan. M., Terzi. F., & Smith. E.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Introduction to R Statistical Software Anthony (Tony) R. Olsen USEPA ORD NHEERL Western Ecology Division Corvallis, OR (541)
Applied Bioinformatics Introduction to Linux and R Bing Zhang Department of Biomedical Informatics Vanderbilt University
Digital Image Processing Lecture3: Introduction to MATLAB.
Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically.
Basic R Programming for Life Science Undergraduate Students Introductory Workshop (Session 1) 1.
1 An Introduction – UCF, Methods in Ecology, Fall 2008 An Introduction By Danny K. Hunt & Eric D. Stolen Getting Started with R (with speaker notes)
ASP.NET Programming with C# and SQL Server First Edition
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Tutorial 1 Getting Started with Adobe Dreamweaver CS3
An introduction to R: get familiar with R Guangxu Liu Bio7932.
732A44 Programming in R.  Self-studies of the course book  2 Lectures (1 in the beginning, 1 in the end)  Labs (computer). Compulsory submission of.
Introduction to SPSS Edward A. Greenberg, PhD
Data, graphics, and programming in R 28.1, 30.1, Daily:10:00-12:45 & 13:45-16:30 EXCEPT WED 4 th 9:00-11:45 & 12:45-15:30 Teacher: Anna Kuparinen.
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.
Creating a Web Site to Gather Data and Conduct Research.
Intro to R R is a free version of S-plus R is a free version of S-plus Can be used interactively but script or syntax files are commonly used to record.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
 A database is a collection of data that is organized so that its contents can easily be accessed, managed, and updated. What is Database?
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
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.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Introduction to R. Why use R Its FREE!!! And powerful, fairly widely used, lots of online posts about it Uses S -> an object oriented programing language.
R packages/libraries Data input/output Rachel Carroll Department of Public Health Sciences, MUSC Computing for Research I, Spring 2014.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Introduction to R Introductions What is R? RStudio Layout Summary Statistics Your First R Graph 17 September 2014 Sherubtse Training.
Introduction to R Carol Bult The Jackson Laboratory Functional Genomics (BMB550) Spring 2011.
STAT 534: Statistical Computing Hari Narayanan
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Learn R Toolkit D Kelly O'DayExcel & R WorldsMod 2 - Excel & R Worlds: 1 Module 2 Moving Between Excel & R Worlds Do See & HearRead Learning PowerPoint.
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
© 2015 by Wade Rogers Introduction to R Cytomics Workshop December, 2015.
Introduction to Exploratory Descriptive Data Analysis in S-Plus Jagdish S. Gangolly State University of New York at Albany.
PROGRAMMING IN R Introduction to R. In this session I will: Introduce you to the R program and windows Show how to install R Write basic programs in R.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
R objects  All R entities exist as objects  They can all be operated on as data  We will cover:  Vectors  Factors  Lists  Data frames  Tables 
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Enterprise Database Systems Introduction to SQL Server Dr. Georgia Garani Dr. Theodoros Mitakos Technological.
Lecture 11 Introduction to R and Accessing USGS Data from Web Services Jeffery S. Horsburgh Hydroinformatics Fall 2013 This work was funded by National.
An Introduction to Programming in Matlab Emily Blumenthal
Pinellas County Schools
Tutorial 1 Getting Started with Adobe Dreamweaver CS5.
Microsoft Excel Illustrated Introductory Workbooks and Preparing them for the Web Managing.
Excel Tutorial 8 Developing an Excel Application
Programming in R Intro, data and programming structures
Basics of R, Ch Functions Help Managing your Objects
MIS2502: Data Analytics Introduction to R and RStudio
Creating a dataset in R Instructor: Li, Han
Presentation transcript:

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 Center

What Is R? a programming “environment” object-oriented similar to S-Plus freeware provides calculations on matrices excellent graphics capabilities supported by a large user network

What is R Not? a statistics software package menu-driven quick to learn a program with a complex graphical interface

Installing R download from CRAN select a download site download the base package at a minimum download contributed packages as needed

Tutorials From R website under “Documentation” –“Manual” is the listing of official R documentation An Introduction to R R Language Definition Writing R Extensions R Data Import/Export R Installation and Administration The R Reference Index

Tutorials cont. –“Contributed” documentation are tutorials and manuals created by R users Simple R R for Beginners Practical Regression and ANOVA Using R –R FAQ –Mailing Lists (listserv) r-help

Tutorials cont. Textbooks –Venables & Ripley (2002) Modern Applied Statistics with S. New York: Springer-Verlag. –Chambers (1998). Programming With Data: A guide to the S language. New York: Springer- Verlag.

R Basics objects naming convention assignment functions workspace history

Objects names types of objects: vector, factor, array, matrix, data.frame, ts, list attributes –mode: numeric, character, complex, logical –length: number of elements in object creation –assign a value –create a blank object

Naming Convention must start with a letter (A-Z or a-z) can contain letters, digits (0-9), and/or periods “.” case-sensitive –mydata different from MyData do not use use underscore “_”

Assignment “<-” used to indicate assignment –x<-c(1,2,3,4,5,6,7) –x<-c(1:7) –x<-1:4 note: as of version 1.4 “=“ is also a valid assignment operator

Functions actions can be performed on objects using functions (note: a function is itself an object) have arguments and options, often there are defaults provide a result parentheses () are used to specify that a function is being called

Let’s look at R

R Workspace & History

Workspace during an R session, all objects are stored in a temporary, working memory list objects –ls() remove objects –rm() objects that you want to access later must be saved in a “workspace” –from the menu bar: File->save workspace –from the command line: save(x,file=“MyData.Rdata”)

History command line history can be saved, loaded, or displayed –savehistory(file=“MyData.Rhistory) –loadhistory(file=“MyData.Rhistory) –history(max.show=Inf) during a session you can use the arrow keys to review the command history

Two most common object types for statistics: matrix data frame

Matrix a matrix is a vector with an additional attribute (dim) that defines the number of columns and rows only one mode (numeric, character, complex, or logical) allowed can be created using matrix() x<-matrix(data=0,nr=2,nc=2) or x<-matrix(0,2,2)

Data Frame several modes allowed within a single data frame can be created using data.frame() L<-LETTERS[1:4] #A B C D x<-1:4 # data.frame(x,L) #create data frame attach() and detach() –the database is attached to the R search path so that the database is searched by R when it is evaluating a variable. –objects in the database can be accessed by simply giving their names

Data Elements select only one element –x[2] select range of elements –x[1:3] select all but one element –x[-3] slicing: including only part of the object –x[c(1,2,5)] select elements based on logical operator –x(x>3)

Data Import & Entry

Importing Data read.table() –reads in data from an external file data.entry() –create object first, then enter data c() –concatenate scan() –prompted data entry R has ODBC for connecting to other programs

Data entry & editing start editor and save changes –data.entry(x) start editor, changes not saved –de(x) start text editor –edit(x)