STAT 251 Lab 1. Outline Lab Accounts Introduction to R.

Slides:



Advertisements
Similar presentations
Basics of Biostatistics for Health Research Session 2 – February 14 th, 2013 Dr. Scott Patten, Professor of Epidemiology Department of Community Health.
Advertisements

Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
 Statistics package  Graphics package  Programming language  Can be used to share/reproduce analyses  Many new packages being created - can be downloaded.
Introduction to GTECH 201 Session 13. What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming.
Introduction to UNIX Working in a multi-user environment.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
CIS101 Introduction to Computing Week 05. Agenda Your questions CIS101 Survey Introduction to the Internet & HTML Online HTML Resources Using the HTML.
Creating First Class Web Pages Log into your account.
CPSC 203 Introduction to Computers Lab 21, 22 by Jie (Jeff) Gao Location: ES650.
Go to our website, and click on the eMedia Catalog link To find books, either click on the advanced search (which I will.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
AP Statistics Chapters 0 & 1 Review. Variables fall into two main categories: A categorical, or qualitative, variable places an individual into one of.
Matlab tutorial course Lesson 2: Arrays and data types
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
Introduction to MATLAB
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.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
Download Dropbox Download should start immediately Save download file:
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.
Section 3 Calculations National 4/5 Scratch Course.
Math 15 Lecture 7 University of California, Merced Scilab A “Very” Short Introduction.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Instructors begin using McGraw-Hill’s Homework Manager by creating a unique class Web site in the system. The Class Homepage becomes the entry point for.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
1 ITI 1120 Lab # 1 An Introduction to the Lab Environment Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
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.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Central Tendency and Variability Chapter 4. Variability In reality – all of statistics can be summed into one statement: – Variability matters. – (and.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
To access our web services, go to……. Click on Customer Login.
Scientific Computing Introduction to Matlab Programming.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Downloading and Installing Autodesk Inventor Professional 2015 This is a 4 step process 1.Register with the Autodesk Student Community 2.Downloading the.
(PubMed) MY NCBI (Advanced Course: Module 2). Table of Contents  How to register and sign into MY NCBI  Setting up filters in MY NCBI  Saving searches.
Chapter Three The UNIX Editors.
CPSC 203 Introduction to Computers T43, T46 & T68 TA: Jie (Jeff) Gao.
Student Quick Start Guide Prepared by: Information Services Division Perpustakaan Sultan Abdul Samad Universiti Putra Malaysia
MySQL Getting Started BCIS 3680 Enterprise Programming.
STAT 534: Statistical Computing Hari Narayanan
A user guide to accessing, reviewing and contributing to the Online Registry System.
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.
For the benefit of business and people Lotus Notes R6 Training 4 February 2016 IT Division.
Creating a Form. Accessing Docs Log into your USD 465 Google Account Click on the “Documents” link at the top of.
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.
Lecture 11 Introduction to R and Accessing USGS Data from Web Services Jeffery S. Horsburgh Hydroinformatics Fall 2013 This work was funded by National.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
MySQL Getting Started BCIS 3680 Enterprise Programming.
Physics 114: Lecture 1 Overview of Class Intro to MATLAB
Logging Into Windows XP for first time (labs only!)
Getting started with Stata
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Guide To UNIX Using Linux Third Edition
Introduction to Summary Statistics
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Stat 251 (2009, Summer) Lab 1 TA: Yu, Chi Wai.
Computer Basics.
Warm Up # 3: Answer each question to the best of your knowledge.
Stat 251 (2009, Summer) Lab 2 TA: Yu, Chi Wai.
Data analysis with R and the tidyverse
Presentation transcript:

STAT 251 Lab 1

Outline Lab Accounts Introduction to R

Session L1E : Th LSK 121 Session L1F : Th LSK 121 TA : Eric  people Course Website:  2009   Summer Term 1 and 2   STAT251

Lab Account Select any one of the Window 2000 server Press Ctrl+\ and return to the ezConnect Manager if you are in a Unix login page. User name: First 8 letter of your full name registered at UBC e.g. Steven Jason Greenly  stevenja Simply use you full name if it is fewer than 8 letters Password: “S” + first 7 digits of your student ID number e.g. UID:  S *Capital letter “S”

Lab Account CHANGE YOUR PASSWORD once you have logged in Press Ctrl+Alt+Del That would bring you back to the Window login page Option at bottom right for changing password. Please come to the front with your student card for help if you have any problems with the computer.

Introduction to R

R : a free statistical programming language Q: Why do I need to learn [R] A: assignments will require the use of this software! A: don’t want to do tedious calculation by hand!

Introduction to R Downloading R: Available at Or, simply google [R], it should appear as the first hit

Introduction to R Click open [R] from your desktop Icon : The R-console

Introduction to R R : Object Oriented Programming (OOP) language We play around with “Objects” / ”Variables” e.g. Vectors, Matrices, Dataframes 3 Components of an Object: Name Class e.g. numeric, character Information

Introduction to R How to create vectors

Function : c() “c” stands for concatenation most primitive way to create a vector e.g. >c(1, 2, 3)numeric data [1] Integers >c(‘a’, ‘b’, ‘c’)nonnumeric data [1] “a” “b” “c”- Characters

Creating Vectors Q : I want to use the same vector again… A : Give it a name and store it as a variable!

Creating Vectors Assignment operator <-OR = e.g. >myvect <- c(1, 2, 3, 4, 5, 6, 7) OR >myvect = c(1, 2, 3, 4, 5, 6, 7)

Creating Vectors Now recall the variable myvect >myvect [1] *Variable name starts with letters contains letters, numeric and period “.” only CASE SENSITIVE!

Creating Vectors Other functions to create a vector…

Function : the colon x:y creates a sequence x:y starts from x, increases by 1 up to y e.g. >myvect2 <- 8:14 >myvect2 [1]

Creating Vectors Q : How about a sequence of odd numbers?

More flexible way to create sequence seq(x, y, k) Starts from x Increase by k up to y e.g. >myvect3 <- seq(1, 14, 2) >myvect3 [1] Function : seq()

Function : rep() “rep” stands for replicate rep(x, b) A vector consists of b replicates of x e.g. >rep(0, 5) [1] >rep( c(1, 2), 2) [1] >rep(‘a’, 3) [1] “a” “a” “a”

Introduction to R Combining vectors

Combining Vectors Recall that the function c() links data together e.g. >combine <- c(myvect, myvect2) >myvect [1] >myvect2 [1] >combine [1]

Introduction to R Manipulating vectors

Vector manipulation The square brackets [ ] are most oftenly used e.g. To select the 2 nd element in combine >combine[2] [1] 2

Vector manipulation e.g. To select from the 2 nd up to the 5 th elements >combine[2:5] [1]

Vector manipulation e.g. To drop the 3 rd element >combine[ -3 ] [1]

More examples

Vector manipulation e.g. To select from the 1 st, 5 th and then 4 th elements >combine[ c(1, 5, 4) ] [1] 1 5 4

Vector manipulation e.g. To drop the 2 nd, 3 rd and then 5 th elements >combine[ -c(2, 3, 5) ] [1]

Introduction to R Basic Mathematical Functions in R

Basic math functions # addition 2 – 3# substraction 2 * 3 # multiplication 2 / 3 # division 2 ^ 3 # power log( 5 ) # natural logarithms sqrt( 2 ) # square root exp( 0.2 ) # exponential function abs( -7 ) # absolute value

Basic math functions When applied to a vector, the values are evaluated element-wise e.g. >myvect [1] >myvect^2 [1]

Basic math functions We can also add, subtract, or multiply two or more vectors of the same length e.g. >myvect [1] >myvect2 [1] >myvect + myvect2 [1]

Caution! Multiplying Vectors

Basic math functions Instead of returning the inner product, the operator * multiplies vectors element-wise e.g. >myvect [1] >myvect2 [1] >myvect * myvect2 [1]

Advanced & Optional

Basic math functions To calculate the inner product operator : %*% e.g. >myvect %*% myvect2 [1] 336 Remark : the data returned is no longer a vector of the same length

Basic math functions Again, if you want to reuse the results, store it to a new variable!

Introduction to R Basic Statistical Functions in R

Basic stat functions sum()#Total sum mean()#Mean median()#Median var()#Variance sd()#Standard Deviation max()#Maximum min()#Minimum range()#Range quantile()#Quantiles (for find IQR) summary()#Similiar to quantiles()

Basic stat functions [R] actually has a command call IQR() Its function is self-explanatory, isn’t it?

Basic Statistical Functions in R Review of basic statistics

Measure of location / central tendency Mean, Median Measure of spread / dispersion Variance, IQR * IQR = 3 rd quantile – 1 st quantile which a number, not an interval !!!

Introduction to R Graphics in R

A picture is worth a thousand words

Visualize data by graphs!

Graphics Scatterplot Boxplot Boxplot Histogram Histogram Pay special attention to the last two as they are important for analyzing data for distributions and outliers (To be continued in Lab2)

Scatterplot Function : plot(x, y) plot each value in the dataset based on sequential order e.g. >x <- rnorm(20) >y <- 3*x + rnorm(20) >plot(x, y) Generate 20 data randomly from normal distribution. Will cover this function in later stage Graphics

Attention ! The computers in this lab response slow when the R graphic device is on. Close the graphics device or save the plot if they will be reused You can save your file in the Z: drive Files stred in other places will be deleted when you log out

Graphics Histogram Function : hist(x) Plot a histogram of data x e.g. >hist(x)

Graphics Boxplot Function : boxplot(x) Generate a boxplot of data x e.g. >boxplot(x)

Median 3 rd quartile 1 st quartile Potential outlier

Introduction to R Quitting and saving your data in R

Saving and Quitting To quit Command : q()OR Click on the “x” on the top right hand corner of the R console

Saving and Quitting You will see a prompt “Save workspace image?” Click “Yes” if you want to save the variables

Yet, your syntax would not be saved!!!

SOLUTIONS

Saving the syntax 1. Type you syntax in a word editor, e.g notepad. Copy and paste to the R to run the commands. 2. In [R], click File  New script Type in the R editor, highlight and press Ctrl+R to run the selected part. OR Copy and Paste To save the scripts, click to activate the editor window, then File  Save

Introduction to R Searching Help for R commands

Help! R help files from web Check the r-project website R Books See the posted lab

Wake up

Bring this home.

R help system

HELP! You want additional information about a particular function, say read.table() Use “?” or command help() e.g. >?read.table >help(read.table)

Pops up the [R] help document

Let’s call it a day~