public double[] marginalEffectSSdf(int index) {
    int error = sweep.A.rows() - 1;
    double errorss = sweep.A.getQuick(error, error);

    int first = 0;
    for (int i = 0; i < index; i++) {
      first += xtxmatrices[i][i].rows();
    }
    int last = first + xtxmatrices[index][index].rows();
    int df = 0;
    for (int i = first; i < last; i++) {
      if (sweep.revg2sweep(i)) {
        df++;
      }
    }

    int nonsingular = sweep.sweepSingularColumns();
    df -= nonsingular;

    double reducedError = sweep.A.getQuick(error, error);
    double[] result = new double[] {(reducedError - errorss), df};
    for (int i = first; i < last; i++) {
      sweep.revg2sweep(i);
    }

    return result;
  }
  private void initialSweep() {
    sweep.XTX = DoubleFactory2D.dense.compose(xtxmatrices);
    sweep.XTy = DoubleFactory2D.dense.compose(xtymatrices);

    totalSS = 0;
    for (int i = 0; i < data.length; i++) {
      totalSS += data[i] * data[i];
    }
    sweep.yTy = DoubleFactory2D.dense.make(1, 1, totalSS);
    sweep.makeA();
    int lastrow = sweep.A.rows() - 1;
    int col = 0;
    double prevSS = totalSS;

    for (int i = 0; i < xtxmatrices.length; i++) {
      double df = 0;
      for (int j = 0; j < xtxmatrices[i][i].rows(); j++) {
        if (sweep.revg2sweep(col++)) {
          df++;
        }
      }
      effectdf.add(new Double(df));
      double newSS = sweep.A.getQuick(lastrow, lastrow);
      double difSS = prevSS - newSS;
      effectSS.add(new Double(difSS));
      prevSS = newSS;
    }
  }