Data & Graphing vectors data frames importing data contingency tables barplots 18 September 2014 Sherubtse Training.

Slides:



Advertisements
Similar presentations
Introduction to R Brody Sandel. Topics Approaching your analysis Basic structure of R Basic programming Plotting Spatial data.
Advertisements

R for Macroecology Aarhus University, Spring 2011.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Cross-Tabulation Tables Tables in R and Computing Chi Square.
Introduction to GTECH 201 Session 13. What is R? Statistics package A GNU project based on the S language Statistical environment Graphics package Programming.
Business Statistics: A Decision-Making Approach, 7e © 2008 Prentice-Hall, Inc. Chap 2-1 Business Statistics: A Decision-Making Approach 7 th Edition Chapter.
R for Research Data Analysis using R Day1: Basic R Baburao Kamble University of Nebraska-Lincoln.
Graphing With Excel Presented by Frank H. Osborne, Ph. D. © 2008 ID 2950 Technology and the Young Child.
Tinkerplots IV Carryn Bellomo
Introduction to Excel 2007 Bar Graphs & Histograms Psych 209 February 1st, 2011.
CS1100: Computer Science and Its Applications Creating Graphs and Charts in Excel.
Chapter 9 Creating Graphs in Illustrator. Objectives Create a graph Edit a graph using the Graph Data window Use the Group Selection tool Use the Graph.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Introduction to SPSS Short Courses Last created (Feb, 2008) Kentaka Aruga.
NU Data Excel Orientation Graphing of Screening Data and Basic Graphing Functions.
Lesson: 4 Spreadsheets After completing this lesson, you will be able to: Identify the components of a spreadsheet. Enter data into a spreadsheet. Perform.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Last Week Lightening Review Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Formulas – A formula of sorts, usually math based, which always.
Introduction to to R Emily Kalah Gade University of Washington Credit to Kristin Siebel for development of much of this PowerPoint.
Chemistry Basics Part 7 Ray Tedder NBC Chemistry Teacher.
Session 3: More features of R and the Central Limit Theorem Class web site: Statistics for Microarray Data Analysis.
Chapter 9 Creating and Designing Graphs. Creating a Graph A graph is a diagram of data that shows relationship among a set of numbers. Data can be represented.
A Picture Is Worth A Thousand Words. DAY 7: EXCEL CHAPTER 4 Tazin Afrin September 10,
Data Analysis Lab 02 Using Crosstabs to compare percentages.
R Programming Yang, Yufei. Normal distribution.
R packages/libraries Data input/output Rachel Carroll Department of Public Health Sciences, MUSC Computing for Research I, Spring 2014.
Introduction to Enterprise Guide Jennifer Schmidt Rhonda Ellis Cassandra Hall.
SPSS Instructions for Introduction to Biostatistics Larry Winner Department of Statistics University of Florida.
Creating Graphs in Illustrator
Graphing Tutorial William Hornick CS 101. Overview You will be given a brief description, example, and “how to create” for each of the following: You.
PowerPoint Lesson 6 Working with Tables and Charts Microsoft Office 2010 Advanced Cable / Morrison 1.
Excel Web App By: Ms. Fatima Shannag.
Chapter 2:Excel. Determining Results with the if Function =IF(logical_test, value_if_true,value_if_false) The IF function has three arguments: – A condition.
Introduction to R Introductions What is R? RStudio Layout Summary Statistics Your First R Graph 17 September 2014 Sherubtse Training.
Excel 2007 Part (3) Dr. Susan Al Naqshbandi
1. Tables, Charts, and Graphs Microsoft Word & Excel 2003.
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.
1 An Introduction to R © 2009 Dan Nettleton. 2 Preliminaries Throughout these slides, red text indicates text that is typed at the R prompt or text that.
1 MATERI PENDUKUNG TIPE DATA Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Use SPSS for solving the problems Lecture#21. Opening SPSS The default window will have the data editor There are two sheets in the window: 1. Data view2.
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 
Bullied as a child? Are you tall or short? 6’ 4” 5’ 10” 4’ 2’ 4”
Chapter 3 Graphs and Charts. Agenda Chart Object linking and embedding.
1 PEER Session 02/04/15. 2  Multiple good data management software options exist – quantitative (e.g., SPSS), qualitative (e.g, atlas.ti), mixed (e.g.,
1 Take a challenge with time; never let time idles away aimlessly.
Basics in R part 2. Variable types in R Common variable types: Numeric - numeric value: 3, 5.9, Logical - logical value: TRUE or FALSE (1 or 0)
EXCEL LESSON 12 CREATING CHARTS VOCABULARY. AXIS A line bordering the chart plot area used as a frame of reference for measurement.
Descriptive Statistics using R. Summary Commands An essential starting point with any set of data is to get an overview of what you are dealing with You.
An Introduction to Programming in Matlab Emily Blumenthal
Working with data in R 2 Fish 552: Lecture 3. Recommended Reading An Introduction to R (R Development Core Team) –
Module 4: Building Reports
DATA MANAGEMENT MODULE: Getting Data Into and Out of R
By Dr. Madhukar H. Dalvi Nagindas Khandwala college
Data, Data, Data.
Data, Data, Data.
TU170 Learning online and computing with confidence
Uploading and handling databases
REDCap Data Migration from CSV file
DATA MANAGEMENT MODULE: Getting Data Into and Out of R
ECONOMETRICS ii – spring 2018
Chapter 2 Describing Data: Graphs and Tables
Python I/O.
Module 5: Data Cleaning and Building Reports
Is a persons’ size related to if they were bullied
Categorical Data National Opinion Research Center’s General Social Survey In 2006 a sample of 1928 adults in the U.S. were asked the question “When is.
CSCI N317 Computation for Scientific Applications Unit R
Week 3 Lecture Notes PSYC2021: Winter 2019.
TransCAD Working with Matrices 2019/4/29.
Chapter 2 Excel Extension: Now You Try!
Presentation transcript:

Data & Graphing vectors data frames importing data contingency tables barplots 18 September 2014 Sherubtse Training

Data CLASSES in R Vector: a single string of data Factor: categorical data, stored as category levels with frequencies Matrix: 2D table of data Array: >2D table of data Data Frame: 2D table that can accept different data modes List: General structure for organizing all project data memory used (object.size)

Data MODES in R Character/String: letters and text in quotation marks Numeric/Integer: numbers Logical: TRUE, FALSE, T, F (must be capital letters, no quotes; converts to 0 & 1 for arithmetic)

Data Classes: Vectors VECTOR A single string of data of the same “mode” Examples: Numeric or Integer Mode x <- c(1, 0, -5, 10, 300) x <- c(2+2, 9-6, 5) x <- c(2.5, 3.9, 0.7, 4.0) numeric or integer mode (spaces are for easy reading) logical mode answer <- c(TRUE, FALSE, TRUE, TRUE) answer <- c(T, F, T, T) Examples: Logical Mode

Data Classes: Vectors VECTOR A single string of data of the same “mode” Examples: Character Mode character mode (single quotes also okay) animals <- c(“dog”, ”cat”, ”bird”) string <- c(“a”, ”c”, ”d”, ”z”, ”p”) answer <- c(“T”, “F”, “T”, “T”) values <- c(“-9”, “0.2”, “1.4”)

Working with Vectors Use subscripts to refer to elements of a vector: > x <- c(1, 0, -5, 10, 300) x[3] x[c(1, 4, 5)] x[-2] x[vector_position] x[1:4]

Logical Operators

Working with Vectors Edit the vector: > x <- c(1, 0, -5, 10, 300) Append (add) data to the end of the vector: Change a single value in the vector: x <- c(x, 400, 500, 700) # NOTE: Also try append() x[6] <- 90 Replace values > 100 with NA: NA 90 NA NA x[x>100]<-NA x[which(x>100)]<-NA # Also try replace()

Importing Data OPTION 1 Type data directly into R OPTION 2 Use job <- scan(what="character") to paste in the following data copied from an Excel column Import the ‘job’ column data (exclude column heading) from the ‘Work’ tab in Excel, and assign it the variable name ‘job’

How might we graph these data? Here's a hint... table(job)

For example, you can just create a vector with labels, then make a barplot of the vector, or put the vector directly in barplot: job.count <- c("farmer"=12, "government"=2, "laborer"=4, "teacher"=2)

Importing Data OPTION 3 Export the data as a csv- or tab-delimited text file, then import the text file into R Import the ‘HtWt’ dataset (notice how the data are arranged in Excel)

Data Classes: Data Frames DATA FRAMES A data frame is similar to the data format used in SPSS...different columns can have different modes (numeric, character, factor, etc.)

Working with Data Frames There are many way to refer to the elements in data frames... but we will focus on just a few To access the height column HtWt$cm HtWt[“cm”] HtWt[4]

Working with Data Frames To access a row HtWt[5,] To access an element HtWt[5,4]HtWt[5,”cm”]

What kinds of interesting questions can we ask? What graphs would we make to answer them? HtWt Data Is there a difference in height between UWICE & SFS personnel? Does it differ for males vs. females? Is there a difference in weight between UWICE & SFS personnel? Does it differ for males vs. females? Is there a relationship between height and weight for UWICE personnel? How about for SFS personnel? Is there a relationship between height and weight for males? How about for females?

Bar Plots For comparing COUNTS, PROPORTIONS (%) or MEANS of data in different qualitative categories. Often we make bar plots of summary data.

Use the table() function to create a contingency table of sample counts by INSTITUTE and SEX. Try it also using with() table(HtWt$institute,HtWt$sex) Working with Data Frames

Now make a stacked barplot from the table you just created

Add title, labels, legend and color...

Convert it to a side-by-side barplot

Move the legend to the top center ADD AS AN ARGUMENT: args.legend=list (horiz=T, x="top")

Transpose the data: t(tab.HtWt)

Working with Data Frames Use the function subset() to create a new data frame called ‘UWICE’ that includes only UWICE data UWICE <- subset(HtWt,institute=="UWICE") Now subset the HtWt data to get a data frame with only 'SFS' data and only the 'INSTITUTE' and 'SEX' columns. Call this data frame 'SFS.sex' SFS.sex <- subset(HtWt,institute=="SFS",select=1:2)

1)Install & load the package reshape2 2)Import the Livestock data and save it to a variable called farms 3)Use the function cast() to reformat the farms data to a matrix form for stacked barplots: m.farms<-acast(farms,town~livestock) 4) Make a stacked barplot from m.farms Reshaping Data

Make this graph—note that the y-axis values should be from 0 to 60