Skip to content

Commit

Permalink
Resolve some R CMD check issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fenguoerbian committed Sep 11, 2024
1 parent 171986d commit 09e1e2b
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 72 deletions.
14 changes: 11 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: LogisticFAR
Title: Logistic Functional Additive Regression with log-contrast constrain.
Version: 0.0.0.9013
Title: Logistic Functional Additive Regression with log-contrast constrain
Version: 0.0.0.9014
Authors@R:
person(given = "Chao",
family = "Cheng",
Expand All @@ -22,7 +22,15 @@ Imports:
future.apply,
progressr,
splitTools,
lme4
lme4,
magrittr,
tidyselect,
dplyr,
tibble,
tidyr,
pbapply,
pROC,
microbiomeDASim
Suggests:
rmarkdown,
knitr
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export(Number_Pick)
export(Summary_Simulation_Res)
import(RcppEigen)
importFrom(Rcpp,sourceCpp)
importFrom(magrittr,"%>%")
useDynLib(LogisticFAR, .registration = TRUE)
10 changes: 2 additions & 8 deletions R/LogisticFAR-package.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
## usethis namespace: start
#' @importFrom magrittr %>%
#' @useDynLib LogisticFAR, .registration = TRUE
## usethis namespace: end
NULL

## usethis namespace: start
#' @importFrom Rcpp sourceCpp
## usethis namespace: end
NULL

## usethis namespace: start
#' @import RcppEigen
## usethis namespace: end
NULL


18 changes: 12 additions & 6 deletions R/flirti_path_solver.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ Logistic_FAR_FLiRTI_Path <- function(y_vec, x_mat, h, kn, p,
# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
# delta_init <- rep(0, h)
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
# mu_1_init <- rep(0, nrow(b_mat))
Expand All @@ -266,7 +267,8 @@ Logistic_FAR_FLiRTI_Path <- function(y_vec, x_mat, h, kn, p,
# check initial values for the algorithm
if(missing(delta_init)){
print("delta_init missing, use default settings")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
}else{

Expand Down Expand Up @@ -594,7 +596,8 @@ Logistic_FAR_FLiRTI_CV_path <- function(y_vec, x_mat, h, kn, p,
# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
# delta_init <- rep(0, h)
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
# mu_1_init <- rep(0, nrow(b_mat))
Expand All @@ -607,7 +610,8 @@ Logistic_FAR_FLiRTI_CV_path <- function(y_vec, x_mat, h, kn, p,
# check initial values for the algorithm
if(missing(delta_init)){
print("delta_init missing, use default settings")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
}else{

Expand Down Expand Up @@ -982,7 +986,8 @@ Logistic_FAR_FLiRTI_CV_path_par <- function(y_vec, x_mat, h, kn, p,
# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
# delta_init <- rep(0, h)
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
# mu_1_init <- rep(0, nrow(b_mat))
Expand All @@ -995,7 +1000,8 @@ Logistic_FAR_FLiRTI_CV_path_par <- function(y_vec, x_mat, h, kn, p,
# check initial values for the algorithm
if(missing(delta_init)){
print("delta_init missing, use default settings")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
}else{

Expand Down
26 changes: 16 additions & 10 deletions R/mm_path_solver.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ Logistic_FARMM_Path <- function(y_vec, x_mat, h, kn, p, rand_eff_df,
# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
# delta_init <- rep(0, h)
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
# mu_1_init <- rep(0, nrow(b_mat))
Expand All @@ -313,7 +314,8 @@ Logistic_FARMM_Path <- function(y_vec, x_mat, h, kn, p, rand_eff_df,
# check initial values for the algorithm
if(missing(delta_init)){
print("delta_init missing, use default settings")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
}else{

Expand Down Expand Up @@ -687,7 +689,8 @@ Logistic_FARMM_CV_path <- function(y_vec, x_mat, h, kn, p, rand_eff_df,
# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
# delta_init <- rep(0, h)
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
# mu_1_init <- rep(0, nrow(b_mat))
Expand All @@ -700,7 +703,8 @@ Logistic_FARMM_CV_path <- function(y_vec, x_mat, h, kn, p, rand_eff_df,
# check initial values for the algorithm
if(missing(delta_init)){
print("delta_init missing, use default settings")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
}else{

Expand Down Expand Up @@ -819,15 +823,15 @@ Logistic_FARMM_CV_path <- function(y_vec, x_mat, h, kn, p, rand_eff_df,
}

rand_eff_mat <- data.frame(subj_vec_fct = rand_eff_df_test$subj_vec_fct) %>%
left_join(post_est$rand_eff_est,
dplyr::left_join(post_est$rand_eff_est,
by = "subj_vec_fct") %>%
dplyr::mutate(
dplyr::across(
tidyselect::everything(),
function(invec){
tidyr::replace_na(data = invec, replace = 0)
})) %>%
select(-subj_vec_fct) %>%
dplyr::select(-subj_vec_fct) %>%
as.matrix()
test_pi_vec2 <- rowSums(zmat * rand_eff_mat)

Expand Down Expand Up @@ -1177,7 +1181,8 @@ Logistic_FARMM_CV_path_par <- function(y_vec, x_mat, h, kn, p, rand_eff_df,
# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
# delta_init <- rep(0, h)
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
# mu_1_init <- rep(0, nrow(b_mat))
Expand All @@ -1190,7 +1195,8 @@ Logistic_FARMM_CV_path_par <- function(y_vec, x_mat, h, kn, p, rand_eff_df,
# check initial values for the algorithm
if(missing(delta_init)){
print("delta_init missing, use default settings")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
}else{

Expand Down Expand Up @@ -1309,15 +1315,15 @@ Logistic_FARMM_CV_path_par <- function(y_vec, x_mat, h, kn, p, rand_eff_df,
}

rand_eff_mat <- data.frame(subj_vec_fct = rand_eff_df_test$subj_vec_fct) %>%
left_join(post_est$rand_eff_est,
dplyr::left_join(post_est$rand_eff_est,
by = "subj_vec_fct") %>%
dplyr::mutate(
dplyr::across(
tidyselect::everything(),
function(invec){
tidyr::replace_na(data = invec, replace = 0)
})) %>%
select(-subj_vec_fct) %>%
dplyr::select(-subj_vec_fct) %>%
as.matrix()
test_pi_vec2 <- rowSums(zmat * rand_eff_mat)

Expand Down
15 changes: 10 additions & 5 deletions R/opath_solver.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ Logistic_FAR_OPath <- function(y_vec, x_mat, h, kn, p,
lambda_seq <- exp(seq(from = log(lam_max), to = log(lam_min), length.out = lambda_length))

print("Overwrite and use default value for delta_init, eta_init and mu1_init!")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, length(svd_vec_stack))
mu1_init <- rep(0, kn)
Expand All @@ -260,7 +261,8 @@ Logistic_FAR_OPath <- function(y_vec, x_mat, h, kn, p,
# check initial values for the algorithm
if(missing(delta_init)){
print("delta_init missing, use default settings")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
}else{

Expand Down Expand Up @@ -593,7 +595,8 @@ Logistic_FAR_CV_opath <- function(y_vec, x_mat, h, kn, p,

# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
mu_1_init <- rep(0, kn)
Expand Down Expand Up @@ -788,7 +791,8 @@ Get_Lambda_Max <- function(y_vec, x_mat, h, kn, p, a, bj_vec, cj_vec, start_id_v
#
# find lambda_max
# conduct the ordinary logistic regressoin
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
pi_fit <- exp(logit_fit$fitted.values) / (1 + exp(logit_fit$fitted.values))
alpha_vec <- rep(0, p)
for(i in 1 : p){
Expand Down Expand Up @@ -1061,7 +1065,8 @@ Logistic_FAR_CV_opath_par <- function(y_vec, x_mat, h, kn, p,

# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
mu_1_init <- rep(0, kn)
Expand Down
18 changes: 12 additions & 6 deletions R/path_solver.R
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ Logistic_FAR_Path <- function(y_vec, x_mat, h, kn, p,
# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
# delta_init <- rep(0, h)
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
# mu_1_init <- rep(0, nrow(b_mat))
Expand All @@ -305,7 +306,8 @@ Logistic_FAR_Path <- function(y_vec, x_mat, h, kn, p,
# check initial values for the algorithm
if(missing(delta_init)){
print("delta_init missing, use default settings")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
}else{

Expand Down Expand Up @@ -672,7 +674,8 @@ Logistic_FAR_CV_path <- function(y_vec, x_mat, h, kn, p,
# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
# delta_init <- rep(0, h)
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
# mu_1_init <- rep(0, nrow(b_mat))
Expand All @@ -685,7 +688,8 @@ Logistic_FAR_CV_path <- function(y_vec, x_mat, h, kn, p,
# check initial values for the algorithm
if(missing(delta_init)){
print("delta_init missing, use default settings")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
}else{

Expand Down Expand Up @@ -1116,7 +1120,8 @@ Logistic_FAR_CV_path_par <- function(y_vec, x_mat, h, kn, p,
# default initial values for lambda_max
print("Using default lambda sequences and initial values for the path searching!")
# delta_init <- rep(0, h)
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
eta_stack_init <- rep(0, p * kn)
# mu_1_init <- rep(0, nrow(b_mat))
Expand All @@ -1129,7 +1134,8 @@ Logistic_FAR_CV_path_par <- function(y_vec, x_mat, h, kn, p,
# check initial values for the algorithm
if(missing(delta_init)){
print("delta_init missing, use default settings")
logit_fit <- glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1, family = binomial)
logit_fit <- stats::glm(y_vec ~ x_mat[, 1 : h, drop = FALSE] - 1,
family = stats::binomial)
delta_init <- logit_fit$coefficients
}else{

Expand Down
Loading

0 comments on commit 09e1e2b

Please sign in to comment.