Skip to content

New (optional) demeaning backend via within #714

Description

@s3alfisc

Hi @bashtage,

Over the last couple of months, we (mostly @schroedk) have spent quite a bit of time developing a faster demeaning algorithm for fixed effects regression that works particularly well for poorly-connected fixed effects (as e.g. in worker firm panels with little mobility). The core idea is to replace the diagonal preconditioner that linearmodels current LSMR implementation uses with an additive Schwarz preconditioner.

For some fixed effects structures, this new preconditioner works much better than diagonal LSMR:

Image

We have Python bindings published to PyPi as within_py that has a pretty simple API. Here is how you'd fit a simple FWL problem:

beta_true = np.array([1.0, -2.0, 0.5])
X = np.random.randn(n, 3)
y = X @ beta_true + np.random.randn(n)

result = solve_batch(fe, np.column_stack([y, X]))
y_tilde, X_tilde = result.demeaned[:, 0], result.demeaned[:, 1:]
beta_hat = np.linalg.lstsq(X_tilde, y_tilde, rcond=None)[0]
print(np.round(beta_hat, 4))  # [ 0.9982 -2.006   0.5005]

If you are curious how the solver works, we have written up details here and here.

Would you be interested to try this out as a second, optional solver for the AbsoringLS backend? If yes, I'd set up a draft PR in the next days / weeks.

Best, Alex

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions