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

OFDM Symbols and Subcarriers Explained

This article explains how OFDM (Orthogonal Frequency Division Multiplexing) symbols and subcarriers work. It covers modulation, mapping symbols to subcarriers, subcarrier frequency spacing, IFFT synthesis, cyclic prefix, and transmission. Step 1: Modulation First, modulate the input bitstream. For example, with 16-QAM , each group of 4 bits maps to one QAM symbol. Suppose we generate a sequence of QAM symbols: s0, s1, s2, s3, s4, s5, …, s63 Step 2: Mapping Symbols to Subcarriers Assume N sub = 8 subcarriers. Each OFDM symbol in the frequency domain contains 8 QAM symbols (one per subcarrier): Mapping (example) OFDM symbol 1 → s0, s1, s2, s3, s4, s5, s6, s7 OFDM symbol 2 → s8, s9, s10, s11, s12, s13, s14, s15 … OFDM sym...

UGC NET Electronic Science June 2026 Question Paper with Answer Key & Detailed Solutions

Home / UGC NET PYQ / June 2026 Solved UGC NET Electronic Science June 2026 Question Paper with Answer Key and Full Explanations 📥 Download Question Paper (PDF) 2025 2024 2023 2022 2021 2020 Explanations 1. Answer: Option (3) Total Students = 900 Urban Students = 7/10*400 + 4/5*500 = 680 680/900 * 100 = 75.56% 2. Answer: Option (1) Urban Students = 7/10*400 + 4/5*500 + 4/7*700 + 1/2 * 600 = 1380 3. Answer: Option (3) Male = 700*4/7 = 400 Female = 700*3/7=300 400-300=100 100/400*100 = 25% 4. Answer: Option (2) 400*3/10*40/100 + 500*1/5*60/100+700*3/7*50/100+600*1/3*30/100 = 318 5. Answer: Option (2) Total Female Students in B,C, and D colleges = 600 Female Post-graduates  = 100*60/100 + 300*50/100 + 200*30/100 = 270 270/600 *100 = 45% 6. Answer: Option (3) 7. Answer: Option (2) 8. Answer: Option (4) 9. Answer: Option (4) 10. Answer: Option (2) 11. Answer: Option (2) 12. Answer...

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

Phase Modulation (PM) & Demodulation

Advanced Analysis of Phase Modulation Phase Modulation (PM): Theoretical Foundations and Spectral Dynamics 1. Analytical Characterization Phase Modulation (PM) is a subset of Angle Modulation , where the information residing in the message signal \( m(t) \) is mapped linearly onto the instantaneous phase of a high-frequency carrier. Unlike Amplitude Modulation (AM), PM is a non-linear modulation process, resulting in an expansion of the signal bandwidth into an infinite dimensional Hilbert space. \[ S_{PM}(t) = A_c \cos\left[ 2\pi f_c t + \phi(t) \right] = A_c \cos\left[ 2\pi f_c t + K_p m(t) \right] \] The instantaneous frequency \( f_i(t) \) is defined as the time derivative of the total angle: \[ f_i(t) = \frac{1}{2\pi} \frac{d\theta_i(t)}{dt} = f_c + \frac{K_p}{2\pi} \frac{dm(t)}{dt} \] ...

Periodicity of Continuous and Discrete Signals

Understanding Periodicity of Sinusoidal Signals: Continuous-Time vs Discrete-Time Signals Periodicity is one of the most important concepts in Signals and Systems, and Digital Signal Processing (DSP). Many students know the formula \(T=\frac{2\pi}{\omega}\), but often get confused when similar questions appear in the context of discrete-time signals. In this article, we will clearly understand the difference between periodicity in continuous-time (analog) signals and discrete-time (digital) signals with examples and exam-oriented shortcuts. What is a Periodic Signal? A signal is said to be periodic if it repeats itself after a fixed interval. Continuous-Time (Analog) Signal A continuous-time signal \(x(t)\) is periodic if there exists a positive number \(T\) such that: \[ x(t+T)=x(t) \] The smallest positive value of \(T\) is called the fundamental period . Or, T = Smallest ...

UGC NET Electronic Science February 2023 Question Paper with Answer Key & Detailed Solutions

    UGC NET Electronic Science February 2023 Question Paper with Answer Key and Detailed Solutions Download Question Paper                   2025 | 2024 | 2023 | 2022 | 2021 | 2020 51. (B): A photodiode operates by absorbing photons and converting them to a current across the device. When it is reverse-biased and kept in the dark, it doesn't receive any photons. Hence, there is no photo-generated current. However, due to thermal energy, a tiny amount of current called the reverse saturation current (or dark current) flows. This is the minimum current flowing through the device when no photons are absorbed. It's essential to keep in mind that the reverse saturation current is a very small value, and it is the baseline current for a reverse-biased photodiode in the dark. 52. (C)        53. (C) ...