Skip to content

Commit

Permalink
Replace NA in glm from ordinary post-selection estmation being 0
Browse files Browse the repository at this point in the history
  • Loading branch information
fenguoerbian committed Sep 2, 2024
1 parent ac84092 commit 8da3368
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ Logistic_FAR_Path_Further_Improve <- function(x_mat, y_vec, h, k_n, p,

# save the results
delta_vec <- glmfit$coefficients
delta_vec[is.na(delta_vec)] <- 0
iter_num <- glmfit$iter
converge <- glmfit$converged

Expand Down Expand Up @@ -719,6 +720,9 @@ Logistic_FAR_Path_Further_Improve <- function(x_mat, y_vec, h, k_n, p,
# save the results
delta_vec <- glmfit$coefficients[1 : h]
eta_active_stack_vec <- glmfit$coefficients[(1 : k_n) + h]
delta_vec[is.na(delta_vec)] <- 0
eta_active_stack_vec[is.na(eta_active_stack_vec)] <- 0

# save the eta result back to original form
for(i in 1 : length(active_idx)){
idx <- active_idx[i]
Expand Down Expand Up @@ -749,6 +753,9 @@ Logistic_FAR_Path_Further_Improve <- function(x_mat, y_vec, h, k_n, p,
# save the results
delta_vec <- glmfit$coefficients[1 : h]
eta_adj_stack_vec <- glmfit$coefficients[-(1 : h)]
delta_vec[is.na(delta_vec)] <- 0
eta_adj_stack_vec[is.na(eta_adj_stack_vec)] <- 0

eta_ref_vec <- apply(matrix(eta_adj_stack_vec, nrow = k_n), 1, function(invec) -sum(invec))
eta_active_stack_vec <- rep(0, k_n * length(active_idx))
eta_active_stack_vec[1 : ((length(active_idx) - 1) * k_n)] <- eta_adj_stack_vec
Expand Down

0 comments on commit 8da3368

Please sign in to comment.