Here we will introduce a geometric interpretation of the equations. This will give a more intuitive interpretation of what is going on.
A vector is both an arrow and a row of numbers — and a gene-expression profile is a vector.
Adding and scaling vectors.
The length (norm) of a vector.
The dot product: one number that measures how two vectors line up.
The dot product gives the angle between vectors → cosine similarity, commonly used to compare high-dimensional samples (e.g. single-cell data later on)
Orthogonality (a right angle = zero dot product).
Projection: the shadow of one vector on another.
A gene-expression profile is a vector
Measure the expression of 3 genes in one tissue sample:
\mathbf{x} = \begin{pmatrix} 12 \\ 0 \\ 7 \end{pmatrix} \quad \begin{array}{l}\text{(Gene A = 12)}\\\text{(Gene B = 0)}\\\text{(Gene C = 7)}\end{array}
A vector is just an ordered list of numbers. Here, 3 numbers → one point/arrow in 3-D space.
A real RNA-seq sample has ~20 000 genes → a vector in 20 000-dimensional space. We cannot draw it, but every rule we learn in 2-D and 3-D still holds.
Two ways to read the same object:
as data: “this sample’s measurements”
as an arrow: from the origin to the point (12, 0, 7).
Vectors as arrows
In 2-D, the vector \mathbf{v} = \begin{pmatrix} 3 \\ 2 \end{pmatrix} is the arrow from the origin to the point (3, 2).
The numbers are the components: move 3 right, 2 up.
An arrow has a direction and a length.
We can slide the arrow around, but by convention we draw it starting at the origin.
# In R a vector is the most basic objectv <-c(3, 2)v# [1] 3 2
Geometrically: place the tail of the second arrow at the head of the first (“tip-to-tail”).
Biological reading: if \mathbf{x} is a baseline profile and \mathbf{d} is the change after a drug, then \mathbf{x} + \mathbf{d} is the treated profile.
c(3, 2) +c(1, 4)# [1] 4 6
Scaling changes a vector’s length, not its direction
A scalar > 1stretches the arrow; between 0 and 1 shrinks it; negative flips it.
Scaling never changes the direction (except the flip) — only the length.
Biological reading: doubling a library’s sequencing depth scales the whole count vector by ~2; normalisation is exactly choosing a scalar to make samples comparable.
2*c(3, 2)# [1] 6 4
A vector’s length (norm) comes from Pythagoras
The length (or norm) of \mathbf{v} comes straight from Pythagoras:
This is cosine similarity — it ranges from -1 to 1 and ignores overall magnitude (it only cares about direction).
Commonly used in biology: two samples of the same cell type have similar shapes of expression, because the ratios of molecules are the same. This compensates for differences in sequencing depth in RNA-seq. Euclidean distance keeps the depth difference.
cos_sim <-function(u, v) sum(u*v) / (sqrt(sum(u^2)) *sqrt(sum(v^2)))cos_sim(c(12,0,7), c(6,0,3.5)) # 1 -> same direction, different depth
Vectors at a right angle have a dot product of zero
Two vectors are orthogonal (perpendicular) when their dot product is zero:
Orthogonal directions carry independent information — no overlap.
This idea is important for PCA later on (the principal components are orthogonal axes).
sum(c(2,0) *c(0,5)) # 0 -> perpendicular
Projection: the shadow of one vector on another
The projection of \mathbf{u} onto \mathbf{v} is the shadow \mathbf{p} that \mathbf{u} casts on the line through \mathbf{v} (imagine light coming straight down):