title: Can't perform chi-squared test statistic of OLS regression in Python
body: <p>it's my first time here and I'm new to programming.</p>
  <p>I regressed a column of my df against another with stats.linregress and I'm trying to evaluate the goodness of fit with the Chi Square Statistic test, and I tried 2 methods, scipy.stats.chi2_contingency() and scipy.stats.chisquare(), problem is I can't get frequencies from the columns that are readable by the methods (this is what I think anyway).</p>
  <p>The code is:</p>
  <pre><code>    import os
      import pandas as pd
      import numpy as np
      import scipy
      from scipy import stats
  
      df3 = pd.read_csv('MODELLO RAVASI-MARK UP shock1+control-table.csv', thousands=',')
      df_cntrl_reg = df3.loc [(df3['time'] &gt; 34) &amp; (df3['wageShock'] == 1) &amp;     
      (df3['wageSchockTime']==30)]
      
  
      x = df_cntrl_reg.time
      y = df_cntrl_reg.profits
      slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
      stats.linregress(x,y)
  </code></pre>
  <p>output:LinregressResult(slope=57.735721968728164, intercept=-1788.6653717798467, rvalue=0.014085574855596942, pvalue=0.47927072225571066, stderr=81.59589542103119)</p>
  <pre><code>    df_cntrl_reg['predicted'] = 57.735721968728164*df_cntrl_reg.time -1788.6653717798467
      obs = df_cntrl_reg['profits'].value_counts()
      exp = df_cntrl_reg['predicted'].value_counts()
      scipy.stats.chisquare(f_obs = obs, f_exp = exp, ddof = 1)
  </code></pre>
  <p>But there I get
  ValueError: operands could not be broadcast together with shapes (2525,) (25,</p>
  <p>I tried to apply the method .ravel() like this:</p>
  <pre><code>    obs = df_cntrl_reg['profits'].value_counts().ravel()
      exp = df_cntrl_reg['predicted'].value_counts().ravel()
  </code></pre>
  <p>But this didn't change anything.</p>
  <p>I tried to use  scipy.stats.chi2_contingency():</p>
  <pre><code>    table = [df_cntrl_reg['predetti'], df_cntrl_reg.profits]
      scipy.stats.chi2_contingency(table)
  </code></pre>
  <p>but i get ValueError: All values in <code>observed</code> must be nonnegative.</p>
  <p>I also tried this to get the table:</p>
  <pre><code>   to_test = df_cntrl_reg[['profits', 'predetti']]
     table = to_test.apply(pd.Series.value_counts(bins=10))
  </code></pre>
  <p>but i get TypeError: value_counts() missing 1 required positional argument: 'self'</p>
  <p>Can you help me with an easy way to get the statistic? I don't need to use the methof itself,
  simply to obtain the statistic, I can get the p-value from the tables. I'm using python 3 on jupiter
  notebook and my OS is win 10 (I know I know, but until very recently I've never needed to program anything).
  Thanks in advance</p>