'Derivative of the expected endog with respect to the parameters.
Parameters
exog : array-like
The exogeneous data at which the derivative is computed,
number of rows must be a multiple of `ncut`.
lin_pred : array-like
The values of the linear predictor, length must be multiple
of `ncut`.
Returns
The derivative of the expected endog with respect to the
parameters.'

def mean_deriv(self, exog, lin_pred):

    expval = np.exp(lin_pred)
    expval_m = np.reshape(expval, ((len(expval) // self.ncut), self.ncut))
    denom = (1 + expval_m.sum(1))
    denom = np.kron(denom, np.ones(self.ncut, dtype=np.float64))
    mprob = (expval / denom)
    dmat = (mprob[:, None] * exog)
    ddenom = (expval[:, None] * exog)
    dmat -= ((mprob[:, None] * ddenom) / denom[:, None])
    return dmat
