Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
706 B
1
Indexable
Never
def midpoint(lower_bound, upper_bound):
    return (lower_bound + upper_bound) / 2

def mean_grouped(data, frequencies):
    return sum(midpoint(data[i], data[i+1]) * frequencies[i] for i in range(len(data) - 1)) / sum(frequencies)

def mean_deviation_grouped(data, frequencies):
    n = sum(frequencies)
    mean = mean_grouped(data, frequencies)
    deviations = [abs(midpoint(data[i], data[i+1]) - mean) * frequencies[i] for i in range(len(data) - 1)]
    return sum(deviations) / n

data = [10, 20, 30, 40, 50]  # Class intervals
frequencies = [5, 8, 12, 10, 5]  # Frequencies of each class interval

result = mean_deviation_grouped(data, frequencies)
print("Mean deviation for grouped data:", result)
Leave a Comment