def calc_mi(med_head_x, lat_head_x, lat_acetabulum_x, side):
    """Calculate migration index (MI).
    For the right hip, MI = (lat acetabulum - lat head) / (med head - lat head)
    For the left hip first need to multiple each point by -1.
    Args:
        med_head_x: x coordinate of medial head
        lat_head_x: x coordinate of lateral head
        lat_acetabulum_x: x coordinate of lateral acetabulum
        side: side of hip from which points come (i.e., 'right' or 'left')
    Raise:
        ValueError if side not in ['right', 'left']
    Returns:
        Migration index in interval [0,1]
    """
    if side not in ['right', 'left']:
        raise ValueError(f'Side must be "right" or "left", not "{side}"')

    if side == 'left':
        med_head_x *= -1
        lat_head_x *= -1
        lat_acetabulum_x *= -1
    mi = (lat_acetabulum_x - lat_head_x) / (med_head_x - lat_head_x)
    
    # bound within [0, 1]
    mi = max(mi, 0)
    mi = min(mi, 1)
    return mi