Attribution Non-Commercial (BY-NC)

29K views

Attribution Non-Commercial (BY-NC)

- Linear Algebra For Dummies Cheat Sheet - For Dummies.pdf
- Getting Started With MATLAB - David Hart
- Letters to Irena
- Final ch 25
- Trace of a Square Matrix in R
- Derive 6
- Matlab
- Matlab Tutorial
- NCERT Solutions Class 12 Math Chapter 3 Matrices
- A Plic Matrices
- The Network of Global Corporate Control
- File
- 1909.00014
- BITSAT Table of Contents
- 6 Straasens
- Introduction to Matlab Application to Electrical Engineering Part II
- scheme of work form 5 2008.doc
- Matlab Guide
- Presentation Optimization 2-Libre
- a344928.pdf

You are on page 1of 4

This document is designed to introduce matrix calculations useful for statistics. It assumes some

familiarity with R. Those meeting R for the first time should go through guides such as “Using

R in Windows XP on the ISS network” and “The R Language - Basics”.

1. Vectors are the key variables within R. They are most easily constructed using the “com-

bine” c(·) function; e.g. x = c(1,2,4,5) creates a vector x of length 4 with elements

1,2,4,5. Matrices are variables represented as 2-way arrays of numbers. They are most eas-

ily created from vectors using the matrix() function:

1 4

x = matrix(c(1,2,3,4,5,6), nrow = 3) yields 2 5

3 6

1 2

x = matrix(c(1,2,3,4,5,6), nrow = 3, byrow = T) yields 3 4

5 6

In each case a vector of length 6 is turned into a 3 × 2 matrix. You can specify nrow=3 or

ncol=2 or both; all three choices are equivalent. The vector fills up the matrix in successive

columns unless “byrow = T” is specified, in which case the matrix is filled up by successive

rows.

2. rbind and cbind are functions which can combine matrices columnwise or rowwise. If x

and y contain the matrices " # " #

1 2 5 6

and ,

3 4 7 8

then cbind(x,y) and rbind(x,y) contain the matrices

1 2

" #

1 2 5 6 3 4

and ,

3 4 7 8 5 6

7 8

in rbind.

September 2002 1

The Statistical Language R - Matrices

3. Subsets. Elements or blocks of elements of vectors and matrices can be picked out using

square brackets. If x is a vector and y is a matrix, then

x[3] element 3 of x

first 3 elements

from row 5, column 6

containing rows 1,2 and columns 2,3

1. In general, operations on vectors and matrices act elementwise. If x and y are n×m matrices,

then x+y and x∗y are n × m matrices with elements x[i,j] + y[i,j], and x[i,j]∗y[i,j],

respectively. See below for “proper” matrix multiplication. If a is a scalar, a∗x has compo-

nents a x[i,j].

2. Matrix addition. If x and y are n × m matrices, then the matrices x+y and x-y make sense

and are evaluated elementwise. If a is a scalar, a+x and a∗x are n×m matrices with elements

a+x[i,j] and a∗x[i,j].

the matrix product with elements m

P

j=1 x[i, j] ∗ y[j, k]. There are also some special cases

involving vectors. In an expression involving a matrix and a vector, the vector is interpreted

as either a row vector or a column vector, whichever makes the multiplication legitimate.

• If x is an n × m matrix and y is a vector of length m, x%∗%y is a vector of length m.

September 2002 2

The Statistical Language R - Matrices

representing the inner product m

P

i=1 x[i]∗y[i].

giving the inverse of a. If b is a vector of length n, solve(a,b) gives the matrix product of

the inverse of a times b.

wise inverse of a. This is very different from the matrix inverse of a !

• If a is a positive integer scalar (e.g. 5) then diag(a) is a 5 × 5 matrix with ones down

the diagonal and zeros elsewhere.

• If a is a vector of length n, diag(a) is an n × n diagonal matrix with (i, i)th element

a[i].

• If a is an n × n matrix, diag(a) is a vector containing the diagonal elements a[i,i],

i = 1, . . . , n.

C. Plotting

matplot(x, col=1)

plots each variable in an n × p data matrix vs 1:n. The ith variable in the plot is labelled i,

i = 1, . . . , p. Remove the option col=1 to see each variable in a different colour.

image(x,col=gray((0:32)/32)) # draws a grayscale image

contour(x, add = TRUE, drawlabels = FALSE) # overlays a contour plot

September 2002 3

The Statistical Language R - Matrices

There are 3 main structures in R: vectors, matrices and data frames. Recall that data frames are

typically obtained from external data files using the read.table command. Let av,am, adf be

a vector, a matrix, and a data frame, respectively. Here are some commands to manipulate them.

• If $dim is defined and contains one number (the length), then a is a vector. The

function length(av) gives the length of the vector av.

• If $dim is defined and contains two numbers (nrow and ncol), then a is a matrix. The

functions nrow(am), ncol(am) give the numbers of rows and columns of the matrix

am.

• If $class is defined and contains the value ‘‘data.frame’’, then a is a data frame.

2. matrix(av) or matrix(av, ncol=1) converts the vector av to a matrix with one column.

Similarly, matrix(av, nrow=1) or the transpose t(av) converts av to a matrix with one

row.

5. If the matrix am has only one column or one row, then as.vector(am) turns it into a vector.

This document was produced by R.G. Aykroyd but was previously the second part of the notes

The Statistical Language R, by J.T. Kent.

September 2002 4

- Linear Algebra For Dummies Cheat Sheet - For Dummies.pdfUploaded bykamayani_pr
- Getting Started With MATLAB - David HartUploaded byapi-3696482
- Letters to IrenaUploaded byallison
- Final ch 25Uploaded bysammy_stuff1
- Trace of a Square Matrix in RUploaded byAnkit Dangi
- Derive 6Uploaded byFlavio Bacelar
- MatlabUploaded byJeremy Byers
- Matlab TutorialUploaded bydoebook
- A Plic MatricesUploaded byELKIN DIAZ
- NCERT Solutions Class 12 Math Chapter 3 MatricesUploaded byVidyakul
- The Network of Global Corporate ControlUploaded bySorg84
- FileUploaded byPiyush Sood
- 1909.00014Uploaded byGaston GB
- BITSAT Table of ContentsUploaded byhrishi0000
- 6 StraasensUploaded byBanwari Lal Meena Lalsot
- Introduction to Matlab Application to Electrical Engineering Part IIUploaded byTrương Đức
- scheme of work form 5 2008.docUploaded bymfkhairi
- Matlab GuideUploaded byanant_nimkar9243
- Presentation Optimization 2-LibreUploaded byNhan Tran
- a344928.pdfUploaded byb4suki
- Octave BasicsUploaded bySanjayan PradeepKumar
- all std 1.rtfUploaded byProvakar Biswas
- Quintic_BOEF.pdfUploaded byodormicchi
- Mathematics 2008 Unsolved Paper Outside Delhi.pdfUploaded bysagar
- Prueba Con Csb MatixUploaded byElvira Rod
- Add Subtract and Multiply MatricesUploaded byCesar Puga Campos
- Week-11(Chain Matrix Multi)Uploaded byTanzeel Mirza
- Basics of MATLABUploaded byromeo
- fps_2013_slides.pdfUploaded bysankar
- Quantitative techniquesUploaded byVivek Sharma

- Model- vs. design-based sampling and variance estimationUploaded byFanny Sylvia C.
- ReviewChaps3-4Uploaded byFanny Sylvia C.
- SampleSizeCalcRevisitedUploaded byFanny Sylvia C.
- ReviewChaps1-2Uploaded byFanny Sylvia C.
- Hypo%26PowerLectureUploaded byFanny Sylvia C.
- Non%26ParaBootUploaded byFanny Sylvia C.
- Chapter 21Uploaded byFanny Sylvia C.
- Chapter 20Uploaded byFanny Sylvia C.
- Chapter 14Uploaded byFanny Sylvia C.
- Chapter 13Uploaded byFanny Sylvia C.
- Chapter 12Uploaded byFanny Sylvia C.
- Chapter 11Uploaded byFanny Sylvia C.
- Chapter 8Uploaded byFanny Sylvia C.
- Chapter 10Uploaded byFanny Sylvia C.
- Chapter 9Uploaded byFanny Sylvia C.
- Chapter 5Uploaded byFanny Sylvia C.
- Chapter 6Uploaded byFanny Sylvia C.
- Chapter5p2LectureUploaded byFanny Sylvia C.
- Chapter 7Uploaded byFanny Sylvia C.
- An Ova PowerUploaded byFanny Sylvia C.
- Intro BootstrapUploaded byMichalaki Xrisoula
- Good Article on Standard Error vs Standard DeviationUploaded byAshok Kumar Bharathidasan
- Data Modeling: General Linear Model &Statistical InferenceUploaded byFanny Sylvia C.
- Bio Math 94 CLUSTERING POPULATIONS BY MIXED LINEAR MODELSUploaded byFanny Sylvia C.
- GRM: Generalized Regression Model for Clustering Linear SequencesUploaded byFanny Sylvia C.
- Clustering in the Linear ModelUploaded byFanny Sylvia C.
- The not so Short Introduction to LaTeXUploaded byoetiker
- Close Out NettingUploaded byFanny Sylvia C.

- Albert Leuchten Catalogue 13-14 - GBUploaded byOxana Gritsanchuk
- ss.pdfUploaded byKarthik Acharya
- FrSky X6R ManualUploaded bymaodesus
- Introduction to Practical Web DevelopmentUploaded byMohammad Rahman
- Kaltwasser n Uwd Sb 13 Wellhead System Dea PresentationUploaded byNorberto Escobar Morales
- MDSR: An Approach to Secure DSR Routing ProtocolUploaded byJournal of Computing
- Neutov Article 2014Uploaded byZarr Aksh
- Demand TheoryUploaded byAkshay Thapar
- tda7266.pdfUploaded byRenato Hernandez
- Striplight Ej PDFUploaded byThomas Martin
- Laser Physics Chapter 1Uploaded byAlexander Mints
- Comsol42a_Update1Uploaded byLuis Lozoya
- Catalog Fo NetvielUploaded byilhamix
- ASTM-A501Uploaded bySra R Gil
- User Defined Functions in TDLUploaded byvenkatesh_finance
- 62126 ID Analisis Pengaruh Harga Promosi Dan PelaUploaded byEfdi Derian
- KOC-G-004_Rev1 - Packing, Marking & Documentation.pdfUploaded by911targa
- OBIEE Applications - Set-Up and Usage of DAC and a LogsUploaded byFiacre Kramo
- Manipulation and Biological Applications of Gold NanorodsUploaded byIam
- WI 19 Pre-FV Version PrEN 15242 Ventilation Calculation Air Flow RatesUploaded byPedro Leite
- Rules of Calculus - Functions of One VariableUploaded byafjkjchhghgfbf
- rbbbUploaded byAnum Ahmed
- SECSE-1.pptUploaded byShamim H Ripon
- Solution for Exam 1Uploaded byKim Howard Castillo
- Introduction (MEOR)Uploaded byMaqsood Iqbal
- Eagle System Overview R41.1Uploaded byTien Hoang
- Hitachi Compute Blade 500 WhitepaperUploaded byPrasadVallura
- CADCAM IntroductionUploaded byscm_2628
- Ocean CurrentsUploaded byRigel Nath
- info_iec61000-3-7{ed2.0}en.pdfUploaded byPaul Davidson

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.