code: def test_results():
      m = OLSModel(x)
      r = m.fit(y)
      # results hand compared with R's printout
  
      assert f"{r.R2:0.4f}" == "0.5737"
      assert f"{r.R2_adj:0.4f}" == "0.5242"
  
      f = r.F_overall
      assert f"{f['F']:0.2f}" == "11.59"
      assert f["df_num"] == 13
      assert f["df_den"] == 112
      assert f"{f['p_value']:0.3e}" == "1.818e-15"
  
      # test Fcontrast, the 8th column of m.design is all 1s
      # let's construct a contrast matrix that tests everything
      # but column 8 is zero
  
      M = np.identity(14)
      M = np.array(
          [M[i] for i in [0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13]]
      )
      Fc = r.Fcontrast(M)
      assert_array_almost_equal([Fc.F], [f["F"]], 6)
      assert_array_almost_equal([Fc.df_num], [f["df_num"]], 6)
      assert_array_almost_equal([Fc.df_den], [f["df_den"]], 6)
  
      thetas = []
      sds = []
      ts = []
      ps = []
  
      # the model has an intercept
  
      assert r.model.has_intercept
  
      # design matrix has full rank
  
      assert r.model.rank == 14
  
      # design matrix has full rank
  
      assert r.df_model == 14
      assert r.df_total == 126
      assert r.df_resid == 112
  
      # entries with '*****' are not tested as they were a different format
  
      resultstr = """
  X1   1.439e-02  2.649e-02   0.543   0.5881
  X2  -6.975e+00  1.022e+01  -0.683   0.4963
  X3   4.410e+01  5.740e+00   7.682   ******
  X4   3.864e+00  5.770e+00   0.670   0.5044
  X5   2.458e+02  4.594e+02   0.535   0.5937
  X6   9.789e+02  3.851e+02   2.542   0.0124
  X7   1.339e+03  8.418e+02   1.591   0.1145
  X8   2.603e+02  8.226e-01 316.463   ******
  X9  -1.955e-02  1.539e-02  -1.270   0.2066
  X10  7.042e-05  2.173e-04   0.324   0.7465
  X11 -3.743e-08  6.770e-07  -0.055   0.9560
  X12  3.060e-06  2.094e-06   1.461   0.1469
  X13  1.440e-06  1.992e-06   0.723   0.4711
  X14 -1.044e-05  7.215e-06  -1.448   0.1505
  X1   1.439e-02  2.649e-02   0.543   0.5881
  X2  -6.975e+00  1.022e+01  -0.683   0.4963
  X3   4.410e+01  5.740e+00   7.682   ******
  X4   3.864e+00  5.770e+00   0.670   0.5044
  X5   2.458e+02  4.594e+02   0.535   0.5937
  X6   9.789e+02  3.851e+02   2.542   0.0124
  X7   1.339e+03  8.418e+02   1.591   0.1145
  X8   2.603e+02  8.226e-01 316.463   ******
  X9  -1.955e-02  1.539e-02  -1.270   0.2066
  X10  7.042e-05  2.173e-04   0.324   0.7465
  X11 -3.743e-08  6.770e-07  -0.055   0.9560
  X12  3.060e-06  2.094e-06   1.461   0.1469
  X13  1.440e-06  1.992e-06   0.723   0.4711
  X14 -1.044e-05  7.215e-06  -1.448   0.1505
  """
  
      for row in resultstr.strip().split("\n"):
          row = row.strip()
          _, th, sd, t, p = row.split()
          thetas.append(th)
          sds.append(sd)
          ts.append(t)
          ps.append(p)
  
      for th, thstr in zip(r.theta, thetas):
          assert f"{th:0.3e}" == thstr
  
      for sd, sdstr in zip(
          [np.sqrt(r.vcov(column=i)) for i in range(14)], sds
      ):
          assert f"{sd:0.3e}" == sdstr
  
      for t, tstr in zip([r.t(column=i) for i in range(14)], ts):
          assert f"{t:0.3f}" == tstr
  
      for i, t in enumerate([r.t(column=i) for i in range(14)]):
          m = np.zeros((14,))
          m[i] = 1.0
          tv = r.Tcontrast(m)
          e = r.theta[i]
          sd = np.sqrt(r.vcov(column=i))
          assert_almost_equal(tv.t, t, 6)
          assert_almost_equal(tv.sd, sd, 6)
          assert_almost_equal(tv.effect, e, 6)
  
      for p, pstr in zip(
          [
              2 * scipy.stats.t.sf(np.fabs(r.t(column=i)), r.df_resid)
              for i in range(14)
          ],
          ps,
      ):
          if pstr.find("*") < 0:
              assert f"{p:0.4f}" == pstr
  
      assert f"{r.SSE:0.5f}" == "72.02328"
      assert f"{r.SST:0.4f}" == "168.9401"
      assert f"{r.SSR:0.5f}" == "96.91685"
  
      assert f"{r.MSE:0.6f}" == "0.643065"
      assert f"{r.MST:0.6f}" == "1.351521"
      assert f"{r.MSR:0.6f}" == "7.455142"
  
      assert f"{np.sqrt(r.MSE):0.4f}" == "0.8019"
  
      # the difference here comes from the fact that
      # we've treated sigma as a nuisance parameter,
      # so our AIC is the AIC of the profiled log-likelihood...
  
      assert f"{r.AIC + 2:0.4f}" == "317.1017"
      assert f"{r.BIC + np.log(126):0.4f}" == "359.6459"
  
imports: import numpy
  import scipy.stats
  from numpy.testing import assert_almost_equal, assert_array_almost_equal
  import nipy.testing
  from ..regression import OLSModel
  from .exampledata import x, y
label_desc: Use image node_id 1 for calling a global function with example usage: test_results() without return types