Skip to content

Commit f622be3

Browse files
committed
BUG/REF/DOC: glm margeff docstrings, fix NonlinearDeltaCov se for 2-dim
1 parent 7a3cdfc commit f622be3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

statsmodels/genmod/generalized_linear_model.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def _derivative_exog(self, params, exog=None, transform="dydx",
629629
dummy_idx=None, count_idx=None,
630630
offset=None, exposure=None):
631631
"""
632-
This should implement the derivative of the non-linear function
632+
Derivative of mean, expected endog with respect to the parameters
633633
"""
634634
if exog is None:
635635
exog = self.exog
@@ -642,8 +642,8 @@ def _derivative_exog(self, params, exog=None, transform="dydx",
642642
k_extra = getattr(self, 'k_extra', 0)
643643
params_exog = params if k_extra == 0 else params[:-k_extra]
644644

645-
lin_pred = self.predict(params, which="linear")
646-
margeff = self.family.link.inverse_deriv(lin_pred)[:, None] * params_exog
645+
margeff = (self.family.link.inverse_deriv(lin_pred)[:, None] *
646+
params_exog)
647647
if 'ex' in transform:
648648
margeff *= exog
649649
if 'ey' in transform:
@@ -2299,6 +2299,9 @@ def get_margeff(self, at='overall', method='dydx', atexog=None,
22992299
dummy=False, count=False):
23002300
"""Get marginal effects of the fitted model.
23012301
2302+
Warning: offset, exposure and weights (var_weights and freq_weights)
2303+
are not supported by margeff.
2304+
23022305
Parameters
23032306
----------
23042307
at : str, optional
@@ -2366,12 +2369,15 @@ def get_margeff(self, at='overall', method='dydx', atexog=None,
23662369
23672370
When using after Poisson, returns the expected number of events per
23682371
period, assuming that the model is loglinear.
2372+
2373+
Status : unsupported features offset, exposure and weights. Default
2374+
handling of freq_weights for average effect "overall" might change.
2375+
23692376
"""
23702377
if getattr(self.model, "offset", None) is not None:
23712378
raise NotImplementedError("Margins with offset are not available.")
23722379
if (np.any(self.model.var_weights != 1) or
2373-
np.any(self.model.freq_weights != 1)
2374-
):
2380+
np.any(self.model.freq_weights != 1)):
23752381
warnings.warn("weights are not taken into account by margeff")
23762382
from statsmodels.discrete.discrete_margins import DiscreteMargins
23772383
return DiscreteMargins(self, (at, method, atexog, dummy, count))

statsmodels/stats/_delta_method.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ def var(self):
151151
"""
152152
g = self.grad()
153153
var = (np.dot(g, self.cov_params) * g).sum(-1)
154+
155+
if var.ndim == 2:
156+
var = var.T
154157
return var
155158

156159
def se_vectorized(self):

0 commit comments

Comments
 (0)