From 4f746478dbf957b52f7aac6e7f0e67324a7a988c Mon Sep 17 00:00:00 2001 From: Noah Greifer Date: Tue, 20 Aug 2024 11:39:16 -0400 Subject: [PATCH] Adjust doc to prevent gbm warning with multinomial --- R/get_w_from_ps.R | 31 ++++++++++++++++++------------- man/get_w_from_ps.Rd | 32 ++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/R/get_w_from_ps.R b/R/get_w_from_ps.R index b2fcb9c..7c445fc 100644 --- a/R/get_w_from_ps.R +++ b/R/get_w_from_ps.R @@ -199,22 +199,27 @@ #' estimand = "ATT", treated = "A") #' all.equal(w1, w3) #' -#' #Using MMWS +#' # Using MMWS #' w4 <- get_w_from_ps(ps, treat = lalonde$treat, #' estimand = "ATE", subclass = 20, #' stabilize = TRUE) -#' @examplesIf requireNamespace("gbm", quietly = TRUE) -#' #A multi-category example using GBM predicted probabilities -#' library(gbm) -#' T3 <- factor(sample(c("A", "B", "C"), nrow(lalonde), replace = TRUE)) -#' -#' gbm.fit <- gbm(T3 ~ age + educ + race + married + -#' nodegree + re74 + re75, data = lalonde, -#' distribution = "multinomial", n.trees = 200, -#' interaction.depth = 3) -#' ps.multi <- drop(predict(gbm.fit, type = "response", -#' n.trees = 200)) -#' w <- get_w_from_ps(ps.multi, T3, estimand = "ATE") +#' +#' # A multi-category example using predicted probabilities +#' # from multinomial logistic regression +#' T3 <- factor(sample(c("A", "B", "C"), nrow(lalonde), +#' replace = TRUE)) +#' +#' multi.fit <- multinom_weightit( +#' T3 ~ age + educ + race + married + +#' nodegree + re74 + re75, data = lalonde, +#' vcov = "none" +#' ) +#' +#' ps.multi <- fitted(multi.fit) +#' head(ps.multi) +#' +#' w5 <- get_w_from_ps(ps.multi, treat = T3, +#' estimand = "ATE") #' @export get_w_from_ps <- function(ps, treat, estimand = "ATE", focal = NULL, treated = NULL, diff --git a/man/get_w_from_ps.Rd b/man/get_w_from_ps.Rd index 335e662..3ebc288 100644 --- a/man/get_w_from_ps.Rd +++ b/man/get_w_from_ps.Rd @@ -155,23 +155,27 @@ w3 <- get_w_from_ps(ps, treat = treatAB, estimand = "ATT", treated = "A") all.equal(w1, w3) -#Using MMWS +# Using MMWS w4 <- get_w_from_ps(ps, treat = lalonde$treat, estimand = "ATE", subclass = 20, stabilize = TRUE) -\dontshow{if (requireNamespace("gbm", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -#A multi-category example using GBM predicted probabilities -library(gbm) -T3 <- factor(sample(c("A", "B", "C"), nrow(lalonde), replace = TRUE)) - -gbm.fit <- gbm(T3 ~ age + educ + race + married + - nodegree + re74 + re75, data = lalonde, - distribution = "multinomial", n.trees = 200, - interaction.depth = 3) -ps.multi <- drop(predict(gbm.fit, type = "response", - n.trees = 200)) -w <- get_w_from_ps(ps.multi, T3, estimand = "ATE") -\dontshow{\}) # examplesIf} + +# A multi-category example using predicted probabilities +# from multinomial logistic regression +T3 <- factor(sample(c("A", "B", "C"), nrow(lalonde), + replace = TRUE)) + +multi.fit <- multinom_weightit( + T3 ~ age + educ + race + married + + nodegree + re74 + re75, data = lalonde, + vcov = "none" +) + +ps.multi <- fitted(multi.fit) +head(ps.multi) + +w5 <- get_w_from_ps(ps.multi, treat = T3, + estimand = "ATE") } \references{ \subsection{Binary treatments}{