class_docstr: Metric for testing factorial designs assuming a main effects only
  logit model.
class_docstr_tok: ["Metric","for","testing","factorial","designs","assuming","a","main","effects","only","logit","model","."]
code: def fetch_trial_data(
      self, trial: BaseTrial, **kwargs: Any
  ) -> MetricFetchResult:
      try:
          if not isinstance(trial, BatchTrial):
              raise ValueError(
                  "Factorial metric can only fetch data for batch trials."
              )
          if not trial.status.expecting_data:
              raise ValueError(
                  "Can only fetch data if trial is expecting data."
              )
  
          data = []
          normalized_arm_weights = trial.normalized_arm_weights()
          for name, arm in trial.arms_by_name.items():
              weight = normalized_arm_weights[arm]
              mean, sem = evaluation_function(
                  parameterization=arm.parameters,
                  weight=weight,
                  coefficients=self.coefficients,
                  batch_size=self.batch_size,
                  noise_var=self.noise_var,
              )
              n = np.random.binomial(self.batch_size, weight)
              data.append(
                  {
                      "arm_name": name,
                      "metric_name": self.name,
                      "mean": mean,
                      "sem": sem,
                      "trial_index": trial.index,
                      "n": n,
                      "frac_nonnull": mean,
                  }
              )
          return Ok(value=Data(df=pd.DataFrame(data)))
  
      except Exception as e:
          return Err(
              MetricFetchE(
                  message=f"Failed to fetch {self.name}", exception=e
              )
          )
  
file_path: Ax/ax/metrics/factorial.py
imports: from typing import Any, Dict, Tuple
  import numpy
  import pandas
  from ax.core.base_trial import BaseTrial
  from ax.core.batch_trial import BatchTrial
  from ax.core.data import Data
  from ax.core.metric import Metric, MetricFetchE, MetricFetchResult
  from ax.core.types import TParameterization, TParamValue
  from ax.utils.common.result import Err, Ok
  from ax.utils.stats.statstools import agresti_coull_sem
label_desc: Use image node_id 3 for calling the FactorialMetric obj's underlying member method code with example usage: obj.fetch_trial_data(trial) and returns: Ok, Err