Untitled
unknown
plain_text
7 months ago
1.1 kB
1
Indexable
Never
def cumulative_frequencies(frequencies): cumulative = [frequencies[0]] for i in range(1, len(frequencies)): cumulative.append(cumulative[i-1] + frequencies[i]) return cumulative def quartile_deviation_grouped(data, frequencies): n = sum(frequencies) cf = cumulative_frequencies(frequencies) q1_index = (n + 1) / 4 q3_index = 3 * (n + 1) / 4 q1, q3 = None, None for i in range(len(cf)): if cf[i] >= q1_index and q1 is None: q1 = data[i] + ((q1_index - cf[i-1]) / frequencies[i]) * (data[i+1] - data[i]) if cf[i] >= q3_index and q3 is None: q3 = data[i] + ((q3_index - cf[i-1]) / frequencies[i]) * (data[i+1] - data[i]) if q1 is not None and q3 is not None: break quartile_deviation = (q3 - q1) / 2 return quartile_deviation data = [10, 20, 30, 40, 50] # Class intervals frequencies = [5, 8, 12, 10, 5] # Frequencies of each class interval result = quartile_deviation_grouped(data, frequencies) print("Quartile deviation for grouped data:", result)
Leave a Comment