Skip to content

Commit

Permalink
version 0.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
asmahani authored and cran-robot committed Feb 3, 2020
1 parent a009418 commit 38b6d05
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 152 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
@@ -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'.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -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
7 changes: 4 additions & 3 deletions MD5
@@ -1,4 +1,5 @@
6e7fa8e3e300366b1f3efe2ea1cb306c *DESCRIPTION
26d0700c6f06f727612f34c3dbaa5901 *ChangeLog
668568cfff12af5151aa6723d79c9893 *DESCRIPTION
5b3f732edd1f53efde0c4f4e8ac46f5d *NAMESPACE
90822c7f7d593478076275cc4466a36a *R/mlr_core.R
8fc81b92a748cb4eaa96fce0e6fc878a *R/mlr_utils.R
Expand All @@ -13,9 +14,9 @@ c586b2b2d129c3ee5cdaaa9e159adbf7 *man/mlr.Rd
0177ee985df45922b93593dfda5b8e29 *man/mlr.bias.constructor.Rd
f0da6d6302c6452a44a5e30012813793 *man/mlr.combine.bias.variance.Rd
ad2b6da3da0ccf29f5f309c015938cdf *man/mlr.generate.Z.o.Rd
16dc34ed2a658570ab12141226ae12a0 *man/mlr.match.Rd
64884b83e20d3139f9d476d48cbf3184 *man/mlr.match.Rd
ce1ef8440d6dde3b5729a77b1de2e6a6 *man/mlr.orthogonalize.Rd
cee827b04a536b598e83640175e9ad34 *man/mlr.power.Rd
27875fdb8666a3081557daa97ef6a381 *man/mlr.power.Rd
92213bc6066fd41378d97c5f8887cc3f *man/mlr.smd.Rd
587560f0d27899421bb33226114716c4 *man/mlr.variance.Rd
88c9d768c900c9e5782a417714ccb702 *man/plot.summary.mlr.Rd
Expand Down
175 changes: 87 additions & 88 deletions man/mlr.match.Rd
@@ -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
114 changes: 57 additions & 57 deletions man/mlr.power.Rd
@@ -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

0 comments on commit 38b6d05

Please sign in to comment.