0% found this document useful (0 votes)
17 views9 pages

Covariance@3PM 24th Sep

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views9 pages

Covariance@3PM 24th Sep

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Covariance:

Covariance is a statistical measure that indicates the degree to which two


variables change together. If the greater values of one variable
correspond to the greater values of the other variable, the covariance is
positive. If the greater values of one variable correspond to the lesser
values of the other variable, the covariance is negative.

Interpretation:
 Positive Covariance: Indicates that the two variables tend to
increase together.
 Negative Covariance: Indicates that as one variable increases, the
other decreases.
 Zero Covariance: Indicates no linear relationship between the
variables.
Covariance is useful in determining the relationship between two
variables, but it does not give insight into the strength of the relationship.
To measure the strength, you would typically look at the correlation.

Example:
Let's calculate the covariance between two variables:
X = [2, 4, 6, 8, 10] and Y = [1, 3, 5, 7, 9].
PYTHON CODE:
import numpy as np
# Data for two variables X and Y
X = [2, 4, 6, 8, 10]
Y = [1, 3, 5, 7, 9]

# Stack the data and calculate the covariance matrix


cov_matrix = np.cov(X, Y)

# Covariance between X and Y is the element [0, 1] or [1, 0]


covariance = cov_matrix[0, 1]
print("Covariance between X and Y:", covariance)

Correlation:
Correlation is a statistical measure that describes the strength and
direction of a linear relationship between two variables. The most
commonly used correlation coefficient is Pearson's correlation coefficient,
which ranges from -1 to +1:

+1 indicates a perfect positive linear relationship (as one variable


increases, the other also increases).
-1 indicates a perfect negative linear relationship (as one variable
increases, the other decreases).
0 indicates no linear relationship.

Step-by-Step Calculation:
Finally:

PYTHON CODE:
import numpy as np
# Data for two variables X and Y
X = [2, 4, 6, 8, 10]
Y = [1, 3, 5, 7, 9]
# Calculate the Pearson correlation coefficient
correlation = np.corrcoef(X, Y)[0, 1]
print("Correlation between X and Y:", correlation)
Coefficient of Variation (CV): The CV is the ratio of the standard
deviation to the mean expressed as a percentage. It is used to compare
the variability of datasets with different means and is commonly used in
fields such as biology, chemistry, and engineering.

The coefficient of variation (CV) is a statistical measure that expresses the


amount of variability in a dataset relative to the mean. It is a
dimensionless quantity that is expressed as a percentage.

The formula for calculating the coefficient of variation is:

CV = (standard deviation / mean) x 100%

OR

Example:
Consider the following incomes (in thousands of dollars):
45,50,55,60,65
Conclusion:
The Coefficient of Variation (CV) is approximately 12.86%, which indicates
that the income values vary by about 12.86% relative to the mean income
of $55,000.

PYTHON Example:
import numpy as np
# Dataset of incomes (in thousands of dollars)
incomes = [45, 50, 55, 60, 65]

# Step 1: Calculate the mean


mean_income = np.mean(incomes)

# Step 2: Calculate the standard deviation


std_deviation = np.std(incomes, ddof=0) # Population standard deviation
# Step 3: Calculate the Coefficient of Variation (CV)
cv = (std_deviation / mean_income) * 100

mean_income, std_deviation, cv

You might also like