Title: | Techniques to Build Better Balance |
Version: | 0.1.0 |
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. |
License: | MIT + file LICENSE |
URL: | https://github.com/r-causal/halfmoon, https://r-causal.github.io/halfmoon/ |
BugReports: | https://github.com/r-causal/halfmoon/issues |
Depends: | R (≥ 2.10) |
Imports: | cli, ggplot2, tidyselect, tidysmd (≥ 0.2.0) |
Suggests: | covr, testthat (≥ 3.0.0), vdiffr |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2023-05-30 17:15:48 UTC; malcolmbarrett |
Author: | Malcolm Barrett |
Maintainer: | Malcolm Barrett <malcolmbarrett@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2023-05-30 18:20:02 UTC |
Calculate weighted and unweighted empirical cumulative distributions
Description
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.
Usage
geom_ecdf(
mapping = NULL,
data = NULL,
geom = "step",
position = "identity",
...,
n = NULL,
pad = TRUE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
Arguments
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 |
Value
a geom
Aesthetics
In addition to the aesthetics for
ggplot2::stat_ecdf()
, geom_ecdf()
also accepts:
-
weights
Examples
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
Description
Create mirrored histograms
Usage
geom_mirror_histogram(
mapping = NULL,
data = NULL,
position = "stack",
...,
binwidth = NULL,
bins = NULL,
na.rm = FALSE,
orientation = NA,
show.legend = NA,
inherit.aes = TRUE
)
Arguments
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 |
Value
a geom
Examples
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)
NHEFS with various propensity score weights
Description
A dataset containing various propensity score weights for
causaldata::nhefs_complete
.
Usage
nhefs_weights
Format
A data frame with 1566 rows and 14 variables:
- qsmk
Quit smoking
- race
Race
- age
Age
- sex
Sex
- education
Education level
- smokeintensity
Smoking intensity
- smokeyrs
Number of smoke-years
- exercise
Exercise level
- active
Daily activity level
- wt71
Participant weight in 1971 (baseline)
- w_ate
ATE weight
- w_att
ATT weight
- w_atc
ATC weight
- w_atm
ATM weight
- w_ato
ATO weight
- .fitted
Propensity score
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- tidyselect
contains
,ends_with
,everything
,last_col
,matches
,num_range
,one_of
,peek_vars
,starts_with
- tidysmd