Loading problem...
In statistical analysis and natural language processing, measuring the association strength between two events is a fundamental task. This metric quantifies whether two events occur together more or less frequently than would be expected if they were statistically independent.
The Association Strength Metric, based on the concept of Pointwise Mutual Information (PMI), compares the observed joint probability of two events with the expected probability under the assumption of statistical independence.
Mathematical Formulation:
Given:
The probabilities are:
The Association Strength Metric is calculated as:
$$ASM(x, y) = \log_2 \left( \frac{P(x, y)}{P(x) \cdot P(y)} \right)$$
Interpreting the Result:
Your Task: Implement a function that calculates the Association Strength Metric given the joint occurrence count, individual counts of each event, and the total sample size. Return the result rounded to 3 decimal places.
joint_count = 50
count_x = 200
count_y = 300
total_samples = 1000-0.263First, we calculate the probabilities:
• P(x) = 200/1000 = 0.2 • P(y) = 300/1000 = 0.3 • P(x, y) = 50/1000 = 0.05
The expected joint probability under independence is: • P(x) × P(y) = 0.2 × 0.3 = 0.06
The Association Strength Metric is: • ASM = log₂(0.05 / 0.06) = log₂(0.8333...) ≈ -0.263
The negative value indicates that events X and Y co-occur slightly less frequently than would be expected if they were independent.
joint_count = 100
count_x = 100
count_y = 100
total_samples = 10003.322Calculate the probabilities:
• P(x) = 100/1000 = 0.1 • P(y) = 100/1000 = 0.1 • P(x, y) = 100/1000 = 0.1
Expected joint probability under independence: • P(x) × P(y) = 0.1 × 0.1 = 0.01
Association Strength Metric: • ASM = log₂(0.1 / 0.01) = log₂(10) ≈ 3.322
The high positive value indicates a very strong association—whenever event X occurs, event Y almost certainly occurs as well, which is 10 times more frequent than expected by chance.
joint_count = 20
count_x = 200
count_y = 100
total_samples = 1000-0.0Calculate the probabilities:
• P(x) = 200/1000 = 0.2 • P(y) = 100/1000 = 0.1 • P(x, y) = 20/1000 = 0.02
Expected joint probability under independence: • P(x) × P(y) = 0.2 × 0.1 = 0.02
Association Strength Metric: • ASM = log₂(0.02 / 0.02) = log₂(1) = 0.0
The value of zero indicates perfect independence—the events X and Y co-occur exactly as often as expected if there were no relationship between them.
Constraints