Naomi Altman Department of Statistics (Based on notes by J. Lee)

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.
Introduction to Matlab
Empirical Estimator for GxE using imputed data Shuo Jiao.
R Lecture 4 Naomi Altman Department of Statistics Department of Statistics (Based on notes by J. Lee)
R Lecture 5 Naomi Altman Department of Statistics.
Maths for Computer Graphics
Statistics 350 Lecture 16. Today Last Day: Introduction to Multiple Linear Regression Model Today: More Chapter 6.
Lecture 7 Sept 19, 11 Goals: two-dimensional arrays (continued) matrix operations circuit analysis using Matlab image processing – simple examples Chapter.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
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.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Stats & Linear Models.
A Presentation on the Implementation of Decision Trees in Matlab
1 Chapter 2 Matrices Matrices provide an orderly way of arranging values or functions to enhance the analysis of systems in a systematic manner. Their.
ECON 1150 Matrix Operations Special Matrices
Session 3: More features of R and the Central Limit Theorem Class web site: Statistics for Microarray Data Analysis.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
Statistics and Linear Algebra (the real thing). Vector A vector is a rectangular arrangement of number in several rows and one column. A vector is denoted.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
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.
Section Copyright © 2014, 2012, 2010 Pearson Education, Inc. Lecture Slides Elementary Statistics Twelfth Edition and the Triola Statistics Series.
MAT 2401 Linear Algebra 2.1 Operations with Matrices
S-PLUS Lecture 2 Jaeyong Lee Department of Statistics Pennsylvania State University.
Class Opener:. Identifying Matrices Student Check:
Scope When we create variables and functions, they are limited in where they are visible and where they can be referenced For the most part, the identifiers.
Factorial Analysis of Variance
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
PH24010 Data Handling and Statistics Use of MathCAD to handle statistical data Data storage in vectors and matrices MathCAD’s built-in functions: –Mean,
Matrix Algebra Section 7.2. Review of order of matrices 2 rows, 3 columns Order is determined by: (# of rows) x (# of columns)
Programming in R Managing Variables. Managing variables in R In this session I will show you how to: Rename, drop and keep variables Create new variables.
The median again The steps of our algorithm: Read the size of the list, N. Declare and instantiate an array of integers, "list". Read the elements of list.
For Loop Tips And Tricks
MA/CS 375 Fall 2002 Lecture 2. Motivation for Suffering All This Math and Stuff Try the Actor demo from
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Categorical Independent Variables STA302 Fall 2015.
S-PLUS Lecture 4 Jaeyong Lee Pennsylvania State University.
STA302: Regression Analysis. Statistics Objective: To draw reasonable conclusions from noisy numerical data Entry point: Study relationships between variables.
= the matrix for T relative to the standard basis is a basis for R 2. B is the matrix for T relative to To find B, complete:
Do Now: Perform the indicated operation. 1.). Algebra II Elements 11.1: Matrix Operations HW: HW: p.590 (16-36 even, 37, 44, 46)
4.1 An Introduction to Matrices Katie Montella Mod. 6 5/25/07.
1 Introduce to the Count Function and Its Applications Chang-Yun Lin Institute of Statistics, NCHU.
Chapter 14 Repeated Measures and Two Factor Analysis of Variance PowerPoint Lecture Slides Essentials of Statistics for the Behavioral Sciences Seventh.
ANOVA: Analysis of Variation
Umm Al-Qura University
S-PLUS Lecture 3 Jaeyong Lee.
13.4 Product of Two Matrices
Linear Programming Revised Simplex Method, Duality of LP problems and Sensitivity analysis D Nagesh Kumar, IISc Optimization Methods: M3L5.
ANOVA: Analysis of Variation
Introduction to Programming in MATLAB
Naomi Altman Department of Statistics (Based on notes by J. Lee)
Lecture 12. MLP (IV): Programming & Implementation
IE-432 Design Of Industrial Experiments
Numerical Descriptives in R
Lecture 12. MLP (IV): Programming & Implementation
Computer Vision Lecture 16: Texture II
Recoding III: Introducing apply()
Introduction to Matrices
Matrices Elements, Adding and Subtracting
Recoding III: Introducing apply()
CSCI N207 Data Analysis Using Spreadsheet
Chapter 8 Data Structures: Cell Arrays and Structures
MATRICES MATRIX OPERATIONS.
Non-parametric Analysis of the Variance in SAS®
Islamic University of Gaza
Maths for Signals and Systems Linear Algebra in Engineering Lectures 13 – 14, Tuesday 8th November 2016 DR TANIA STATHAKI READER (ASSOCIATE PROFFESOR)
Derivation of the 2D Rotation Matrix
Matrices.
Lecture 2 General Problem
General Computer Science for Engineers CISC 106 Lecture 11
Presentation transcript:

Naomi Altman Department of Statistics (Based on notes by J. Lee) R Lecture 3 Naomi Altman Department of Statistics (Based on notes by J. Lee)

Intrinsic Attributes: mode and length Every object in R has two attributes, mode and length. The mode of an object says what type of object it is. The function attributes(x) gives all non-intrinsic attributes of x. There is a special attribute called class which was introduced to enhance object-oriented programming. We will talk about this later.

Session: Intrinsic Attributes x=rnorm(100,3,2) t.out=t.test(x,mu=1) attributes(x) class(x) attributes(t.out) length(t.out) class(t.out) names(t.out) t.out[[1]] t.out$conf t.out #printing is affected by the class unclass(t.out)

Factors A factor is a special type of vector, normally used to hold a categorical variable in many statistical functions. Factors are primarily used in Analysis of Variance (ANOVA). When a factor is used as a predictor variable, the corresponding indicator variable are created.

Session: Factors citizen <- c("uk", "us", "no","au","uk","us", "us","no","au") citizenf <- factor(citizen) citizen citizenf attributes(citizenf) unclass(citizenf) table(citizenf)

"apply" and its relatives Often we want to repeat the same function on all the rows or columns of a matrix, or all the elements of a list. We could do this in a loop, but R has a more efficient operator the apply function

Applying a function to the rows or columns of a matrix If mat is a matrix and fun is a function (such as mean, var, lm ...) that takes a vector as its arguments, then apply(mat,1,fun) applies fun to each row of mat apply(mat,2,fun) applies fun to each column of mat In either case, the output is a vector.

Relatives of apply lapply(list,fun) applies the function to every element of list tapply(x,factor,fun) uses the factor to split x into groups, and then applies fun to each group

Using apply and related functions data() #a list of internal data sets ?trees class(trees) class(trees$Girth) class(trees$Height) class(trees$Volume) apply(trees,2,mean) lapply(trees,mean)

?ChickWeight tapply(ChickWeight$weight,ChickWeight$Chick,mean) weight.byChick=split(ChickWeights$weight,ChickWeights$Chick) weight.byChick lapply(weight.byChick,mean)