def analytic_false_alarm_probability(lspinfo,<EOL>times,<EOL>conservative_nfreq_eff=True,<EOL>peakvals=None,<EOL>inplace=True):
from scipy.stats import beta<EOL>frequencies = <NUM_LIT:1.0>/lspinfo['<STR_LIT>']<EOL>M = independent_freq_count(frequencies,<EOL>times,<EOL>conservative=conservative_nfreq_eff)<EOL>if peakvals is None:<EOL><INDENT>peakvals = lspinfo['<STR_LIT>']<EOL><DEDENT>nphasebins = nparange(<NUM_LIT:0.0>, <NUM_LIT:1.0>, lspinfo['<STR_LIT>']['<STR_LIT>']).size<EOL>ndet = times.size<EOL>false_alarm_probs = []<EOL>for peakval in peakvals:<EOL><INDENT>prob_xval = ((ndet-nphasebins)/(nphasebins-<NUM_LIT:1.0>))*peakval<EOL>prob_exceeds_val = beta.cdf(prob_xval,<EOL>(ndet-nphasebins)/<NUM_LIT>,<EOL>(nphasebins-<NUM_LIT:1.0>)/<NUM_LIT>)<EOL>import ipdb; ipdb.set_trace()<EOL>false_alarm_probs.append(<NUM_LIT:1.0> - (<NUM_LIT:1.0> - prob_exceeds_val)**M)<EOL><DEDENT>if inplace:<EOL><INDENT>lspinfo['<STR_LIT>'] = false_alarm_probs<EOL><DEDENT>return false_alarm_probs<EOL>
This returns the analytic false alarm probabilities for periodogram
    peak values.

    FIXME: this doesn't actually work. Fix later.

    The calculation follows that on page 3 of Zechmeister & Kurster (2009)::

        FAP = 1 − [1 − Prob(z > z0)]**M

    where::

        M is the number of independent frequencies
        Prob(z > z0) is the probability of peak with value > z0
        z0 is the peak value we're evaluating

    For PDM, the Prob(z > z0) is described by the beta distribution, according
    to:

    - Schwarzenberg-Czerny (1997;
      https://ui.adsabs.harvard.edu/#abs/1997ApJ...489..941S)

    - Zalian, Chadid, and Stellingwerf (2013;
      http://adsabs.harvard.edu/abs/2014MNRAS.440...68Z)

    This is given by::

        beta( (N-B)/2, (B-1)/2; ((N-B)/(B-1))*theta_pdm )

    Where::

        N = number of observations
        B = number of phase bins

    This translates to a scipy.stats call to the beta distribution CDF::

        x = ((N-B)/(B-1))*theta_pdm_best
        prob_exceeds_val = scipy.stats.beta.cdf(x, (N-B)/2.0, (B-1.0)/2.0)

    Which we can then plug into the false alarm prob eqn above with the
    calculation of M.

    Parameters
    ----------

    lspinfo : dict
        The dict returned by the
        :py:func:`~astrobase.periodbase.spdm.stellingwerf_pdm` function.

    times : np.array
        The times for which the periodogram result in ``lspinfo`` was
        calculated.

    conservative_nfreq_eff : bool
        If True, will follow the prescription given in Schwarzenberg-Czerny
        (2003):

        http://adsabs.harvard.edu/abs/2003ASPC..292..383S

        and estimate the effective number of independent frequences M_eff as::

            min(N_obs, N_freq, DELTA_f/delta_f)

    peakvals : sequence or None
        The peak values for which to evaluate the false-alarm probability. If
        None, will calculate this for each of the peak values in the
        ``nbestpeaks`` key of the ``lspinfo`` dict.

    inplace : bool
        If True, puts the results of the FAP calculation into the ``lspinfo``
        dict as a list available as ``lspinfo['falsealarmprob']``.

    Returns
    -------

    list
        The calculated false alarm probabilities for each of the peak values in
        ``peakvals``.