code: def _prepare_rerp_preds(
      n_samples,
      sfreq,
      events,
      event_id=None,
      tmin=-0.1,
      tmax=1,
      covariates=None,
  ):
      """Build predictor matrix and metadata (e.g. condition time windows)."""
      conds = list(event_id)
      if covariates is not None:
          conds += list(covariates)
  
      # time windows (per event type) are converted to sample points from times
      # int(round()) to be safe and match Epochs constructor behavior
      if isinstance(tmin, (float, int)):
          tmin_s = {cond: int(round(tmin * sfreq)) for cond in conds}
      else:
          tmin_s = {
              cond: int(round(tmin.get(cond, -0.1) * sfreq))
              for cond in conds
          }
      if isinstance(tmax, (float, int)):
          tmax_s = {
              cond: int(round(tmax * sfreq) + 1) for cond in conds
          }
      else:
          tmax_s = {
              cond: int(round(tmax.get(cond, 1.0) * sfreq)) + 1
              for cond in conds
          }
  
      # Construct predictor matrix
      # We do this by creating one array per event type, shape (lags, samples)
      # (where lags depends on tmin/tmax and can be different for different
      # event types). Columns correspond to predictors, predictors correspond to
      # time lags. Thus, each array is mostly sparse, with one diagonal of 1s
      # per event (for binary predictors).
  
      cond_length = dict()
      xs = []
      for cond in conds:
          tmin_, tmax_ = tmin_s[cond], tmax_s[cond]
          n_lags = int(tmax_ - tmin_)  # width of matrix
          if cond in event_id:  # for binary predictors
              ids = (
                  [event_id[cond]]
                  if isinstance(event_id[cond], int)
                  else event_id[cond]
              )
              onsets = -(events[np.isin(events[:, 2], ids), 0] + tmin_)
              values = np.ones((len(onsets), n_lags))
  
          else:  # for predictors from covariates, e.g. continuous ones
              covs = covariates[cond]
              if len(covs) != len(events):
                  error = (
                      f"Condition {cond} from ``covariates`` is not the same length as "
                      "``events``"
                  )
                  raise ValueError(error)
              onsets = -(events[np.where(covs != 0), 0] + tmin_)[0]
              v = np.asarray(covs)[np.nonzero(covs)].astype(float)
              values = np.ones((len(onsets), n_lags)) * v[:, np.newaxis]
  
          cond_length[cond] = len(onsets)
          xs.append(
              sparse.dia_matrix(
                  (values, onsets), shape=(n_samples, n_lags)
              )
          )
  
      return sparse.hstack(xs), conds, cond_length, tmin_s, tmax_s
  
file_path: mne-python/mne/stats/regression.py
imports: from collections import namedtuple
  from inspect import isgenerator
  import numpy
  from scipy import linalg, sparse, stats
  from .._fiff.pick import _picks_to_idx, pick_info, pick_types
  from ..epochs import BaseEpochs
  from ..evoked import Evoked, EvokedArray
  from ..source_estimate import SourceEstimate
  from ..utils import _reject_data_segments, fill_doc, logger, warn
label_desc: Use image node_id 5 for calling a global function with example usage: _prepare_rerp_preds(n_samples, sfreq, events, event_id, tmin, tmax, covariates) and returns: sparse,  conds,  cond_length,  tmin_s,  tmax_s