code: def test_p_from_null():
      import numpy as np
      from brainiak.utils.utils import p_from_null
  
      # Create random null and observed value in tail
      null = np.random.randn(10000)
      observed = np.ceil(np.percentile(null, 97.5) * 1000) / 1000
  
      # Check that we catch improper side
      with pytest.raises(ValueError):
          _ = p_from_null(observed, null, side="wrong")
  
      # Check two-tailed p-value for observed
      p_ts = p_from_null(observed, null)
      assert np.isclose(p_ts, 0.05, atol=1e-02)
  
      # Check two-tailed p-value for observed
      p_right = p_from_null(observed, null, side="right")
      assert np.isclose(p_right, 0.025, atol=1e-02)
      assert np.isclose(p_right, p_ts / 2, atol=1e-02)
  
      # Check two-tailed p-value for observed
      p_left = p_from_null(observed, null, side="left")
      assert np.isclose(p_left, 0.975, atol=1e-02)
      assert np.isclose(1 - p_left, p_right, atol=1e-02)
      assert np.isclose(1 - p_left, p_ts / 2, atol=1e-02)
  
      # Check 2-dimensional input (i.e., samples by voxels)
      null = np.random.randn(10000, 3)
      observed = (
          np.ceil(np.percentile(null, 97.5, axis=0) * 1000) / 1000
      )
  
      # Check two-tailed p-value for observed
      p_ts = p_from_null(observed, null, axis=0)
      assert np.allclose(p_ts, 0.05, atol=1e-02)
  
      # Check two-tailed p-value for observed
      p_right = p_from_null(observed, null, side="right", axis=0)
      assert np.allclose(p_right, 0.025, atol=1e-02)
      assert np.allclose(p_right, p_ts / 2, atol=1e-02)
  
      # Check two-tailed p-value for observed
      p_left = p_from_null(observed, null, side="left", axis=0)
      assert np.allclose(p_left, 0.975, atol=1e-02)
      assert np.allclose(1 - p_left, p_right, atol=1e-02)
      assert np.allclose(1 - p_left, p_ts / 2, atol=1e-02)
  
      # Check for exact test
      p_ts = p_from_null(observed, null, exact=True, axis=0)
      assert np.allclose(p_ts, 0.05, atol=1e-02)
  
      # Check two-tailed p-value for exact
      p_right = p_from_null(
          observed, null, side="right", exact=True, axis=0
      )
      assert np.allclose(p_right, 0.025, atol=1e-02)
      assert np.allclose(p_right, p_ts / 2, atol=1e-02)
  
      # Check two-tailed p-value for exact
      p_left = p_from_null(
          observed, null, side="left", exact=True, axis=0
      )
      assert np.allclose(p_left, 0.975, atol=1e-02)
      assert np.allclose(1 - p_left, p_right, atol=1e-02)
      assert np.allclose(1 - p_left, p_ts / 2, atol=1e-02)
  
file_path: brainiak/tests/utils/test_utils.py
imports: import pytest
label_desc: Use image node_id 8 for calling a global function with example usage: test_p_from_null() without return types