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

CMOS Logic Gates: Inverter, NAND, and NOR

CMOS Logic Gates: Inverter, NAND, and NOR Complementary metal–oxide–semiconductor (CMOS) technology forms the backbone of modern digital IC design. Patented by Frank Wanlass in 1963 ( US patent 3,356,858 ), CMOS enables low-power, high-speed, and noise-immune logic circuits. CMOS gates, including inverters, NAND, and NOR, are widely used in both large-scale and small-scale integrated circuits due to their efficiency and versatility. CMOS Inverter A CMOS inverter consists of a complementary pair of PMOS and NMOS transistors. The PMOS transistor connects to the supply voltage V DD , while the NMOS connects to ground. The input voltage V IN controls both gates, and the output voltage V OUT is taken from the connected drains. CMOS inverters are highly energy-efficient and produce minimal heat due to their comple...

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...

Decision Feedback Equalizer (DFE) in MATLAB

  MATLAB Code M = 4; % QPSK numSymbols = 10000; numTrainingSymbols = 5000; chtaps = [1 0.5*exp(1i*pi/6) 0.1*exp(-1i*pi/8)]; % Generate QPSK symbols data = randi([0 M-1], numSymbols, 1); tx = pskmod(data, M, pi/4); % DFE setup eq = comm.DecisionFeedbackEqualizer; eq.ReferenceTap = 1; eq.NumForwardTaps = 5; eq.NumFeedbackTaps = 3; % SNR sweep snrVec = 0:5:25; % 0,5,10,...25 dB berBefore = zeros(size(snrVec)); berAfter = zeros(size(snrVec)); for k = 1:length(snrVec) % Apply channel and AWGN rx = awgn(filter(chtaps,1,tx), snrVec(k), 'measured' ); % BER before equalization rxDataNoEq = pskdemod(rx, M, pi/4); [~, berBefore(k)] = biterr(data, rxDataNoEq); % Equalize [y,~,~] = eq(rx, tx(1:numTrainingSymbols)); % Phase correction phaseOffset = angle(mean(conj(tx(1:numTrainingSymbols)) .* y(1:numTrainingSymbols))); yCorrected = y * exp(-1i*phaseOffset); % BER after equalization rxDataEq = pskdemod(yCorrected, M, pi/4); [...

Design of CMOS Flip-Flops (SR, D, JK)

Design of CMOS Flip-Flops (SR, D, JK) A flip-flop or latch is a circuit with two stable states, used to store state information. It is the basic storage element in sequential logic and a fundamental building block in digital electronics systems, including computers and communication devices. Flip-flops and latches act as data storage elements for states, pulse counting, and synchronization of variably-timed input signals to a reference clock. Flip-flops can be transparent/opaque (latches) or clocked (synchronous, edge-triggered). Latches are level-sensitive, while flip-flops are edge-sensitive. In sequential logic, the output depends on current inputs and previous states. Fig.1 shows a sequential circuit combining a combinational block and a memory element. ...

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 Flat Fading and Frequency-Selective Fading Effects of Multipath Components and the Nakagami-m Parameter 1. Flat Fading Flat fading occurs when the signal bandwidth is smaller than the channel's coherence bandwidth, meaning that all frequency components of the transmitted signal experience approximately the same fading. It is typically associated with narrowband signals, where the multipath delay spread is small relative to the symbol duration. ...

Superheterodyne Receiver Online Simulator

Superheterodyne Receiver Simulator Simulation Controls Message Frequency (Hz): Carrier Frequency (Hz): Intermediate Frequency (Hz): Sampling Frequency (Hz): Simulation Duration (s): Run Simulation Signal Plots Numerical Values (first 10 samples) Superheterodyne Receiver Workflow The superheterodyne receiver converts a received RF signal to an intermediate frequency (IF) to simplify filtering and amplification, and finally recovers the original message signal. Steps: Input Message Signal: A low-frequency signal m(t) (e.g., sine wave). RF Modulation (AM): The message modulates the carrier with amplitude modulation: RF(t) = [1 + K_a * m(t)] * cos(2Ï€ f_c t) Mixing with Local Oscillator (LO): The RF signal is multiplied by a local oscillator LO(t) = cos(2Ï€ f_LO t) to produce: IF(t) = RF(t) * LO(t) Intermediate Frequency Filtering: A low-pass filter extracts t...

MUSIC Algorithm Explained (with MATLAB + Simulator)

Practical Implementation of the MUSIC Algorithm The focus is on how the algorithm works computationally , not just theory, and it explains the denominator (a H E n E n H a) mathematically and intuitively. 1. Introduction The MUSIC (Multiple Signal Classification) algorithm is a high-resolution method used in signal processing and array processing to estimate the Direction of Arrival (DOA) of signals received by a sensor array. Unlike classical beamforming methods, MUSIC uses eigenvector decomposition of the covariance matrix to separate the signal subspace and noise subspace , allowing it to achieve much higher angular resolution. In practical implementations, MUSIC works by: Simulating or collecting array signals Computing the covariance matrix Performing eigenvalue decomposition Separating signal and noise subspaces Scanning possible angles using a steering vector Constructing a pseudo-spectrum where peaks indicate signal directions 2. Signal Mo...

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...