U
    Ãmœd‘  ã                   @   sx   d dl Z d dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ G dd„ dƒZdd	„ ZG d
d„ dƒZdS )é    N)Úassert_equal)Úsummary_col)Úadd_constant)ÚOLSc                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestSummaryLatexc                 C   sx   d}dddddg}t |ƒ}dddddg}d	dd
ddg}t||ƒ ¡ }t||ƒ ¡ }t||gƒ ¡ }d| }t||ƒ d S ©NaË  
\begin{table}
\caption{}
\label{}
\begin{center}
\begin{tabular}{lll}
\hline
               & y I      & y II      \\
\hline
const          & 7.7500   & 12.4231   \\
               & (1.1058) & (3.1872)  \\
x1             & -0.7500  & -1.5769   \\
               & (0.2368) & (0.6826)  \\
R-squared      & 0.7697   & 0.6401    \\
R-squared Adj. & 0.6930   & 0.5202    \\
\hline
\end{tabular}
\end{center}
\end{table}
\bigskip
Standard errors in parentheses.
é   é   é   é   é   é   é   é   r   é   z
%s
)r   r   Úfitr   Úas_latexr   ©ÚselfÚdesiredÚxÚy1Úy2Úreg1Úreg2Úactual© r   ú^/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/statsmodels/iolib/tests/test_summary2.pyÚtest_summarycol   s    z TestSummaryLatex.test_summarycolc           	      C   s¾   d}dddddg}t |ƒ}dddddg}d	dd
ddg}t||ƒ ¡ }t||ƒ ¡ }t||gdd� ¡ }d| }t||ƒ t||gddd�}dt|ƒksšt‚dt|ƒksªt‚dt|ƒksºt‚d S )Na/  
==========================
                y I   y II
--------------------------
const          7.7   12.4 
               (1.1) (3.2)
x1             -0.7  -1.6 
               (0.2) (0.7)
R-squared      0.8   0.6  
R-squared Adj. 0.7   0.5  
==========================
Standard errors in
parentheses.
r   r	   r
   r   r   r   r   r   r   r   z%0.1f©Úfloat_formatz%s
T)Ústarsr    z7.7***z12.4**z12.4***)r   r   r   r   Zas_textr   ÚstrÚAssertionError)	r   r   r   r   r   r   r   r   Zstarredr   r   r   Útest_summarycol_float_format1   s    
z-TestSummaryLatex.test_summarycol_float_formatc              
   C   sÖ   dddddg}t |ƒ}t |t dgdgdgdgdgg¡gd¡}d	dd
ddg}dddddg}t||ƒ ¡ }t||ƒ ¡ }t||gddgdd�}dt|ƒksžt‚t||gdgdd�}dt|ƒksÂt‚dt|ƒksÒt‚d S )Nr   r	   r
   r   é	   éÿÿÿÿr   r   r   r   r   r   ÚconstÚx1T)Úregressor_orderZdrop_omittedÚx2F)	r   ÚnpÚconcatenateÚarrayr   r   r   r"   r#   )r   r   r*   r   r   r   r   r   r   r   r   Útest_summarycol_drop_omittedP   s     *ÿÿz-TestSummaryLatex.test_summarycol_drop_omittedc              
   C   s
  dddddg}t |ƒ}t |t dgdgdgdgdgg¡gd¡}tj|d	d
dgd�}dddddg}dddddg}t||ƒ ¡ }t||ƒ ¡ }dd„ dd„ dœ}t||gdd� }}	t||gdd
gd|d�}	d}
t	|ƒ 
d¡D ](}|
D ]}| |¡rä|t	|	ƒksät‚qäqÜd S )Nr   r	   r
   r   r%   r&   r   r   r'   ÚbÚa)Úcolumnsr   r   r   r   c                 S   s   d  t| jƒ¡S )Nz{:.3f})ÚformatÚintZrsquared©r   r   r   r   Ú<lambda>l   ó    zFTestSummaryLatex.test_summary_col_ordering_preserved.<locals>.<lambda>c                 S   s   d  t| jƒ¡S )Nz{0:d})r2   r3   Znobsr4   r   r   r   r5   m   r6   )ZR2ÚNz%0.4fr   )r)   r    Ú	info_dict)r'   r/   r0   Ú
)r   r+   r,   r-   ÚpdZ	DataFramer   r   r   r"   ÚsplitÚ
startswithr#   )r   r   r*   r   r   r   r   r8   Úoriginalr   Ú	variablesÚlineÚvariabler   r   r   Ú#test_summary_col_ordering_preserveda   s*    *ÿþ
z4TestSummaryLatex.test_summary_col_ordering_preservedc                 C   sx   d}dddddg}t |ƒ}dddddg}d	dd
ddg}t||ƒ ¡ }t||ƒ ¡ }t||gƒ ¡ }d| }t||ƒ d S r   )r   r   r   r   Z_repr_latex_r   r   r   r   r   Útest__repr_latex_x   s    z"TestSummaryLatex.test__repr_latex_c              	   C   sx   dddddg}t |ƒ}dddddg}t||ƒ ¡ }t ¡ � t d¡ | ¡  ¡ }W 5 Q R X d	}||k}|d
kstt‚d S )Nr   r	   r
   r   r   r   r   Úignorez\end{tabular}
\begin{tabular}T)	r   r   r   ÚwarningsÚcatch_warningsÚsimplefilterÚsummaryr   r#   )r   r   r   r   r   Zstring_to_findÚresultr   r   r   Útest_OLSsummaryš   s    

z TestSummaryLatex.test_OLSsummaryN)	Ú__name__Ú
__module__Ú__qualname__r   r$   r.   rA   rB   rI   r   r   r   r   r      s   ""r   c               	   C   s   ddddddddg} ddddddd	dg}t |t| ƒƒ ¡ }d
}t t¡� |t| ¡ ƒks^t‚W 5 Q R X t t¡� |t| 	¡ ƒksˆt‚W 5 Q R X t || dd� ¡ }d}t t¡� |t| ¡ ƒksÈt‚W 5 Q R X t t¡� |t| 	¡ ƒksòt‚W 5 Q R X d S )Nr   r	   r
   r   r   r   r   r%   é
   z
R-squared:F)ÚhasconstzR-squared (uncentered):)
r   r   r   ÚpytestZwarnsÚUserWarningr"   Zsummary2r#   rG   )r   ÚyZreg_with_constantZr2_strZreg_without_constantr   r   r   Útest_ols_summary_rsquared_label«   s    rR   c                   @   s,   e Zd ZdZedd„ ƒZdd„ Zdd„ ZdS )	ÚTestSummaryLabelsz@
    Test that the labels are correctly set in the summary tablec                 C   s:   ddddgd }t ddddgd ƒ}t||d� ¡ | _d S )Nr   r   r   r   )ZendogZexog)r   r   r   Úmod)ÚclsrQ   r   r   r   r   Úsetup_classÂ   s    zTestSummaryLabels.setup_classc                 C   s2   t | jdd�}dt|ƒkst‚dt|ƒks.t‚d S )NT©ÚresultsZ
include_r2zR-squared  úR-squared Adj.©r   rT   r"   r#   ©r   Útabler   r   r   Útest_summary_col_r2È   s    z%TestSummaryLabels.test_summary_col_r2c                 C   s2   t | jdd�}dt|ƒkst‚dt|ƒks.t‚d S )NFrW   z	R-squaredrY   rZ   r[   r   r   r   Útest_absence_of_r2Î   s    z$TestSummaryLabels.test_absence_of_r2N)rJ   rK   rL   Ú__doc__ÚclassmethodrV   r]   r^   r   r   r   r   rS   ¾   s
   
rS   )rD   Únumpyr+   Zpandasr:   rO   Znumpy.testingr   Zstatsmodels.iolib.summary2r   Zstatsmodels.tools.toolsr   Z#statsmodels.regression.linear_modelr   r   rR   rS   r   r   r   r   Ú<module>   s    