code: def lm(data, xseq, **params):
      
      X = sm.add_constant(data['x'])
      Xseq = sm.add_constant(xseq)
  
      if 'weight' in data:
          init_kwargs, fit_kwargs = separate_method_kwargs(
              params['method_args'], sm.WLS, sm.WLS.fit)
          model = sm.WLS(data['y'], X, weights=data['weight'], **init_kwargs)
      else:
          init_kwargs, fit_kwargs = separate_method_kwargs(
              params['method_args'], sm.OLS, sm.OLS.fit)
          model = sm.OLS(data['y'], X, **init_kwargs)
  
      results = model.fit(**fit_kwargs)
      data = pd.DataFrame({'x': xseq})
      data['y'] = results.predict(Xseq)
  
      if params['se']:
          alpha = 1 - params['level']
          prstd, iv_l, iv_u = wls_prediction_std(
              results, Xseq, alpha=alpha)
          data['se'] = prstd
          data['ymin'] = iv_l
          data['ymax'] = iv_u
  
      return data
docs: Fit OLS / WLS if data has weight