code: def test_f_twoway_rm():
      """Test 2-way anova."""
      rng = np.random.RandomState(42)
      iter_params = product(
          [4, 10], [2, 15], [4, 6, 8], ["A", "B", "A:B"], [False, True]
      )
      _effects = {4: [2, 2], 6: [2, 3], 8: [2, 4]}
      for params in iter_params:
          n_subj, n_obs, n_levels, effects, correction = params
          data = rng.random_sample([n_subj, n_levels, n_obs])
          fvals, pvals = f_mway_rm(
              data, _effects[n_levels], effects, correction=correction
          )
          assert (fvals >= 0).all()
          if pvals.any():
              assert ((0 <= pvals) & (1 >= pvals)).all()
          n_effects = len(_map_effects(n_subj, effects)[0])
          assert fvals.size == n_obs * n_effects
          if n_effects == 1:  # test for principle of least surprise ...
              assert fvals.ndim == 1
  
          fvals_ = f_threshold_mway_rm(
              n_subj, _effects[n_levels], effects
          )
          assert (fvals_ >= 0).all()
          assert fvals_.size == n_effects
  
      # check time-frequency input
      n_subj, n_freqs, n_times, n_levels = (5, 10, 101, 4)
      data = rng.random_sample([n_subj, n_levels, n_freqs, n_times])
      fvals, pvals = f_mway_rm(data, _effects[n_levels])
      assert fvals.shape[1:] == pvals.shape[1:] == (n_freqs, n_times)
  
      data = rng.random_sample([n_subj, n_levels, 1])
      pytest.raises(
          ValueError,
          f_mway_rm,
          data,
          _effects[n_levels],
          effects="C",
          correction=correction,
      )
      data = rng.random_sample([n_subj, n_levels, n_obs, 3])
      # check for dimension handling
      f_mway_rm(
          data, _effects[n_levels], effects, correction=correction
      )
  
      # now check against external software results
      test_data = generate_data(n_subjects=20, n_conditions=6)
      fvals, pvals = f_mway_rm(test_data, [2, 3])
  
      assert_array_almost_equal(fvals, test_external["spss_fvals"], 3)
      assert_array_almost_equal(
          pvals, test_external["spss_pvals_uncorrected"], 3
      )
      assert_array_almost_equal(fvals, test_external["r_fvals"], 4)
      assert_array_almost_equal(
          pvals, test_external["r_pvals_uncorrected"], 3
      )
  
      _, pvals = f_mway_rm(test_data, [2, 3], correction=True)
      assert_array_almost_equal(
          pvals, test_external["spss_pvals_corrected"], 3
      )
  
      test_data = generate_data(n_subjects=20, n_conditions=8)
      fvals, _ = f_mway_rm(test_data, [2, 2, 2])
      assert_array_almost_equal(fvals, test_external["r_fvals_3way"], 5)
  
      fvals, _ = f_mway_rm(test_data, [8], "A")
      assert_array_almost_equal(fvals, test_external["r_fvals_1way"], 5)
  
file_path: mne-python/mne/stats/tests/test_parametric.py
imports: from functools import partial
  from itertools import product
  import numpy
  import pytest
  import scipy.stats
  from numpy.testing import assert_allclose, assert_array_almost_equal, assert_array_less
  import mne
  from mne.stats.parametric import _map_effects, f_mway_rm, f_threshold_mway_rm
label_desc: Use image node_id 3 for calling a global function with example usage: test_f_twoway_rm() without return types