Added option in select_weight

This commit is contained in:
2025-05-26 13:55:42 +02:00
parent cdda1aab85
commit 2eafd5c3a6
2 changed files with 12 additions and 3 deletions

View File

@ -9,11 +9,12 @@
#' @param grp string containing the name of the column where the group membership variable is stored in df
#' @param X vector of strings containing the name of confounders to be included in the model
#' @param instr vector of strings containing the name of instrumental variables to be included in the model
#' @param type.res string containing the type of glm residuals to be used. Default is "deviance"
#' @return A vector of weights to be included in a PCBSM
#' @export
select_weight <- function(df=NULL,grp=NULL,X=NULL,instr=NULL) {
select_weight <- function(df=NULL,grp=NULL,X=NULL,instr=NULL,type.res="deviance") {
formu <- paste0(grp,"~")
formu2 <- paste(X,sep="+",collapse="+")
formu3 <- paste(instr,sep="+",collapse="+")
@ -25,6 +26,6 @@ select_weight <- function(df=NULL,grp=NULL,X=NULL,instr=NULL) {
}
formu <- paste(formu,formu2)
logit_mod <- glm(formula = formu,data = df,family = binomial(link = "probit"))
res <- residuals(logit_mod)
res <- residuals(logit_mod,type=type.res)
return(res)
}