# Path: pyleoclim/utils/tsmodel.py
# def ar1_fit_evenly(y):
#     ''' Returns the lag-1 autocorrelation from AR(1) fit.
# 
#     Parameters
#     ----------
#     y : array
#         vector of (float) numbers as a time series
# 
#     Returns
#     -------
#     g : float
#         lag-1 autocorrelation coefficient
# 
#     '''
#     # syntax compatible with statsmodels v0.11.1
#     #ar1_mod = sm.tsa.ARMA(y, (1, 0), missing='drop').fit(trend='nc', disp=0)
#     # syntax compatible with statsmodels v0.12
#     ar1_mod = ARIMA(y, order = (1, 0, 0), missing='drop',trend='ct').fit()
#     g = ar1_mod.params[2]
# 
#     if g > 1:
#         print('Warning: AR(1) fitted autocorrelation greater than 1; setting to 1-eps^{1/4}')
#         eps = np.spacing(1.0)
#         g = 1.0 - eps**(1/4)
# 
#     return g


import numpy as np
import statsmodels.api as sm
from scipy.stats import pearsonr
from scipy.stats.mstats import gmean
from scipy.stats import t as stu
from scipy.stats import gaussian_kde
from sklearn import preprocessing
from .tsmodel import ar1_fit_evenly
        vectors of (real) numbers with identical length, no NaNs allowed
        
    y2 : array
        vectors of (real) numbers with identical length, no NaNs allowed
        
    alpha : float
        significance level for critical value estimation [default: 0.05]

    Returns
    -------

    r : float
         correlation between x and y
         
    signif : bool
        true (1) if significant; false (0) otherwise
        
    pval : float
        test p-value (the probability of the test statistic exceeding the observed one by chance alone)
        
    See Also
    --------
    
    pyleoclim.utils.correlation.corr_isopersist : Estimate Pearson's correlation and associated significance using AR(1)
    
    pyleoclim.utils.correlation.corr_isospec : Estimate Pearson's correlation and associated significance using phase randomization
    
    """
    r = pearsonr(y1, y2)[0]


# Path: pyleoclim/utils/tsmodel.py
# def ar1_fit_evenly(y):
#     ''' Returns the lag-1 autocorrelation from AR(1) fit.
# 
#     Parameters
#     ----------
#     y : array
#         vector of (float) numbers as a time series
# 
#     Returns
#     -------
#     g : float
#         lag-1 autocorrelation coefficient
# 
#     '''
#     # syntax compatible with statsmodels v0.11.1
#     #ar1_mod = sm.tsa.ARMA(y, (1, 0), missing='drop').fit(trend='nc', disp=0)
#     # syntax compatible with statsmodels v0.12
#     ar1_mod = ARIMA(y, order = (1, 0, 0), missing='drop',trend='ct').fit()
#     g = ar1_mod.params[2]
# 
#     if g > 1:
#         print('Warning: AR(1) fitted autocorrelation greater than 1; setting to 1-eps^{1/4}')
#         eps = np.spacing(1.0)
#         g = 1.0 - eps**(1/4)
# 
#     return g


# Path: pyleoclim/utils/correlation.py
import numpy as np
import statsmodels.api as sm
from scipy.stats import pearsonr
from scipy.stats.mstats import gmean
from scipy.stats import t as stu
from scipy.stats import gaussian_kde
from sklearn import preprocessing
from .tsmodel import ar1_fit_evenly

        vectors of (real) numbers with identical length, no NaNs allowed
        
    y2 : array
        vectors of (real) numbers with identical length, no NaNs allowed
        
    alpha : float
        significance level for critical value estimation [default: 0.05]

    Returns
    -------

    r : float
         correlation between x and y
         
    signif : bool
        true (1) if significant; false (0) otherwise
        
    pval : float
        test p-value (the probability of the test statistic exceeding the observed one by chance alone)
        
    See Also
    --------
    
    pyleoclim.utils.correlation.corr_isopersist : Estimate Pearson's correlation and associated significance using AR(1)
    
    pyleoclim.utils.correlation.corr_isospec : Estimate Pearson's correlation and associated significance using phase randomization
    
    """
    r = pearsonr(y1, y2)[0]


    g1 = ar1_fit_evenly(y1)