def centralmoment(vi, k):
    """
    Converts raw distribution moments to central moments
    
    Parameters
    ----------
    vi : array
        The first four raw distribution moments
    k : int
        The central moment (0 to 4) to calculate (i.e., k=2 is the variance)
    
    Returns
    -------
    cm : scalar
        The central moment itself
        
    """
    if k==0:
        ans = 1
    elif k==1:
        ans = 0
    elif k==2:
        ans = vi[2] - vi[1]**2
    elif k==3:
        ans = vi[3] - 3*vi[2]*vi[1] + 2*vi[1]**3
    elif k==4:
        ans = vi[4] - 4*vi[3]*vi[1] + 6*vi[2]*vi[1]**2 - 3*vi[1]**4
    else:
        print('Can only calculate central moments k = 0 to 4. Sorry.')
        ans = None
    return ans