Skip to content

Commit

Permalink
continuous.stan: deal with (nearly) singular case
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoodri committed Sep 20, 2019
1 parent f2d2d7f commit 5d91237
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/stan_files/continuous.stan
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ transformed data {
matrix[N, has_intercept + K + K_smooth ] X_ = has_intercept ? append_col(rep_vector(1.0, N),
(K_smooth > 0 ? append_col(X[1], S) : X[1])) :
(K_smooth > 0 ? append_col(X[1], S) : X[1]);
XtX = crossprod(X_);
OLS = mdivide_left_spd(XtX, X_' * y);
SSR = dot_self(y - X_ * OLS);
matrix[cols(X_), cols(X_)] R = qr_thin_R(X_);
if (tail(diagonal(R), 1)[1] > 1e-16) {
matrix[N, cols(R)] Q = qr_thin_Q(X_);
XtX = crossprod(X_);
OLS = mdivide_right_tri_low(y' * Q, R')';
SSR = dot_self(y - X_ * OLS);
} else can_do_OLS = 0;
}
if (can_do_normalidglm) {
XS = K_smooth > 0 ? append_col(X[1], S) : X[1];
Expand Down

0 comments on commit 5d91237

Please sign in to comment.