% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/PsFunctions.R
\name{trimByPs}
\alias{trimByPs}
\title{Trim persons by propensity score}
\usage{
trimByPs(population, trimByPsArgs = createTrimByPsArgs(trimFraction = 0.05))
}
\arguments{
\item{population}{A data frame with the three columns described below}

\item{trimByPsArgs}{An object of type \code{trimByPsArgs} as created by the
\code{\link[=createTrimByPsArgs]{createTrimByPsArgs()}} function.}
}
\value{
Returns a tibble with the same three columns as the input.
}
\description{
Use the provided propensity scores to trim subjects with extreme scores or weights.
}
\details{
The data frame should have the following three columns:
\itemize{
\item rowId (numeric): A unique identifier for each row (e.g. the person ID).
\item treatment (integer): Column indicating whether the person is in the target (1) or comparator (0) group.
\item propensityScore (numeric): Propensity score.
}
}
\examples{
rowId <- 1:2000
treatment <- rep(0:1, each = 1000)
propensityScore <- c(runif(1000, min = 0, max = 1), runif(1000, min = 0, max = 1))
iptw <- ifelse(treatment == 1,
               mean(treatment == 1) / propensityScore,
               mean(treatment == 0) / (1 - propensityScore))
data <- data.frame(rowId = rowId,
                   treatment = treatment,
                   propensityScore = propensityScore,
                   iptw = iptw)
result1 <- trimByPs(data, createTrimByPsArgs(trimFraction = 0.05))
result2 <- trimByPs(data, createTrimByPsArgs(equipoiseBounds = c(0.3, 0.7)))
result3 <- trimByPs(data, createTrimByPsArgs(maxWeight = 10))

}
