R/prop_scores.R

Defines functions prop_scores

Documented in prop_scores

#' Fit the Propensity Score Model
#'
#' Fit the propensity score model.
#'
#' Fit the propensity score model to obtain the score for a given data set.
#'
#' @param data Data.frame.
#' @param formula Formula used to fit the propensity score.
#'
#' @source Section 6.2.2, p. 120-121. Used throughout chapter 10.
#'
#' @return List with
#' \describe{
#'   \item{scores}{Vector of propensity scores.}
#'   \item{fit}{The object of class glm returned by glm().}
#' }
#' @export
#' @examples
#' # An example can be found in the location identified in the
#' # source section above at the github site
#' # https://github.com/FrankLef/FundamentalsCausalInference.
prop_scores <- function(data, formula) {
  checkmate::assertDataFrame(data)
  checkmate::assertFormula(formula)

  fit <- glm(formula = formula, family = "binomial", data = data)
  scores <- fitted(fit)
  list("scores" = scores, "fit" = fit)
}

#' @rdname prop_scores
#' @export
prop.r <- prop_scores
FrankLef/fciR documentation built on Nov. 12, 2023, 6:09 a.m.