Title: | Techniques to Build Better Balance |
---|---|
Description: | Build better balance in causal inference models. 'halfmoon' helps you assess propensity score models for balance between groups using metrics like standardized mean differences and visualization techniques like mirrored histograms. 'halfmoon' supports both weighting and matching techniques. |
Authors: | Malcolm Barrett [aut, cre, cph] |
Maintainer: | Malcolm Barrett <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2024-11-22 03:51:23 UTC |
Source: | https://github.com/r-causal/halfmoon |
The empirical cumulative distribution function (ECDF) provides an alternative
visualization of distribution. geom_ecdf()
is similar to
ggplot2::stat_ecdf()
but it can also calculate weighted ECDFs.
geom_ecdf( mapping = NULL, data = NULL, geom = "step", position = "identity", ..., n = NULL, pad = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
geom_ecdf( mapping = NULL, data = NULL, geom = "step", position = "identity", ..., n = NULL, pad = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data, either as a
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to |
n |
if NULL, do not interpolate. If not NULL, this is the number of points to interpolate with. |
pad |
If |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
a geom
In addition to the aesthetics for
ggplot2::stat_ecdf()
, geom_ecdf()
also accepts:
weights
library(ggplot2) ggplot( nhefs_weights, aes(x = smokeyrs, color = qsmk) ) + geom_ecdf(aes(weights = w_ato)) + xlab("Smoking Years") + ylab("Proportion <= x")
library(ggplot2) ggplot( nhefs_weights, aes(x = smokeyrs, color = qsmk) ) + geom_ecdf(aes(weights = w_ato)) + xlab("Smoking Years") + ylab("Proportion <= x")
Create mirrored histograms
geom_mirror_histogram( mapping = NULL, data = NULL, position = "stack", ..., binwidth = NULL, bins = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )
geom_mirror_histogram( mapping = NULL, data = NULL, position = "stack", ..., binwidth = NULL, bins = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to |
binwidth |
The width of the bins. Can be specified as a numeric value
or as a function that calculates width from unscaled x. Here, "unscaled x"
refers to the original x values in the data, before application of any
scale transformation. When specifying a function along with a grouping
structure, the function will be called once per group.
The default is to use the number of bins in The bin width of a date variable is the number of days in each time; the bin width of a time variable is the number of seconds. |
bins |
Number of bins. Overridden by |
na.rm |
If |
orientation |
The orientation of the layer. The default ( |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
a geom
library(ggplot2) ggplot(nhefs_weights, aes(.fitted)) + geom_mirror_histogram( aes(group = qsmk), bins = 50 ) + geom_mirror_histogram( aes(fill = qsmk, weight = w_ate), bins = 50, alpha = 0.5 ) + scale_y_continuous(labels = abs)
library(ggplot2) ggplot(nhefs_weights, aes(.fitted)) + geom_mirror_histogram( aes(group = qsmk), bins = 50 ) + geom_mirror_histogram( aes(fill = qsmk, weight = w_ate), bins = 50, alpha = 0.5 ) + scale_y_continuous(labels = abs)
A dataset containing various propensity score weights for
causaldata::nhefs_complete
.
nhefs_weights
nhefs_weights
A data frame with 1566 rows and 14 variables:
Quit smoking
Race
Age
Sex
Education level
Smoking intensity
Number of smoke-years
Exercise level
Daily activity level
Participant weight in 1971 (baseline)
ATE weight
ATT weight
ATC weight
ATM weight
ATO weight
Propensity score