Book Image

Mastering Scientific Computing with R

Book Image

Mastering Scientific Computing with R

Overview of this book

Table of Contents (17 chapters)
Mastering Scientific Computing with R
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Basic matrix operations


It is important to first point out that computational operations can be done on both whole matrices, termed "matrixwise operations", and on the individual elements of a matrix, termed "element-wise operations". Matrix addition or subtraction is simply a matter of the addition of, or subtraction from, each individual value in a matrix to the value in the corresponding location in another matrix, so matrixwise and element-wise operations are the same. However, matrix multiplication is different from element-wise multiplication of elements within a matrix.

Let's start by creating a correlation matrix of our physical functioning data and creating an abbreviated raw data matrix:

cor.mat <- matrix(cor(phys.func), ncol = 20)
phys.brief.mat <- as.matrix(phys.func[c(1:30),])

This dataset is categorical rather than ordinal and is far from being normally distributed, but as we will discuss in this chapter, on the common factor model, this may still be a legitimate way to...