Skip to content

Commit

Permalink
add pearson residual for three main models
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengp0 committed Dec 26, 2024
1 parent 78cf530 commit 1897df6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/regmod/models/binomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ def jacobian2(self, coefs: NDArray) -> NDArray:
return jacobian2

def get_pearson_residuals(self, coefs: NDArray) -> NDArray:
z = np.exp(self.get_lin_param(coefs))

pred = z / (1 + z)
pred = self.params[0].get_param(coefs, self.data, mat=self.mat[0])
pred_sd = np.sqrt(pred * (1 - pred) / self.data.weights)

return (self.data.obs - pred) / pred_sd
Expand Down
6 changes: 6 additions & 0 deletions src/regmod/models/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ def jacobian2(self, coefs: NDArray) -> NDArray:
jacobian2 = jacobian.dot(jacobian.T) + hess_mat_gprior
return jacobian2

def get_pearson_residuals(self, coefs: NDArray) -> NDArray:
pred = self.params[0].get_param(coefs, self.data, mat=self.mat[0])
pred_sd = 1.0 / np.sqrt(self.data.weights)

return (self.data.obs - pred) / pred_sd

def fit(self, optimizer: Callable = msca_optimize, **optimizer_options):
"""Fit function.
Expand Down
6 changes: 6 additions & 0 deletions src/regmod/models/poisson.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ def jacobian2(self, coefs: NDArray) -> NDArray:
jacobian2 = jacobian.dot(jacobian.T) + hess_mat_gprior
return jacobian2

def get_pearson_residuals(self, coefs: NDArray) -> NDArray:
pred = self.params[0].get_param(coefs, self.data, mat=self.mat[0])
pred_sd = np.sqrt(pred * self.data.weights)

return (self.data.obs - pred) / pred_sd

def fit(self, optimizer: Callable = msca_optimize, **optimizer_options):
"""Fit function.
Expand Down

0 comments on commit 1897df6

Please sign in to comment.