code: def add_beta_var_lm(info_dict):
      """Adds the covariance matrix for estimated coefficients to `info_dict` for linear models.
  
      The covariance matrix for estimated coefficients is defined as
  
      .. code-block:: none
  
          mse * (X'WX+aI)^-1X'X(X'WX+aI)
  
      for linear models, and defined as the inverse Fisher information matrix
      divided by ``n_sample`` for generalized linear models.
  
      Only variance of beta hat information will be added in this function.
      A series of these functions are used in a flow to get all information needed
      in linear model summary. The flow is
      `~greykite.algo.common.model_summary_utils.create_info_dict_lm`,
      `~greykite.algo.common.model_summary_utils.add_model_params_lm`,
      `~greykite.algo.common.model_summary_utils.add_model_df_lm`,
      `~greykite.algo.common.model_summary_utils.add_model_ss_lm`,
      `~greykite.algo.common.model_summary_utils.add_beta_var_lm`,
      `~greykite.algo.common.model_summary_utils.add_model_coef_df_lm`,
      `~greykite.algo.common.model_summary_utils.add_model_significance_lm`.
      For flow implementation, see
      `~greykite.algo.common.model_summary_utils.get_info_dict_lm`.
  
      Parameters
      ----------
      info_dict : `dict`
          The information dictionary returned by
          `~greykite.algo.common.model_summary_utils.add_model_ss_lm`.
  
      Returns
      -------
      info_dict : `dict`
          The information dictionary with the following keys added:
  
              "beta_var_cov" : `numpy.array` or `None`
                  The covariance matrix of estimated coefficients. The square root of
                  its diagonal elements are standard errors of the estimated coefficients.
                  Set as ``None`` for sparse solutions.
      """
      if (
          info_dict["fit_algorithm"]
          in [
              "statsmodels_ols",
              "statsmodels_wls",
              "statsmodels_gls",
              "linear",
              "ridge",
          ]
          or info_dict["fit_algorithm"] in ["sgd", "elastic_net"]
          and info_dict["l1_ratio"] == 0
      ):
          xtwx_alphai_inv = info_dict["xtwx_alphai_inv"]
          mse = info_dict["mse"]
          # Variance of estimated coefficients mse * (X'WX+aI)^-1X'X(X'WX+aI)^-1
          x_nz = info_dict["x_nz"]
          info_dict["beta_var_cov"] = (
              xtwx_alphai_inv @ x_nz.T @ x_nz @ xtwx_alphai_inv * mse
          )
      elif info_dict["fit_algorithm"] in ["statsmodels_glm"]:
          # Variance of mle is approximately I(beta_hat)^-1/n, where I is Fisher's information matrix.
          assert isinstance(
              info_dict["ml_model"],
              statsmodels.genmod.generalized_linear_model.GLMResultsWrapper,
          )
          info_dict["beta_var_cov"] = info_dict["ml_model"].cov_params()
      else:
          info_dict[
              "beta_var_cov"
          ] = None  # The covariance matrix for beta is not support with sparse solution
      return info_dict
  
imports: import numpy
  import pandas
  import statsmodels
  import statsmodels.api
  from scipy.stats import f
  from scipy.stats import norm
  from scipy.stats import t
  from sklearn.base import clone
  from sklearn.linear_model import Ridge
  from sklearn.model_selection import train_test_split
  from greykite.algo.common.col_name_utils import INTERCEPT
  from greykite.algo.common.col_name_utils import simplify_pred_cols
label_desc: Use image node_id 7 for calling a global function with example usage: add_beta_var_lm(info_dict) and returns: info_dict