diff --git a/R/select_weight.R b/R/select_weight.R index 17da336..7f4378c 100644 --- a/R/select_weight.R +++ b/R/select_weight.R @@ -10,11 +10,12 @@ #' @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" +#' @param std boolean indicating whether residuals should be standardized. Default is TRUE #' @return A vector of weights to be included in a PCBSM #' @export -select_weight <- function(df=NULL,grp=NULL,X=NULL,instr=NULL,type.res="deviance") { +select_weight <- function(df=NULL,grp=NULL,X=NULL,instr=NULL,type.res="deviance",std=T) { formu <- paste0(grp,"~") formu2 <- paste(X,sep="+",collapse="+") formu3 <- paste(instr,sep="+",collapse="+") @@ -27,5 +28,8 @@ select_weight <- function(df=NULL,grp=NULL,X=NULL,instr=NULL,type.res="deviance" formu <- paste(formu,formu2) logit_mod <- glm(formula = formu,data = df,family = binomial(link = "probit")) res <- residuals(logit_mod,type=type.res) + if (std) { + res <- rstandard(logit_mod,type='deviance') + } return(res) } diff --git a/man/select_weight.Rd b/man/select_weight.Rd index 93812b6..95efdba 100644 --- a/man/select_weight.Rd +++ b/man/select_weight.Rd @@ -9,7 +9,8 @@ select_weight( grp = NULL, X = NULL, instr = NULL, - type.res = "deviance" + type.res = "deviance", + std = T ) } \arguments{ @@ -22,6 +23,8 @@ select_weight( \item{instr}{vector of strings containing the name of instrumental variables to be included in the model} \item{type.res}{string containing the type of glm residuals to be used. Default is "deviance"} + +\item{std}{boolean indicating whether residuals should be standardized. Default is TRUE} } \value{ A vector of weights to be included in a PCBSM