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

UGC NET Electronic Science Previous Year Question Papers with Solutions

Download Papers and Solutions Exam Pattern Preparation Tips FAQs More Home / Engineering & Other Exams / UGC NET 2026 PYQ 📊 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 2026 - Question Paper Download PDF June 202...

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 Demodulation More Topics 1. ASK (Ampli...

Flat vs Frequency Selective Online Simulator

Flat vs Frequency Selective Online Simulator Channel Type Without Fading Flat Fading Multipaths Nakagami m SNR(dB) Run Simulation Input Signal Signal After Fading Constellation Diagram BER vs SNR Explore Advanced Flat vs Frequency-Selective Fading Simulator Want to see these equations in action? Visualize it. Launch Simulator Tool Interactive Rayleigh Fading Simulator Want to see Rayleigh fading in action? Visualize it. Launch Simulator Tool Return to DSP Simulations Main Page →

AM Modulation Online Simulator

Amplitude Modulation Simulator s AM (t) = A c [1 + k a m(t)] cos(ω c t) where, ω = 2Ï€f & k a = Amplitude Sensitivity Modulation index, μ = k a A m Message Frequency (fm): Carrier Frequency (fc): Carrier Amplitude (Ac): Modulation Index (m = Am / Ac): Interactive AM Demodulation Online Simulator Want to see these equations in action? Visualize it. Launch Simulator Tool Interactive AM Power Simulator Visualize it. Launch Simulator Tool Return to DSP Simulations Main Page →

Theoretical BER vs SNR for binary ASK, FSK, and PSK (with MATLAB Code + Simulator)

📘 Overview & Theory 🧮 MATLAB Codes 🧮 Q-function 📚 Further Reading Bit Error Rate (BER) Equations In ASK, noise directly affects the signal amplitude, making it the most vulnerable since the data is carried in amplitude changes. In FSK, data is represented by frequency variations, and because noise typically impacts amplitude more than frequency, FSK is more robust than ASK. In PSK, data is encoded in the signal phase, and BPSK specifically uses 180-degree phase shifts, creating the greatest separation between signal points and therefore achieving the lowest bit error rate (BER) for the same power level. BER formulas for ASK, FSK, and PSK modulation schemes. ASK BER = 0.5 × erfc(0.5 × √SNR) FSK BER = 0.5 × erfc(√(SNR / 2)) PSK BER = 0.5 × erfc(√SNR) ...

Chirp Signal Simulator

Chirp Signal Simulator Starting Frequency (Hz) Ending Frequency (Hz) Amplitude phase Up-Chirp (unchecked = Down-Chirp) Generate Chirp Demodulate Return to DSP Simulations Main Page →

Linear vs Circular Convolution

Linear vs Circular Convolution Linear convolution vs circular convolution Linear convolution (what nature does) If: x[n] = transmitted signal h[n] = channel impulse response (multipath) Then the received signal is: y[n] = x[n] * h[n] This means: Past symbols spill into future symbols Causes inter-symbol interference (ISI) DFT of y[n] is not a simple product Circular convolution (what DFT assumes) The DFT assumes periodic signals : y[n] = x[n] ⊛ h[n], where indices wrap around modulo N Only under circular convolution does the DFT satisfy: Y[k] = X[k] · H[k] This is what enables one-tap frequency-domain equalization . What happens in the real channel (linear convolution) The channel performs linear convolution: y[n] = Σ l=0 Lh−1 h[l] x[n-l] But because: CP absorbs the “spillover” Receiver discards CP before DFT The useful part of the received symbol becomes: y[n] = Σ l=0 Lh−1 h[l] x[(n-l) mod N] Modulo inde...