def get_x2(oi, ei):
    """
    Function to calculate the statistical test for the categorical data analysis,
    it is a chi squared value.
    
    Parameters:
    --------------------------
    oi : list
        Frequency from the observed events.
    ei : list
        Frequency from the expected events.
    
    Returns:
    --------------------------
    x2 : double
        Chi squared value which represents the calculated statistical test.
    """
    if (any(isinstance(el, list) for el in oi)): # Validate if the list is a list of lists
        x2 = 0
    
        for i in range(len(oi)):
            for j in range(len(oi[i])):
                x2 += (oi[i][j] - ei[i][j])**2 / ei[i][j]
            
        return x2
    else:
        k = len(oi)
        x2 = sum([((oi[x] - ei[x])**2 / ei[x]) for x in range(k)])
        return x2