Coefficient of Variation (CV) is defined as the ratio of the standard deviation (σ) to the mean (μ) and is usually expressed as a percentage:
Program :
# Function to calculate Coefficient of Variation for a Discrete Series
cv_discrete <- function(x) {
mean_val <- mean(x)
sd_val <- sd(x)
cv <- (sd_val / mean_val) * 100
return(cv)
}
# Function to calculate Coefficient of Variation for a Continuous Series
cv_continuous <- function(lower_bound, upper_bound, frequency) {
# Calculate midpoints of the class intervals
midpoints <- (lower_bound + upper_bound) / 2
# Calculate the mean for the continuous series
mean_val <- sum(midpoints * frequency) / sum(frequency)
# Calculate variance
variance <- sum(frequency * (midpoints - mean_val)^2) / sum(frequency)
# Calculate standard deviation
sd_val <- sqrt(variance)
# Calculate Coefficient of Variation
cv <- (sd_val / mean_val) * 100
return(cv)
}
# Example Usage for Discrete Series:
discrete_data <- c(10, 20, 30, 40, 50) # Example values for discrete series
cv_discrete(discrete_data)
# Example Usage for Continuous Series:
lower_bound <- c(0, 10, 20, 30) # Lower bounds of class intervals
upper_bound <- c(10, 20, 30, 40) # Upper bounds of class intervals
frequency <- c(5, 10, 8, 7) # Frequency of each class interval
cv_continuous(lower_bound, upper_bound, frequency)
Output :
No comments:
Post a Comment