
p7]c           @   s  d  d l  m Z d  d l m Z m Z m Z d  d l Z d  d l m Z m	 Z	 d  d l
 m Z m Z d  d l m Z d  d l m Z d  d l m Z m Z m Z m Z d  d l j j j Z d  d l j j Z d  d	 l m Z m Z d  d
 l  m! Z! m" Z" d  d l# m$ Z$ d  d l% j j& Z' d  d l( m) Z) d g Z* d d  Z+ d   Z, d d  Z- d e j. f d     YZ/ d e j0 f d     YZ1 d e' j2 f d     YZ3 e' j4 e3 e1  e5 d k rd  d l6 j7 Z8 e8 j9 j: j; d e<  Z: e/ e: j=  Z> e> j? d d  Z@ e/ e: j=  ZA eA j? d d d d d d d d  d! d"  ZB d  d lC ZC d  d lD jE ZF eF jG d# d$ d% d&  ZH eF jI d' eH d( eJ e: j=   ZK eC jL d) eH jM d* eJ e: j=  d% d+  ZN e jO d$ d$ eJ e: j=   ZP eF jI eP d% d& ZP d  d lM ZM e jQ e eM jM jR eK jS   jT eU    ZV eC jW e: j= d, eV Z: e/ e: d% d& ZX eX j? d d d d  ZY e jQ d- d. d/ d0 d1 d0 d2 d3 d4 d5 g
  ZZ e j[ eZ  Z\ d6 Z] n  d S(7   i(   t   division(   t	   iteritemst   ranget   lmapN(   t   dott   identity(   t   invt   slogdet(   t   norm(   t   OLS(   t   lagmatt	   add_trendt   _ar_transparamst   _ar_invtransparams(   t   cache_readonlyt   cache_writable(   t   approx_fprimet   approx_hess(   t   KalmanFilter(   t   utilt   ARi    c         C   s   t  j |  d d | S(   s<   Helper function to calculate sum of squares along first axisi   t   axis(   t   npt   sum(   t   xR   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   sumofsq   s    c         C   s5   | d k s | r1 |  | k  r1 t  d |    n  d  S(   Nt   cmlesE   Start must be >= k_ar for conditional MLE or dynamic forecast. Got %d(   t
   ValueError(   t   startt   k_art   methodt   dynamic(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   _check_ar_start   s    c         C   s   | r | |  n d } | | d  d  d  } t  j | |  } | r^ |  | | | !| | *n |  | | | *t  j |  }	 xM t |  D]? }
 | t  j | | |
 |
 | ! } | |	 |
 <| | |
 | <q W|	 S(   Ni    i(   R   t   zerosR   R   (   t   yt   paramsR   t   k_trendt   stepsR   t   mut   arparamst   endogt   forecastt   it   fcast(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   _ar_predict_out_of_sample#   s    !
c           B   s	  e  Z e j i d  d 6d d 6e j d 6d d 6Z d d d d  Z d	   Z	 d
   Z
 d   Z d   Z d d  Z d d e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d d  Z d d d d e d d d d d d d  Z RS(    s   Autoregressive AR(p) modelt   modelsV   endog : array-like
        1-d endogenous response variable. The independent variable.R#   t   extra_paramst    t   extra_sectionst   nonec         C   s   t  t |   j | d  | | d | |  j } | j d k r_ | d  d   d  f } | |  _ n1 | j d k r | j d d k r t d   n  d  S(   Nt   missingi   s'   Only the univariate case is implemented(   t   superR   t   __init__t   NoneR(   t   ndimt   shapeR   (   t   selfR(   t   datest   freqR2   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR4   >   s    %	"c         C   s   d  S(   N(    (   R8   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt
   initializeG   s    c         C   sJ   |  j  } |  j } | j   } t | | | | !j    | | | | +| S(   s   
        Transforms params to induce stationarity/invertability.

        Reference
        ---------
        Jones(1980)
        (   R   R$   t   copyR   (   R8   R#   t   pt   kt	   newparams(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   _transparamsJ   s
    		(c         C   sJ   |  j  } |  j } | j   } t | | | | !j    | | | | +| S(   s9   
        Inverse of the Jones reparameterization
        (   R   R$   R<   R   (   R8   t   start_paramsR=   R>   R?   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   _invtransparamsX   s
    		(c         C   s  |  j  } t j | | | |  } t j | | | d |  }	 t j | d f  }
 t t t | d  t j	 | |   t |	 |	 j  j
 d   } | j | | d d } | } t j |  } x t |  D] } | | t | |
  } t t | |  | j  } d | } t t t | |  | j  |  } t | |
  t | |  }
 | t | |  } t t | |  | j  t |	 |	 j  } | | d k r t | |
  | | d | <q q Wd S(   s   
        Return the pre-sample predicted values using the Kalman Filter

        Notes
        -----
        See predict method for how to use start and p.
        i    i   i   t   Ft   orderg      ?N(   R$   R   t   Tt   RR   R!   R   R   R   t   kront   ravelt   reshapet   ZR   (   R8   R#   R   R=   t   endR"   t   predictedvaluesR>   t   T_matt   R_matt   alphat   Q_0t   Pt   Z_matR*   t   v_matt   F_matt   Finvt   Kt   L(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   _presample_fitb   s&    	&
$+c   	      C   s   t  |  d d  } t  |  d d  } | d  k rb | d k rL | rL d } n | } |  j | } n  | d  k r~ |  j d } n  t t |   j | | |  \ } } } } d | k r | | k  r t d |   n  t | | | |  | | | | f S(   NR   t   mleR   i    isE   Start must be >= k_ar for conditional MLE or dynamic forecast. Got %s(   t   getattrR5   t   _indexR3   R   t   _get_prediction_indexR   R    (	   R8   R   RK   R   t   indexR   R   t   out_of_samplet   prediction_index(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR\      s    	*c         C   s  |  j  | | |  \ } } } } | | d k r@ t d   n  |  j } |  j } |  j }	 |  j j   }
 | r | | | d 7} t |
 | | | | |  St j	 | d |  } |	 d k rC| r | d d t j
 | |  } n d } | | k  rC|  j | | | t | d |  |
 |  | |  | | | c  | 7*qCn  | | k  rS| St j |  j |  } t | | d  } t | | d  } t t |  | | d  } | | | !| | )| rt |
 | | | |  } t j | | f } n  | S(   s  
        Returns in-sample and out-of-sample prediction.

        Parameters
        ----------
        params : array
            The fitted model parameters.
        start : int, str, or datetime
            Zero-indexed observation number at which to start forecasting, ie.,
            the first forecast is start. Can also be a date string to
            parse or a datetime type.
        end : int, str, or datetime
            Zero-indexed observation number at which to end forecasting, ie.,
            the first forecast is start. Can also be a date string to
            parse or a datetime type.
        dynamic : bool
            The `dynamic` keyword affects in-sample prediction. If dynamic
            is False, then the in-sample lagged values are used for
            prediction. If `dynamic` is True, then in-sample forecasts are
            used in place of lagged dependent variables. The first forecasted
            value is `start`.

        Returns
        -------
        predicted values : array

        Notes
        -----
        The linear Gaussian Kalman filter is used to return pre-sample fitted
        values. The exact initial Kalman Filter is used. See Durbin and Koopman
        in the references for more information.
        i   s   end is before startRY   i    (   R\   R   R   R$   R   R(   t   squeezeR,   R   R!   R   RX   t   minR   t   Xt   maxt   lent   r_(   R8   R#   R   RK   R   R^   t   _R   R$   R   R(   RL   R&   t   fittedvaluest   pv_startt   fv_startt   fv_endt   forecastvalues(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   predict   sB    #!			"		c         C   s   |  j  } |  j } | d } t j d | | f } t j | | f d | j } x t d |  D]q } t j | | |   d  | | d | d d  f <| | d | d d  f c t j | | |  d  8<qa W| | j t j	 | j
    } | S(   s   
        Returns the inverse of the presample variance-covariance.

        Notes
        -----
        See Hamilton p. 125
        i   it   dtypeN(   R$   R   R   Re   R!   Rm   R   t	   correlateRE   t   diagt   diagonal(   R8   R#   R>   R=   t   p1t   params0t   VpinvR*   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   _presample_varcov   s    		
2= c         C   s}   |  j  } |  j } |  j } t | j   t j | |   } | | } | d t j d t j  t j |  | d | S(   sQ   
        Loglikelihood of AR(p) process using conditional sum of squares
        i   (	   t   nobst   YRb   R   R`   R   R   t   logt   pi(   R8   R#   Ru   Rv   Rb   t   ssrt   sigma2(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   _loglike_css  s    			"
)c         C   s  |  j  } |  j } |  j } |  j } |  j } |  j rH |  j |  } n  | |  j   } | rr | d g | } n	 d g } t j	 | d t j
 | |   }	 | |	 d d  d f }
 |  j |  } t j t j |
 j |  |
  j   } t | | j   t j | |   } d | | | } | |  _ t |  d } d | t j d t j  t j |  | | | | | } | S(	   sO   
        Loglikelihood of AR(p) process using exact maximum likelihood
        i    i   Ng      ?ig       @i   g      (   Ru   Rb   R(   R   R$   t   transparamsR@   R<   R   t   asarrayR   R5   Rt   R   RE   t   itemR   R`   Rz   R   Rw   Rx   (   R8   R#   Ru   Rb   R(   R   R$   t   ypt   ct   mupt   diffpRs   t
   diffpVpinvRy   Rz   t   logdett   loglike(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   _loglike_mle  s,    							$'&	<c         C   s-   |  j  d k r |  j |  S|  j |  Sd S(   s  
        The loglikelihood of an AR(p) process

        Parameters
        ----------
        params : array
            The fitted parameters of the AR model

        Returns
        -------
        llf : float
            The loglikelihood evaluated at `params`

        Notes
        -----
        Contains constant term.  If the model is fit by OLS then this returns
        the conditonal maximum likelihood.

        .. math:: \frac{\left(n-p\right)}{2}\left(\log\left(2\pi\right)+\log\left(\sigma^{2}\right)\right)-\frac{1}{\sigma^{2}}\sum_{i}\epsilon_{i}^{2}

        If it is fit by MLE then the (exact) unconditional maximum likelihood
        is returned.

        .. math:: -\frac{n}{2}log\left(2\pi\right)-\frac{n}{2}\log\left(\sigma^{2}\right)+\frac{1}{2}\left|V_{p}^{-1}\right|-\frac{1}{2\sigma^{2}}\left(y_{p}-\mu_{p}\right)^{\prime}V_{p}^{-1}\left(y_{p}-\mu_{p}\right)-\frac{1}{2\sigma^{2}}\sum_{t=p+1}^{n}\epsilon_{i}^{2}

        where

        :math:`\mu_{p}` is a (`p` x 1) vector with each element equal to the
        mean of the AR process and :math:`\sigma^{2}V_{p}` is the (`p` x `p`)
        variance-covariance matrix of the first `p` observations.
        R   N(   R   R{   R   (   R8   R#   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR   9  s    !c         C   s   |  j  } t | | d d S(   s  
        Return the gradient of the loglikelihood at params.

        Parameters
        ----------
        params : array-like
            The parameter values at which to evaluate the score function.

        Notes
        -----
        Returns numerical gradient.
        t   epsilong:0yE>(   R   R   (   R8   R#   R   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   score`  s    	c         C   s   d S(   s%   
        Not Implemented Yet
        N(    (   R8   R#   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   informationp  s    c         C   s   |  j  } t | |  S(   s4   
        Returns numerical hessian for now.
        (   R   R   (   R8   R#   R   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   hessianv  s    	c         C   sd   |  j  } t | d | d d } t j |  } | rW t | d t d | d d } n  | |  _ | S(   st   
        Private method to build the RHS matrix for estimation.

        Columns are trend terms then lags.
        t   maxlagt   trimt   botht   prependt   trendt   has_constantt   raise(   R(   R
   R   t   get_trendorderR   t   TrueR$   (   R8   R   R   R(   Rb   R$   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   _stackX}  s    	!	R   RY   c         C   s  |  j  } | | } | |  _ |  j | |  } | |  _ |  j } t d |  } i  }	 | d k r xr t | | d  D]] }
 | | |
 } t |  j d |
 d | d d d | d d	 d
 d  } t	 | |  |	 |
 <qu Wt
 d   t |	  D  \ } } n d } x t | | d d  D]v }
 | | |
 } t |  j d |
 d | d d d | d d d
 d  } d } t j | j d  | k r|
 } PqqW| S(   s2  
        Select the lag order according to the information criterion.

        Parameters
        ----------
        maxlag : int
            The highest lag length tried. See `AR.fit`.
        ic : str {'aic','bic','hqic','t-stat'}
            Criterion used for selecting the optimal lag length.
            See `AR.fit`.
        trend : str {'c','nc'}
            Whether to include a constant or not. 'c' - include constant.
            'nc' - no constant.

        Returns
        -------
        bestlag : int
            Best lag according to IC.
        i   s   t-statR   R   t   full_outputi    R   t   maxiterid   t   dispc         s   s!   |  ] \ } } | | f Vq d  S(   N(    (   t   .0R>   t   res(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pys	   <genexpr>  s    gjg	RQ?ii#   (   R(   Rv   R   Rb   R$   Rc   R   R   t   fitRZ   Ra   R   R   t   abst   tvalues(   R8   R   t   icR   R   R(   Rv   Rb   R>   t   resultst   lagt	   endog_tmpR   t   bestict   bestlagt   stop(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   select_order  s6    	
			%R   t   lbfgsi#   i   c         K   sX  | j    } | d k r+ t d |   n  | |  _ | |  _ | |  _ t |  j  } |  j } | d k r t t	 d | d d   } n  | } | d k	 r | j    } | d k r t d |   n  |  j
 | | | |  } n  | |  _ | | d  d d  f } |  j | |  } |  j } t j |  j | |  |  _ | |  _ | |  _ | d k rt | |  j   } | j } | | |  _ | j | j |  _ nK| d k r| j    } | |  _ | d k rt | |  j   j } n9 t |  | | k rt d t |  | | f   n  |  j |  } | d k r|| j d d  | j d d  | j d d  | j d t  n  t t |   j d | d | d | d |	 d |
 d | |  } | j } |  j r|  j |  } t  |  _ qn  t! j" j# |  } t! j$ | | j%  } t& |  | |  } | d k rN|	 rN| j' | _' | j( | _( n  t) |  S(   s  
        Fit the unconditional maximum likelihood of an AR(p) process.

        Parameters
        ----------
        maxlag : int
            If `ic` is None, then maxlag is the lag length used in fit.  If
            `ic` is specified then maxlag is the highest lag order used to
            select the correct lag order.  If maxlag is None, the default is
            round(12*(nobs/100.)**(1/4.))
        method : str {'cmle', 'mle'}, optional
            cmle - Conditional maximum likelihood using OLS
            mle - Unconditional (exact) maximum likelihood.  See `solver`
            and the Notes.
        ic : str {'aic','bic','hic','t-stat'}
            Criterion used for selecting the optimal lag length.
            aic - Akaike Information Criterion
            bic - Bayes Information Criterion
            t-stat - Based on last lag
            hqic - Hannan-Quinn Information Criterion
            If any of the information criteria are selected, the lag length
            which results in the lowest value is selected.  If t-stat, the
            model starts with maxlag and drops a lag until the highest lag
            has a t-stat that is significant at the 95 % level.
        trend : str {'c','nc'}
            Whether to include a constant or not. 'c' - include constant.
            'nc' - no constant.

        The below can be specified if method is 'mle'

        transparams : bool, optional
            Whether or not to transform the parameters to ensure stationarity.
            Uses the transformation suggested in Jones (1980).
        start_params : array-like, optional
            A first guess on the parameters.  Default is cmle estimates.
        solver : str or None, optional
            Solver to be used if method is 'mle'.  The default is 'lbfgs'
            (limited memory Broyden-Fletcher-Goldfarb-Shanno).  Other choices
            are 'bfgs', 'newton' (Newton-Raphson), 'nm' (Nelder-Mead),
            'cg' - (conjugate gradient), 'ncg' (non-conjugate gradient),
            and 'powell'.
        maxiter : int, optional
            The maximum number of function evaluations. Default is 35.
        tol : float
            The convergence tolerance.  Default is 1e-08.
        full_output : bool, optional
            If True, all output from solver will be available in
            the Results object's mle_retvals attribute.  Output is dependent
            on the solver.  See Notes for more information.
        disp : bool, optional
            If True, convergence information is output.
        callback : function, optional
            Called after each iteration as callback(xk) where xk is the current
            parameter vector.
        kwargs
            See Notes for keyword arguments that can be passed to fit.

        References
        ----------
        Jones, R.H. 1980 "Maximum likelihood fitting of ARMA models to time
            series with missing observations."  `Technometrics`.  22.3.
            389-95.

        See Also
        --------
        statsmodels.base.model.LikelihoodModel.fit
        R   t   ywRY   s   Method %s not recognizedi   g      Y@i   g      @t   aict   bict   hqics   t-stats   ic option %s not understoodNs6   Length of start params is %d. There are %d parameters.R   t   pgtolg:0yE>t   factrt   mt   approx_gradRA   R   R   R   R   t   callback(   R   R   RY   g      ?(   R   R   R   s   t-stat(*   t   lowerR   R   R   R|   Rd   R(   R5   t   intt   roundR   R   R   R$   R   t   make_lag_namest   endog_namest
   exog_namesRv   Rb   R	   R   R#   Ru   Ry   Rz   RB   t
   setdefaultR   R3   R   R@   t   FalseR   t   linalgt   pinvR   RE   t	   ARResultst   mle_retvalst   mle_settingst   ARResultsWrapper(   R8   R   R   R   R   R|   RA   t   solverR   R   R   R   t   kwargsRu   R(   R   Rv   Rb   R$   t   arfitR#   t   mlefitt	   pinv_exogt   normalized_cov_params(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR     sr    F				!								
N(   t   __name__t
   __module__t   tsbaset   _tsa_doct   baset   _missing_param_doct   __doc__R5   R4   R;   R@   RB   RX   R\   R   Rl   Rt   R{   R   R   R   R   R   R   R   R   R   (    (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR   7   s.   
				
	#T			%	'				8R   c           B   s  e  Z d  Z i  Z d d d  Z e   d    Z e   d    Z e	 d    Z
 e	 d    Z e	 d    Z e	 d    Z e	 d	    Z e	 d
    Z e	 d    Z e	 d    Z e	 d    Z d d e d  Z e j j j d  Z d j e d  e d  e _ RS(   s
  
    Class to hold results from fitting an AR model.

    Parameters
    ----------
    model : AR Model instance
        Reference to the model that is fit.
    params : array
        The fitted parameters from the AR Model.
    normalized_cov_params : array
        inv(dot(X.T,X)) where X is the lagged values.
    scale : float, optional
        An estimate of the scale of the model.

    Attributes
    ----------

    aic : float
        Akaike Information Criterion using Lutkephol's definition.
        :math:`log(sigma) + 2*(1 + k_ar + k_trend)/nobs`
    bic : float
        Bayes Information Criterion
        :math:`\log(\sigma) + (1 + k_ar + k_trend)*\log(nobs)/nobs`
    bse : array
        The standard errors of the estimated parameters. If `method` is 'cmle',
        then the standard errors that are returned are the OLS standard errors
        of the coefficients. If the `method` is 'mle' then they are computed
        using the numerical Hessian.
    fittedvalues : array
        The in-sample predicted values of the fitted AR model. The `k_ar`
        initial values are computed via the Kalman Filter if the model is
        fit by `mle`.
    fpe : float
        Final prediction error using Lütkepohl's definition
        ((n_totobs+k_trend)/(n_totobs-k_ar-k_trend))*sigma
    hqic : float
        Hannan-Quinn Information Criterion.
    k_ar : float
        Lag length. Sometimes used as `p` in the docs.
    k_trend : float
        The number of trend terms included. 'nc'=0, 'c'=1.
    llf : float
        The loglikelihood of the model evaluated at `params`. See `AR.loglike`
    model : AR model instance
        A reference to the fitted AR model.
    nobs : float
        The number of available observations `nobs` - `k_ar`
    n_totobs : float
        The number of total observations in `endog`. Sometimes `n` in the docs.
    params : array
        The fitted parameters of the model.
    pvalues : array
        The p values associated with the standard errors.
    resid : array
        The residuals of the model. If the model is fit by 'mle' then the
        pre-sample residuals are calculated using fittedvalues from the Kalman
        Filter.
    roots : array
        The roots of the AR process are the solution to
        (1 - arparams[0]*z - arparams[1]*z**2 -...- arparams[p-1]*z**k_ar) = 0
        Stability requires that the roots in modulus lie outside the unit
        circle.
    scale : float
        Same as sigma2
    sigma2 : float
        The variance of the innovations (residuals).
    trendorder : int
        The polynomial order of the trend. 'nc' = None, 'c' or 't' = 0,
        'ct' = 1, etc.
    tvalues : array
        The t-values associated with `params`.
    g      ?c   	      C   s   t  t |   j | | | |  i  |  _ | j |  _ t | j  } | |  _ | j |  _ | j	 |  _	 | j
 } | |  _
 | j } | |  _ d  } | d k r | d } n  | |  _ | | |  _ | |  j |  _ |  j _ d  S(   Ni    i   (   R3   R   R4   t   _cacheRu   Rd   R(   t   n_totobsRb   Rv   R   R$   R5   t
   trendordert   df_modelt   df_residR-   (	   R8   R-   R#   R   t   scaleR   R   R$   R   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR4     s$    							c         C   s>   |  j  } | j d k r0 d |  j t |  j  S|  j  j Sd  S(   NR   g      ?(   R-   R   Ru   R   t   residRz   (   R8   R-   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyRz     s    	c         C   s   |  j  S(   N(   Rz   (   R8   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR     s    c         C   s   |  j  j d k rj |  j } t j | |  } | |  j |  j |  j } t j t j	 |  j
 d |    St |  j |  j  j  } t j t j	 t j j |    Sd  S(   NR   R   (   R-   R   R   R   R   Ru   R   R$   t   sqrtRo   t
   cov_paramsR   R#   R   R   R   (   R8   R   Ry   t	   ols_scalet   hess(    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   bse  s    	"c         C   s   t  j t j |  j   d S(   Ni   (   R   t   sfR   R   R   (   R8   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   pvalues  s    c         C   s&   t  j |  j  d d |  j |  j S(   Ni   i   (   R   Rw   Rz   R   Ru   (   R8   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR     s    c         C   sB   |  j  } t j |  j  d t j t j |   | d |  j S(   Ni   i   (   Ru   R   Rw   Rz   R   (   R8   Ru   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR     s    	,c         C   s)   |  j  } |  j } | | | | |  j S(   N(   Ru   R   Rz   (   R8   Ru   R   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   fpe  s    		c         C   s5   |  j  } t j |  j  d |  j t j |  | S(   Ni   (   Ru   R   Rw   Rz   R   (   R8   Ru   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR     s    	c         C   sQ   |  j  } | j j   } | j d k r9 | |  j |  j S| j j   |  j Sd  S(   NR   (   R-   R(   R`   R   R   Rg   (   R8   R-   R(   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR      s
    	c         C   s/   |  j  } t j t j d |  j | f  d S(   Ni   i(   R$   R   t   rootsRe   R#   (   R8   R>   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR     s    	c         C   s   |  j  j |  j  S(   N(   R-   Rl   R#   (   R8   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyRg     s    c         C   s(   |  j  } |  j j | | | |  } | S(   N(   R#   R-   Rl   (   R8   R   RK   R   R#   RL   (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyRl     s    	s   
i   i   N(   R   R   R   R   R5   R4   R   Rz   R   R   R   R   R   R   R   R   R   R   Rg   R   Rl   R   t   splitt   preddoct   join(    (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR   Z  s"   HR   c           B   sD   e  Z i  Z e j e j j e  Z i  Z e j e j j	 e  Z	 RS(    (
   R   R   t   _attrst   wrapt   union_dictsR   t   TimeSeriesResultsWrappert   _wrap_attrst   _methodst   _wrap_methods(    (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyR   "  s   	t   __main__t	   as_pandasR   i	   R   RY   R   t   bfgsR   i  t   gtolg|=t   yeari  R:   t   At
   start_datet   lengthR   t   periodss   A-DECR]   i  i  i  i  i  i  i  i  g     ~@g      ?(^   t
   __future__R    t   statsmodels.compat.pythonR   R   R   t   numpyR   R   R   t   numpy.linalgR   R   t   scipy.statsR   t#   statsmodels.regression.linear_modelR	   t   statsmodels.tsa.tsatoolsR
   R   R   R   t   statsmodels.tsa.base.tsa_modelt   tsaR   t	   tsa_modelR   t   statsmodels.base.modelR-   t   statsmodels.tools.decoratorsR   R   t   statsmodels.tools.numdiffR   R   t$   statsmodels.tsa.kalmanf.kalmanfilterR   t   statsmodels.base.wrappert   wrapperR   t   statsmodels.tsa.vector_arR   t   __all__R   R    R,   t   TimeSeriesModelR   t   TimeSeriesModelResultsR   t   ResultsWrapperR   t   populate_wrapperR   t   statsmodels.apit   apit   smt   datasetst   sunspotst   loadR   R(   t   ar_olsR   t   res_olst   ar_mlet   res_mle_bfgst   pandast   scikits.timeseriest
   timeseriest   tst   Datet   d1t
   date_arrayRd   t   ts_drt   DatetimeIndext   datetimet	   pandas_drt   arangeR9   R}   t   fromordinalt	   toordinalt   astypeR   t   dt_datest   Seriest   modR   t   IBMt   difft   wt   theta(    (    (    s7   lib/python2.7/site-packages/statsmodels/tsa/ar_model.pyt   <module>   sd   "		  %$!	-