Ejemplo n.º 1
0
    def create_moments(self, _n_moments):
        self.n_moments = _n_moments

        self.true_moments = []

        for i in range(0, self.n_moments):
            self.true_moments.append(
                beta.moment(i + 1, self.p_beta, self.q_beta))
Ejemplo n.º 2
0
def beta_example_gender():
    '''
    Plot example beta distribution for males and females
    '''

    a_f, b_f = 3 * 1, 2 * 1
    a_m, b_m = a_f * 2, b_f * 2

    # Mean and sample size
    mu_m = beta.moment(1, a_m, b_m)
    mu_f = beta.moment(1, a_f, b_f)
    n_m, n_f = a_m + b_m, a_f + b_f

    x = np.linspace(0, 1, 1000)

    fig, ax = plt.subplots()

    # Function to create label
    def label_str(g, mu, n):
        label_str = g + ' \\\\ ' \
            + r'($\mu = $' + str(round(mu, 2)) + r', $n = $' + str(n) + ')'
        return label_str

    ax.plot(x,
            beta.pdf(x, a_m, b_m),
            label=label_str('Men', mu_m, n_m),
            color=color_list[0])

    ax.plot(x,
            beta.pdf(x, a_f, b_f),
            label=label_str('Women', mu_f, n_f),
            color=color_list[1])

    ax.legend(loc='upper left', handlelength=0.5, frameon=False, borderpad=0)

    # get the current limit of y-axis
    _, y_max = ax.get_ylim()

    # Dotted line at mean
    ax.plot([mu_f, mu_f], [0, y_max], ':', color='#BBBBBB')

    # set y-limit
    ax.set_ylim(0, y_max)
Ejemplo n.º 3
0
    def generate_moments(self, max_moment):
        '''
        Calculate & store moments to retrieve more efficiently later
        '''

        self._moments = np.zeros((max_moment, 1))

        #Rely on scipy.stats to return non-central moment
        for i in range(max_moment):
            self._moments[i] = scipybeta.moment(i+1, self._alpha, self._beta,
                                                self._shift, self._scale)