Skip to content

Commit 1e221ef

Browse files
authored
jit compile multicollinearity detection #466 (#579)
1 parent 72e1967 commit 1e221ef

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pyfixest/estimation/feols_.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from importlib import import_module
55
from typing import Optional, Union
66

7+
import numba as nb
78
import numpy as np
89
import pandas as pd
910
import polars as pl
@@ -2190,6 +2191,7 @@ def _drop_multicollinear_variables(
21902191
return X, names_array.tolist(), collin_vars, collin_index
21912192

21922193

2194+
@nb.njit(parallel=False)
21932195
def _find_collinear_variables(
21942196
X: np.ndarray, tol: float = 1e-10
21952197
) -> tuple[np.ndarray, int, bool]:
@@ -2215,7 +2217,7 @@ def _find_collinear_variables(
22152217
"""
22162218
K = X.shape[1]
22172219
R = np.zeros((K, K))
2218-
id_excl = np.zeros(K, dtype=bool)
2220+
id_excl = np.zeros(K, dtype=np.int32)
22192221
n_excl = 0
22202222
min_norm = X[0, 0]
22212223

@@ -2228,11 +2230,11 @@ def _find_collinear_variables(
22282230

22292231
if R_jj < tol:
22302232
n_excl += 1
2231-
id_excl[j] = True
2233+
id_excl[j] = 1
22322234

22332235
if n_excl == K:
22342236
all_removed = True
2235-
return id_excl, n_excl, all_removed
2237+
return id_excl.astype(np.bool_), n_excl, all_removed
22362238

22372239
continue
22382240

@@ -2250,7 +2252,7 @@ def _find_collinear_variables(
22502252
value -= R[k, i] * R[k, j]
22512253
R[j, i] = value / R_jj
22522254

2253-
return id_excl, n_excl, False
2255+
return id_excl.astype(np.bool_), n_excl, False
22542256

22552257

22562258
def _check_vcov_input(vcov: Union[str, dict[str, str]], data: pd.DataFrame):

0 commit comments

Comments
 (0)