Skip to main content

Covariance and Correlation: Formula, Examples, X^T*X and X*X^T


Covariance vs Correlation: Difference, Formula, Examples and Comparison

Introduction

Covariance and correlation are two important statistical concepts used to measure the relationship between two variables.

They help answer questions such as:

  • Does advertising increase sales?
  • Does study time affect exam marks?
  • Are height and weight related?

Although both measure relationships between variables, covariance and correlation have important differences in interpretation and usage.

What is Covariance?

Covariance measures the direction in which two variables change together.

$$ Cov(X,Y)= \frac{\sum(X_i-\bar X)(Y_i-\bar Y)} {n} $$

Interpretation of Covariance

Positive Covariance

When:

$$ Cov(X,Y)>0 $$

Both variables increase or decrease together.

Negative Covariance

$$ Cov(X,Y)<0 div="">

One variable increases while the other decreases.

Zero Covariance

$$ Cov(X,Y)=0 $$

There is no linear relationship between variables.

What is Correlation?

Correlation measures both the direction and strength of the relationship between two variables.

$$ r= \frac{Cov(X,Y)} {\sigma_X\sigma_Y} $$

Correlation always lies between:

$$ -1\leq r\leq1 $$
Correlation Value Meaning
+1 Perfect positive relationship
0 No linear relationship
-1 Perfect negative relationship

Covariance vs Correlation: Main Differences

Feature Covariance Correlation
Purpose Shows direction Shows direction and strength
Range -∞ to +∞ -1 to +1
Units Has units No units
Scale Effect Affected by scale Not affected by scale
Standardized No Yes

Numerical Example: Covariance and Correlation

Consider:

$$ X=\{1,2,3,4,5\} $$ $$ Y=\{50,55,65,70,80\} $$

Step 1: Calculate Mean

$$ \bar X=3 $$ $$ \bar Y=64 $$
X Y X-X̄ Y-Ȳ Product
1 50 -2 -14 28
2 55 -1 -9 9
3 65 0 1 0
4 70 1 6 6
5 80 2 16 32

Covariance

$$ Cov(X,Y)=\frac{75}{5} $$ $$ \boxed{Cov(X,Y)=15} $$

Correlation

$$ r= \frac{15} {\sqrt2 \times \sqrt{114}} $$ $$ \boxed{r\approx0.99} $$

The result shows a very strong positive relationship between study hours and exam marks.

Real-Life Applications

Applications of Covariance

  • Stock market return analysis
  • Economic studies
  • Weather and energy consumption analysis

Applications of Correlation

  • Machine learning feature selection
  • Medical research
  • Business analytics
  • Predictive modelling

Final Conclusion

Covariance and correlation are related statistical tools but they provide different information.

  • Covariance tells whether two variables move together.
  • Correlation tells how strongly two variables are related.
  • Covariance depends on measurement units.
  • Correlation is standardized and always ranges between -1 and +1.
$$ Correlation= \frac{Covariance} {Standard\ Deviation_X \times Standard\ Deviation_Y} $$

In practical data analysis, correlation is usually preferred because it allows comparison between different datasets.


Understanding XXáµ€ and Xáµ€X in Correlation and Covariance

Many statistics and machine learning books use expressions like XXáµ€ and Xáµ€X when explaining covariance, correlation, and data matrices.

These expressions can look confusing at first, but they are simply matrix multiplications used to calculate relationships between data points and variables.

1. What Does XXáµ€ Mean?

Consider a row vector:

$$ X= \begin{bmatrix} 1&2&3 \end{bmatrix} $$

The transpose of X is:

$$ X^T= \begin{bmatrix} 1\\ 2\\ 3 \end{bmatrix} $$

Now multiply:

$$ XX^T= \begin{bmatrix} 1&2&3 \end{bmatrix} \begin{bmatrix} 1\\ 2\\ 3 \end{bmatrix} $$

This becomes:

$$ XX^T=1^2+2^2+3^2 $$ $$ =1+4+9 $$ $$ \boxed{XX^T=14} $$

This is the dot product of the vector with itself.

2. What Does Xáµ€X Mean?

Now consider X as a column vector:

$$ X= \begin{bmatrix} 1\\ 2\\ 3 \end{bmatrix} $$

Its transpose is:

$$ X^T= \begin{bmatrix} 1&2&3 \end{bmatrix} $$

Multiplication gives:

$$ X^TX= \begin{bmatrix} 1&2&3 \end{bmatrix} \begin{bmatrix} 1\\ 2\\ 3 \end{bmatrix} $$ $$ =1^2+2^2+3^2 $$ $$ \boxed{X^TX=14} $$
Important: For a single vector, $$ XX^T=X^TX $$ The difference appears when X is a matrix containing multiple variables.

3. How Xáµ€X is Used in Correlation

Correlation can be calculated using:

$$ r= \frac{X^TY} {\sqrt{X^TX}\sqrt{Y^TY}} $$

The data must first be centered by subtracting the mean.

Numerical Example

Consider two variables:

$$ X= \begin{bmatrix} 1\\ 2\\ 3 \end{bmatrix} $$ $$ Y= \begin{bmatrix} 2\\ 4\\ 6 \end{bmatrix} $$

Step 1: Calculate Xáµ€Y

$$ X^TY= \begin{bmatrix} 1&2&3 \end{bmatrix} \begin{bmatrix} 2\\ 4\\ 6 \end{bmatrix} $$ $$ =1(2)+2(4)+3(6) $$ $$ =2+8+18 $$ $$ \boxed{X^TY=28} $$

Step 2: Calculate Xáµ€X

$$ X^TX= 1^2+2^2+3^2 $$ $$ =1+4+9 $$ $$ \boxed{X^TX=14} $$

Step 3: Calculate Yáµ€Y

$$ Y^TY= 2^2+4^2+6^2 $$ $$ =4+16+36 $$ $$ \boxed{Y^TY=56} $$

Step 4: Calculate Correlation

$$ r= \frac{28} {\sqrt{14}\sqrt{56}} $$ $$ r=1 $$
Result: $$ \boxed{r=1} $$ This indicates a perfect positive correlation between X and Y.

4. Why Do Books Use XXáµ€?

In machine learning, data is often stored as a matrix.

Example:

$$ X= \begin{bmatrix} x_1&y_1\\ x_2&y_2\\ x_3&y_3 \end{bmatrix} $$

Here each row represents an observation.

When we calculate:

$$ X^TX $$

we get:

$$ \begin{bmatrix} \sum x^2&\sum xy\\ \sum xy&\sum y^2 \end{bmatrix} $$

The term:

$$ \sum xy $$

is the important part used in covariance and correlation.

5. Simple Memory Trick

Expression Meaning
Xáµ€X Relationship between variables/features
XXáµ€ Relationship between observations/samples
Covariance Uses centered data products
Correlation Normalized covariance
  • XXáµ€ and Xáµ€X are matrix operations.
  • They are used as building blocks for covariance calculations.
  • Correlation is obtained by normalizing covariance.
  • The difference between XXáµ€ and Xáµ€X depends on whether samples are stored as rows or columns.
$$ Correlation= \frac{Covariance} {Standard\ Deviation_X \times Standard\ Deviation_Y} $$


Contact Us

Name

Email *

Message *

Popular Posts

Hybrid Beamforming | Page 1

Beamforming Techniques Hybrid Beamforming... Page 1 | Page 2 | Hybrid Beamforming: Hybrid beam formation was developed to address some of the limitations of digital pre-coding approaches. Every antenna element is connected to an RF chain in digital pre-coding (beam forming) method. We also know that each RF chain is in charge of providing a separate data stream between the transmitter and the receiver. We know that a larger number of independent data streams leads to higher data rates. It has a spatial multiplexing feature for MIMO. As a result, we may assume that switching from MIMO to massive MIMO will benefit us more in terms of spatial multiplexing in massive MIMO, where each antenna is coupled to a single RF chain. We'll proceed with a definition of hybrid beam forming. Overview of hybrid beam forming with example: Unlike digital beam forming, more than one antenna element is connected to a single RF chain in hybr...

Amplitude Shift Keying (ASK) Modulation & Demodulation (with Simulation)

Amplitude Shift Keying (ASK): Signal Analysis and Characterization Theoretical Overview: Amplitude Shift Keying (ASK) represents a primary digital modulation technique wherein information is encoded through discrete variations in the carrier signal's instantaneous amplitude. In a Binary ASK (BASK) framework, the modulation process maps binary data onto two distinct amplitude levels. Specifically, the binary '1' (mark) is conveyed by a sinusoidal carrier with amplitude A c and frequency f c over a bit interval T b , while the binary '0' (space) is represented by a null signal state. This particular signaling method is widely recognized as On-Off Keying (OOK) . It is technically realized by gating a carrier oscillator with a unipolar baseband sequence, effectively performing a product modulation that shifts the baseband spectrum to the carrier frequency. ASK Transmitter Architecture: ...

RMS Delay Spread, Excess Delay Spread and Multi-path ...(with MATLAB + Simulator)

📘 Overview of Delay Spread and Multi-path 🧮 Excess Delay spread 🧮 Power delay Profile 🧮 RMS Delay Spread 📚 Further Reading 📂 Other Topics on RMS Delay Spread, Excess Delay ... 🧮 Multipath Components or MPCs 🧮 Online Simulator for Calculating RMS Delay Spread 🧮 Why is there significant multipath in the case of very high frequencies? 🧮 Why RMS Delay Spread is essential for wireless communication? 🧮 Why the Power Delay Profile is essential? 🧮 MATLAB Codes for Calculating Different Types of delay Spreads Delay Spread, Excess Delay Spread, and Multipath (MPCs) The fundamental distinction between wireless and wired connections is that in wireless connections signal reaches at receiver thru multipath signal propagation rather than directed transmission like co-axial cable. Wireless Communication has no set communication path between the transmitter and the receiver. The line...

UGC NET Electronic Science Previous Year Question Papers with Solutions

Home / Engineering & Other Exams / UGC NET 2026 PYQ ⬇️ Download Papers and Solutions 📋 Exam Pattern 💡 Preparation Tips ❓ FAQs 📊 Exam Highlights: Electronic Science (88) Feature Details Junior Research Fellowship (JRF) ₹37,000 + HRA per month Eligibility M.Sc/M.Tech in Electronics (55%) Validity of Certificate JRF (3 Years) | Lectureship (Lifetime) 📥 Download UGC NET Electronics PDFs Complete collection of previous year question papers, answer keys and explanations for Subject Code 88. Start Downloading 📂 View All Question Papers June 2025 - Question Paper Download PDF June 2025 - Solved Paper + Explanation ...

Frequency Shift Keying (FSK) Modulation & Demodulation (with Simulation)

Frequency Shift Keying (FSK) Theoretical Foundations: Frequency Shift Keying (FSK) is a discrete frequency modulation scheme wherein the digital information is encoded via instantaneous shifts in the carrier signal's frequency. The fundamental implementation is Binary FSK (BFSK), which maps binary data onto two distinct, discrete spectral states. A binary '1' (the "mark" state) is represented by a carrier frequency \( f_1 \), while a binary '0' (the "space" state) corresponds to frequency \( f_2 \). Each symbol is sustained for a bit interval denoted by \( T_b \). FSK Transmitter Characterization: The mathematical model for the modulated BFSK output \( s(t) \) is defined as: \[ s(t) = \begin{cases} A_c \cos(2\pi f_1 t), & \text{for } m = 1 \\ A_c \cos(2\pi f_2 t), & \text{for } m = 0 \end{cases} \] ...

Advanced M-ary Modulation Simulator: Constellation, min dist, Efficiency, SER, EVM (RMS)

Advanced M-ary Communication Lab Analytical & Statistical Performance of Digital Modulation Theoretical Probability of Error (\(P_s\)) \[ P_s = Q\left(\sqrt{\frac{2 E_b}{N_0}}\right) \] Modulation (M-ary) BPSK (M=2) QPSK (M=4) 8-PSK (M=8) 16-QAM (M=16) 64-QAM (M=64) 256-QAM (M=256) SNR (\(E_b/N_0\)): 12 dB Efficiency 2 bps/Hz Min Dist (\(d_{min}\)) 1.41 Symbol Error 1.2e-5 EVM (RMS) 0.0% Constellation Diagram Noise PDF & Decision Tail 1. Geometric Mapping ...

MATLAB Code for Rms Delay Spread

RMS delay spread is crucial when you need to know how much the signal is dispersed in time due to multipath propagation, the spread (variance) around the average. In high-data-rate systems like LTE, 5G, or Wi-Fi, even small time dispersions can cause ISI. RMS delay spread is directly related to the amount of ISI in such systems. RMS Delay Spread [↗] Delay Spread Calculator Enter delays (ns) separated by commas: Enter powers (dB) separated by commas: Calculate   The above calculator Converts Power to Linear Scale: It correctly converts the power values from decibels (dB) to a linear scale. Calculates Mean Delay: It accurately computes the mean excess delay, which is the first moment of the power delay profile. Calculates RMS Delay Spread: It correctly calculates the RMS delay spread, defined as the square root of the second central moment of the power delay profile.   MATLAB Code  clc...

Online Simulator for ASK, FSK, and PSK Signal Generation

Interactive Digital Signal Processing (DSP) Tutorial and Simulator for ASK, FSK, and BPSK modulation techniques. Try our new Digital Signal Processing Simulator!   •   Interactive ASK, FSK, and BPSK tools updated for 2025. Start Now Digital Modulation Visualizer: ASK, FSK, & BPSK Simulator Learn and visualize binary modulation techniques (ASK, FSK, BPSK) in real-time with adjustable carrier and sampling parameters. Perfect for DSP students and engineers. 📡 ASK Simulator 📶 FSK Simulator 🎚️ BPSK Simulator 📚 More Topics ASK Modulator FSK Modulator BPSK Modulator More Topics 1. ASK (Amplitude Shift Keying) Simulat...