class_docstr: Initialize IVEstimator object.
  
  Parameters
  ----------
  model: pgmpy.models.SEM
      The model for which estimation need to be done.
  
  Examples
  --------
class_docstr_tok: ["Initialize","IVEstimator","object",".","Parameters","--","--","--","--","--","model",":","pgmpy.models.SEM","The","model","for","which","estimation","need","to","be","done",".","Examples","--","--","--","--"]
docstr: Estimates the parameter X -> Y.
  
  Parameters
  ----------
  X: str
      The covariate variable of the parameter being estimated.
  
  Y: str
      The predictor variable of the parameter being estimated.
  
  data: pd.DataFrame
      The data from which to learn the parameter.
  
  ivs: List (default: None)
      List of variable names which should be used as Instrumental Variables (IV).
      If not specified, tries to find the IVs from the model structure, fails if
      can't find either IV or Conditional IV.
  
  civs: List of tuples (tuple form: (var, coditional_var))
      List of conditional IVs to use for estimation.
      If not specified, tries to find the IVs from the model structure, fails if
      can't find either IV or Conditional IVs.
  
  Examples
  --------
  >>> from pgmpy.estimators import IVEstimator # TODO: Finish example.
docstr_tok: ["Estimates","the","parameter","X","-",">","Y.","Parameters","--","--","--","--","--","X",":","str","The","covariate","variable","of","the","parameter","being","estimated",".","Y",":","str","The","predictor","variable","of","the","parameter","being","estimated",".","data",":","pd.DataFrame","The","data","from","which","to","learn","the","parameter",".","ivs",":","List","(","default",":","None",")","List","of","variable","names","which","should","be","used","as","Instrumental","Variables","(","IV",")",".","If","not","specified",",","tries","to","find","the","IVs","from","the","model","structure",",","fails","if","ca","n't","find","either","IV","or","Conditional","IV",".","civs",":","List","of","tuples","(","tuple","form",":","(","var",",","coditional_var",")",")","List","of","conditional","IVs","to","use","for","estimation",".","If","not","specified",",","tries","to","find","the","IVs","from","the","model","structure",",","fails","if","ca","n't","find","either","IV","or","Conditional","IVs",".","Examples","--","--","--","--",">",">",">","from","pgmpy.estimators","import","IVEstimator","#","TODO",":","Finish","example","."]
code: def fit(self, X, Y, data, ivs=None, civs=None):
      """
      Estimates the parameter X -> Y.
  
      Parameters
      ----------
      X: str
          The covariate variable of the parameter being estimated.
  
      Y: str
          The predictor variable of the parameter being estimated.
  
      data: pd.DataFrame
          The data from which to learn the parameter.
  
      ivs: List (default: None)
          List of variable names which should be used as Instrumental Variables (IV).
          If not specified, tries to find the IVs from the model structure, fails if
          can't find either IV or Conditional IV.
  
      civs: List of tuples (tuple form: (var, coditional_var))
          List of conditional IVs to use for estimation.
          If not specified, tries to find the IVs from the model structure, fails if
          can't find either IV or Conditional IVs.
  
      Examples
      --------
      >>> from pgmpy.estimators import IVEstimator # TODO: Finish example.
      """
      if (ivs is None) and (civs is None):
          ivs = self.model.get_ivs(X, Y)
          civs = self.model.get_conditional_ivs(X, Y)
  
      civs = [civ for civ in civs if civ[0] not in ivs]
  
      reg_covars = []
      for var in self.model.graph.predecessors(X):
          if var in self.model.observed:
              reg_covars.append(var)
  
      # Get CIV conditionals
      civ_conditionals = []
      for civ in civs:
          civ_conditionals.extend(civ[1])
  
      # First stage regression.
      params = (
          sm.OLS(
              data.loc[:, X], data.loc[:, reg_covars + civ_conditionals]
          )
          .fit()
          .params
      )
  
      data["X_pred"] = np.zeros(data.shape[0])
      for var in reg_covars:
          data.X_pred += params[var] * data.loc[:, var]
  
      summary = sm.OLS(
          data.loc[:, Y], data.loc[:, ["X_pred"] + civ_conditionals]
      ).fit()
      return summary.params["X_pred"], summary
  
file_path: pgmpy/pgmpy/estimators/SEMEstimator.py
imports: import numpy
  import pandas
  import statsmodels.api
  import torch
  from pgmpy import config
  from pgmpy.models import SEM, SEMAlg, SEMGraph
  from pgmpy.utils import optimize, pinverse
label_desc: Use image node_id 2 for calling the IVEstimator obj's underlying member method code with example usage: obj.fit(X, Y, data, ivs, civs) and returns: summary,  summary