Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a009418
commit 38b6d05
Showing
5 changed files
with
155 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Changes in 0.7.3 | ||
* Removed 'dots' from argument section of the man page for the 'mlr.match' function. | ||
* Removed autogenerated 'keyword' lines from man page for 'mlr.power'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
Package: MatchLinReg | ||
Type: Package | ||
Title: Combining Matching and Linear Regression for Causal Inference | ||
Version: 0.7.0 | ||
Date: 2015-07-11 | ||
Version: 0.7.3 | ||
Date: 2020-02-03 | ||
Author: Alireza S. Mahani, Mansour T.A. Sharabiani | ||
Maintainer: Alireza S. Mahani <alireza.s.mahani@gmail.com> | ||
Description: Core functions as well as diagnostic and calibration tools for combining matching and linear regression for causal inference in observational studies. | ||
License: GPL (>= 2) | ||
Depends: R (>= 3.1.0) | ||
Imports: Hmisc, Matching, graphics, stats | ||
NeedsCompilation: no | ||
Packaged: 2015-07-12 00:14:58 UTC; amahani | ||
Repository: CRAN | ||
Date/Publication: 2015-07-12 11:06:19 | ||
Packaged: 2020-02-03 17:22:02 UTC; amahani | ||
Date/Publication: 2020-02-03 18:00:06 UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,87 @@ | ||
\name{mlr.match} | ||
\alias{mlr.match} | ||
%- Also NEED an '\alias' for EACH other topic documented here. | ||
\title{ | ||
Thin wrapper around \code{Match} function from \code{Matching} package | ||
} | ||
\description{ | ||
Performs propensity score or Mahalanobis matching and return indexes of treatment and control groups. | ||
} | ||
\usage{ | ||
mlr.match(tr, X, psm = TRUE, replace = F, caliper = Inf | ||
, verbose = TRUE) | ||
} | ||
%- maybe also 'usage' for other objects documented here. | ||
\arguments{ | ||
\item{tr}{Binary treatment indicator vector (1=treatment, 0=control), whose coefficient in the linear regression model is TE.} | ||
\item{X}{Covariates used in matching, either directly (Mahalanobis matching) or indirectly (propensity score).} | ||
\item{psm}{Boolean flag, indicating whether propensity score matching should be used (\code{TRUE}) or Mahalanobis matching (\code{FALSE}).} | ||
\item{replace}{Boolean flag, indicating whether matching must be done with or without replacement.} | ||
\item{caliper}{Size of caliper (standardized distance of two observations) used in matching. Treatment and control observations with standardized distance larger than \code{caliper} will not be considered as eligible pairs duing matching.} | ||
\item{verbose}{Boolean flag, indicating whether size of treatment and control groups before and after matching will be printed.} | ||
\item{\dots}{Other arguments to be passed to \code{Match} function.} | ||
} | ||
|
||
\details{ | ||
For propensity score matching, linear predictors from logistic regression are used (rather than predicted probabilities). | ||
} | ||
|
||
\value{ | ||
A vector of matched indexes, containing both treatment and control groups. Also, the following attributes are attached: 1) \code{nt}: size of treatment group, 2) \code{nc}: size of control group, 3) \code{psm.reg}: logistic regression object used in generating propensity scores (\code{NA} if \code{psm} is \code{FALSE}), 4) \code{match.obj}: matching object returned by \code{Match} function. | ||
} | ||
|
||
%\references{ | ||
%% ~put references to the literature/web site here ~ | ||
%} | ||
|
||
\author{ | ||
Alireza S. Mahani, Mansour T.A. Sharabiani | ||
} | ||
|
||
%\note{ | ||
%% ~~further notes~~ | ||
%} | ||
|
||
%% ~Make other sections like Warning with \section{Warning }{....} ~ | ||
|
||
%\seealso{ | ||
%% ~~objects to See Also as \code{\link{help}}, ~~~ | ||
%} | ||
|
||
\examples{ | ||
|
||
data(lalonde) | ||
|
||
tr <- lalonde$treat | ||
Z.i <- as.matrix(lalonde[, c("age", "educ", "black" | ||
, "hispan", "married", "nodegree", "re74", "re75")]) | ||
Z.o <- model.matrix(~ I(age^2) + I(educ^2) + I(re74^2) + I(re75^2) - 1, lalonde) | ||
|
||
# propensity score matching on all covariates | ||
idx <- mlr.match(tr = tr, X = cbind(Z.i, Z.o), caliper = 1.0, replace = FALSE) | ||
|
||
# improvement in maximum single-covariate bias due to matching | ||
bias.obj.before <- mlr.bias(tr = tr, Z.i = Z.i, Z.o = Z.o) | ||
bias.before <- bias.obj.before$subspace$bias | ||
dir <- bias.obj.before$subspace$dir | ||
bias.after <- as.numeric(mlr.bias(tr = tr[idx] | ||
, Z.i = Z.i[idx, ], Z.o = dir[idx], gamma.o = 1.0)$single$bias) | ||
|
||
# percentage bias-squared rediction | ||
cat("normalized bias - before:", bias.before, "\n") | ||
cat("normalized bias - after:", bias.after, "\n") | ||
cat("percentage squared-bias reduction:" | ||
, (bias.before^2 - bias.after^2)/bias.before^2, "\n") | ||
|
||
# matching with replacement | ||
idx.wr <- mlr.match(tr = tr, X = cbind(Z.i, Z.o), caliper = 1.0 | ||
, replace = TRUE) | ||
bias.after.wr <- as.numeric(mlr.bias(tr = tr | ||
, Z.i = Z.i, Z.o = dir, gamma.o = 1.0, idx = idx.wr)$single$bias) | ||
cat("normalized bias - after (with replacement):", bias.after.wr, "\n") | ||
|
||
} | ||
|
||
% Add one or more standard keywords, see file 'KEYWORDS' in the | ||
% R documentation directory. | ||
% \keyword{ ~kwd1 } | ||
% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line | ||
\name{mlr.match} | ||
\alias{mlr.match} | ||
%- Also NEED an '\alias' for EACH other topic documented here. | ||
\title{ | ||
Thin wrapper around \code{Match} function from \code{Matching} package | ||
} | ||
\description{ | ||
Performs propensity score or Mahalanobis matching and return indexes of treatment and control groups. | ||
} | ||
\usage{ | ||
mlr.match(tr, X, psm = TRUE, replace = F, caliper = Inf | ||
, verbose = TRUE) | ||
} | ||
%- maybe also 'usage' for other objects documented here. | ||
\arguments{ | ||
\item{tr}{Binary treatment indicator vector (1=treatment, 0=control), whose coefficient in the linear regression model is TE.} | ||
\item{X}{Covariates used in matching, either directly (Mahalanobis matching) or indirectly (propensity score).} | ||
\item{psm}{Boolean flag, indicating whether propensity score matching should be used (\code{TRUE}) or Mahalanobis matching (\code{FALSE}).} | ||
\item{replace}{Boolean flag, indicating whether matching must be done with or without replacement.} | ||
\item{caliper}{Size of caliper (standardized distance of two observations) used in matching. Treatment and control observations with standardized distance larger than \code{caliper} will not be considered as eligible pairs duing matching.} | ||
\item{verbose}{Boolean flag, indicating whether size of treatment and control groups before and after matching will be printed.} | ||
} | ||
|
||
\details{ | ||
For propensity score matching, linear predictors from logistic regression are used (rather than predicted probabilities). | ||
} | ||
|
||
\value{ | ||
A vector of matched indexes, containing both treatment and control groups. Also, the following attributes are attached: 1) \code{nt}: size of treatment group, 2) \code{nc}: size of control group, 3) \code{psm.reg}: logistic regression object used in generating propensity scores (\code{NA} if \code{psm} is \code{FALSE}), 4) \code{match.obj}: matching object returned by \code{Match} function. | ||
} | ||
|
||
%\references{ | ||
%% ~put references to the literature/web site here ~ | ||
%} | ||
|
||
\author{ | ||
Alireza S. Mahani, Mansour T.A. Sharabiani | ||
} | ||
|
||
%\note{ | ||
%% ~~further notes~~ | ||
%} | ||
|
||
%% ~Make other sections like Warning with \section{Warning }{....} ~ | ||
|
||
%\seealso{ | ||
%% ~~objects to See Also as \code{\link{help}}, ~~~ | ||
%} | ||
|
||
\examples{ | ||
|
||
data(lalonde) | ||
|
||
tr <- lalonde$treat | ||
Z.i <- as.matrix(lalonde[, c("age", "educ", "black" | ||
, "hispan", "married", "nodegree", "re74", "re75")]) | ||
Z.o <- model.matrix(~ I(age^2) + I(educ^2) + I(re74^2) + I(re75^2) - 1, lalonde) | ||
|
||
# propensity score matching on all covariates | ||
idx <- mlr.match(tr = tr, X = cbind(Z.i, Z.o), caliper = 1.0, replace = FALSE) | ||
|
||
# improvement in maximum single-covariate bias due to matching | ||
bias.obj.before <- mlr.bias(tr = tr, Z.i = Z.i, Z.o = Z.o) | ||
bias.before <- bias.obj.before$subspace$bias | ||
dir <- bias.obj.before$subspace$dir | ||
bias.after <- as.numeric(mlr.bias(tr = tr[idx] | ||
, Z.i = Z.i[idx, ], Z.o = dir[idx], gamma.o = 1.0)$single$bias) | ||
|
||
# percentage bias-squared rediction | ||
cat("normalized bias - before:", bias.before, "\n") | ||
cat("normalized bias - after:", bias.after, "\n") | ||
cat("percentage squared-bias reduction:" | ||
, (bias.before^2 - bias.after^2)/bias.before^2, "\n") | ||
|
||
# matching with replacement | ||
idx.wr <- mlr.match(tr = tr, X = cbind(Z.i, Z.o), caliper = 1.0 | ||
, replace = TRUE) | ||
bias.after.wr <- as.numeric(mlr.bias(tr = tr | ||
, Z.i = Z.i, Z.o = dir, gamma.o = 1.0, idx = idx.wr)$single$bias) | ||
cat("normalized bias - after (with replacement):", bias.after.wr, "\n") | ||
|
||
} | ||
|
||
% Add one or more standard keywords, see file 'KEYWORDS' in the | ||
% R documentation directory. | ||
% \keyword{ ~kwd1 } | ||
% \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
\name{mlr.power} | ||
\alias{mlr.power} | ||
%- Also NEED an '\alias' for EACH other topic documented here. | ||
\title{ | ||
Power analysis for causal inference using linear regression | ||
} | ||
\description{ | ||
Monte Carlo based calculation of study power for treatment effect estimation using linear regression on treatment indicator and adjustment covariates. | ||
} | ||
\usage{ | ||
mlr.power(tr, Z.i = NULL, d, sig.level = 0.05, niter = 1000 | ||
, verbose = FALSE, idx = 1:length(tr), rnd = FALSE) | ||
} | ||
%- maybe also 'usage' for other objects documented here. | ||
\arguments{ | ||
\item{tr}{Binary treatment indicator vector (1=treatment, 0=control), whose coefficient in the linear regression model is TE.} | ||
\item{Z.i}{Matrix of adjustment covariates included in linear regression. We must have \code{nrow(Z.i) == length(tr)}.} | ||
\item{d}{Standardized effect size, equal to treatment effect divided by standard deviation of generative noise.} | ||
\item{sig.level}{Significance level for rejecting null hypothesis.} | ||
\item{niter}{Number of Monte Carlo simulations used for calculating power.} | ||
\item{verbose}{If \code{TRUE}, calculated power is printed.} | ||
\item{idx}{Subset of observations to use for power calculation.} | ||
\item{rnd}{Boolean flag. If \code{TRUE}, power is also calculated for random subsampling of observations, using same treatment and control group sizes as indicated by \code{idx}.} | ||
} | ||
|
||
\details{ | ||
In each Monte Carlo iteration, response variable is generated from a normal distribution whose mean is equal to \code{d * tr} (other coefficients are assumed to be zero since their value does not affect power calculation), and whose standard deviation is \code{1.0}. Then OLS-based regression is performed on data, and p-value for treatment effect is compared to \code{sig.level}, based on which null hypothesis (no effect) is rejected or accepted. The fraction of iterations where null hypothesis is rejected is taken to be power. Standard error is calculated using a binomial-distribution assumption. | ||
} | ||
|
||
\value{ | ||
A numeric vector is returned. If \code{rnd} is \code{FALSE}, meand and standard error of calculated power is returned. If \code{rnd} is \code{TRUE}, mean and standard error of power calculated for random subsampling of observations is returned as well. | ||
} | ||
|
||
%\references{ | ||
%% ~put references to the literature/web site here ~ | ||
%} | ||
|
||
\author{ | ||
Alireza S. Mahani, Mansour T.A. Sharabiani | ||
} | ||
|
||
%\note{ | ||
%% ~~further notes~~ | ||
%} | ||
|
||
%% ~Make other sections like Warning with \section{Warning }{....} ~ | ||
|
||
%\seealso{ | ||
%% ~~objects to See Also as \code{\link{help}}, ~~~ | ||
%} | ||
|
||
%\examples{ | ||
%} | ||
% Add one or more standard keywords, see file 'KEYWORDS' in the | ||
% R documentation directory. | ||
\keyword{ ~kwd1 } | ||
\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line | ||
\name{mlr.power} | ||
\alias{mlr.power} | ||
%- Also NEED an '\alias' for EACH other topic documented here. | ||
\title{ | ||
Power analysis for causal inference using linear regression | ||
} | ||
\description{ | ||
Monte Carlo based calculation of study power for treatment effect estimation using linear regression on treatment indicator and adjustment covariates. | ||
} | ||
\usage{ | ||
mlr.power(tr, Z.i = NULL, d, sig.level = 0.05, niter = 1000 | ||
, verbose = FALSE, idx = 1:length(tr), rnd = FALSE) | ||
} | ||
%- maybe also 'usage' for other objects documented here. | ||
\arguments{ | ||
\item{tr}{Binary treatment indicator vector (1=treatment, 0=control), whose coefficient in the linear regression model is TE.} | ||
\item{Z.i}{Matrix of adjustment covariates included in linear regression. We must have \code{nrow(Z.i) == length(tr)}.} | ||
\item{d}{Standardized effect size, equal to treatment effect divided by standard deviation of generative noise.} | ||
\item{sig.level}{Significance level for rejecting null hypothesis.} | ||
\item{niter}{Number of Monte Carlo simulations used for calculating power.} | ||
\item{verbose}{If \code{TRUE}, calculated power is printed.} | ||
\item{idx}{Subset of observations to use for power calculation.} | ||
\item{rnd}{Boolean flag. If \code{TRUE}, power is also calculated for random subsampling of observations, using same treatment and control group sizes as indicated by \code{idx}.} | ||
} | ||
|
||
\details{ | ||
In each Monte Carlo iteration, response variable is generated from a normal distribution whose mean is equal to \code{d * tr} (other coefficients are assumed to be zero since their value does not affect power calculation), and whose standard deviation is \code{1.0}. Then OLS-based regression is performed on data, and p-value for treatment effect is compared to \code{sig.level}, based on which null hypothesis (no effect) is rejected or accepted. The fraction of iterations where null hypothesis is rejected is taken to be power. Standard error is calculated using a binomial-distribution assumption. | ||
} | ||
|
||
\value{ | ||
A numeric vector is returned. If \code{rnd} is \code{FALSE}, meand and standard error of calculated power is returned. If \code{rnd} is \code{TRUE}, mean and standard error of power calculated for random subsampling of observations is returned as well. | ||
} | ||
|
||
%\references{ | ||
%% ~put references to the literature/web site here ~ | ||
%} | ||
|
||
\author{ | ||
Alireza S. Mahani, Mansour T.A. Sharabiani | ||
} | ||
|
||
%\note{ | ||
%% ~~further notes~~ | ||
%} | ||
|
||
%% ~Make other sections like Warning with \section{Warning }{....} ~ | ||
|
||
%\seealso{ | ||
%% ~~objects to See Also as \code{\link{help}}, ~~~ | ||
%} | ||
|
||
%\examples{ | ||
%} | ||
% Add one or more standard keywords, see file 'KEYWORDS' in the | ||
% R documentation directory. | ||
%\keyword{ ~kwd1 } | ||
%\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line |