Skip to content

Commit

Permalink
ENH: add minimal RLMDetSMM (including mscale version with constraint)
Browse files Browse the repository at this point in the history
  • Loading branch information
josef-pkt committed Apr 23, 2024
1 parent c1a2574 commit 68a79f9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion statsmodels/robust/resistant_linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, endog, exog, norm=None, breakdown_point=0.5,
exog_start = self.exog[:, col_indices]

Check warning on line 45 in statsmodels/robust/resistant_linear_model.py

View check run for this annotation

Codecov / codecov/patch

statsmodels/robust/resistant_linear_model.py#L45

Added line #L45 was not covered by tests

if include_endog:
self.data_start = np.column_stack(endog, exog_start)
self.data_start = np.column_stack((endog, exog_start))

Check warning on line 48 in statsmodels/robust/resistant_linear_model.py

View check run for this annotation

Codecov / codecov/patch

statsmodels/robust/resistant_linear_model.py#L48

Added line #L48 was not covered by tests
else:
self.data_start = exog_start

Check warning on line 50 in statsmodels/robust/resistant_linear_model.py

View check run for this annotation

Codecov / codecov/patch

statsmodels/robust/resistant_linear_model.py#L50

Added line #L50 was not covered by tests

Expand Down Expand Up @@ -90,3 +90,32 @@ def fit(self, h, maxiter=100, maxiter_step=5):
# results instance of _fit_once has RLM as `model`
res_best.model_dets = self
return res_best

Check warning on line 92 in statsmodels/robust/resistant_linear_model.py

View check run for this annotation

Codecov / codecov/patch

statsmodels/robust/resistant_linear_model.py#L91-L92

Added lines #L91 - L92 were not covered by tests


class RLMDetSMM(RLMDetS):

Check warning on line 95 in statsmodels/robust/resistant_linear_model.py

View check run for this annotation

Codecov / codecov/patch

statsmodels/robust/resistant_linear_model.py#L95

Added line #L95 was not covered by tests
"""MM-estimator with S-estimator starting values
"""

def fit(self, h=None, binding=False):
norm_m = rnorms.TukeyBiweight(c=4.685061)
res_s = super().fit(h)
mod_m = RLM(res_s.model.endog, res_s.model.exog, M=norm_m)
res_mm = mod_m.fit(

Check warning on line 104 in statsmodels/robust/resistant_linear_model.py

View check run for this annotation

Codecov / codecov/patch

statsmodels/robust/resistant_linear_model.py#L100-L104

Added lines #L100 - L104 were not covered by tests
start_params=np.asarray(res_s.params),
start_scale=res_s.scale,
update_scale=False
)

if not binding:
# we can compute this first and skip MM if scale decrease
mod_sm = RLM(res_s.model.endog, res_s.model.exog, M=norm_m)
res_sm = mod_sm.fit(

Check warning on line 113 in statsmodels/robust/resistant_linear_model.py

View check run for this annotation

Codecov / codecov/patch

statsmodels/robust/resistant_linear_model.py#L112-L113

Added lines #L112 - L113 were not covered by tests
start_params=res_s.params,
scale_est=self.mscale
)

if not binding and res_sm.scale < res_mm.scale:
return res_sm

Check warning on line 119 in statsmodels/robust/resistant_linear_model.py

View check run for this annotation

Codecov / codecov/patch

statsmodels/robust/resistant_linear_model.py#L119

Added line #L119 was not covered by tests
else:
return res_mm

Check warning on line 121 in statsmodels/robust/resistant_linear_model.py

View check run for this annotation

Codecov / codecov/patch

statsmodels/robust/resistant_linear_model.py#L121

Added line #L121 was not covered by tests

0 comments on commit 68a79f9

Please sign in to comment.