Skip to content

Commit

Permalink
documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
kkholst committed Oct 9, 2024
1 parent 041c315 commit 581e7d5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 78 deletions.
18 changes: 8 additions & 10 deletions R/aipw.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
##' @export
##' @param response_model Model for the response given covariates (ml_model or
##' formula)
##' @param missing_model Missing data mechanism model (propensity model)
##' (ml_model or formula)
##' @param propensity_model Optional missing data mechanism model (propensity
##' model) (ml_model or formula)
##' @param data data.frame
##' @param ... additional arguments (see [cate()])
##' @param formula design specifying the OLS estimator with outcome given by the
##' EIF
##' @param missing_model Optional missing_model (ml_model or formula). By
##' default will use the same design as the response_model.
##' @examples
##' m <- lvm(y ~ x+z, r ~ x)
##' distribution(m,~ r) <- binomial.lvm()
Expand All @@ -22,7 +20,7 @@
##'
##' aipw(y0 ~ x, data=d)
aipw <- function(response_model,
missing_model,
propensity_model,
formula = ~1,
data,
...) {
Expand All @@ -35,14 +33,14 @@ aipw <- function(response_model,
data = data, na.action = na.pass
)) * 1
data[, "R_"] <- r[, 1]
if (base::missing(missing_model)) {
missing_model <- update(response_model$formula, as.formula("R_ ~ ."))
if (base::missing(propensity_model)) {
propensity_model <- update(response_model$formula, as.formula("R_ ~ ."))
}
if (inherits(missing_model, "formula")) {
missing_model <- ML(missing_model, family=binomial)
if (inherits(propensity_model, "formula")) {
propensity_model <- ML(propensity_model, family=binomial)
}
cate(response_model=response_model,
propensity_model=missing_model,
propensity_model=propensity_model,
cate_model = formula,
data = data, contrast = 1, stratify = TRUE,
...
Expand Down
4 changes: 2 additions & 2 deletions R/cate.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ ate_if_fold <- function(fold, data,
IC <- part1 + eY
adj <- NULL
if (inherits(pmod, "glm")) {
## Term from estimating propensity model / treatment probabilities that does not go to
## zero in probability unless Q-model is correct
## Term from estimating propensity model / treatment probabilities that does
## not go to zero in probability unless Q-model is correct
pX <- propensity_model$design(deval, intercept = TRUE)
dlinkinv <- pmod$family$mu.eta
adj <- -part1 / pr * dlinkinv(pmod$family$linkfun(pr))
Expand Down
64 changes: 33 additions & 31 deletions R/riskreg.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
##' @description Risk regression with binary exposure and nuisance model for the odds-product.
##' @description Risk regression with binary exposure and nuisance model for the
##' odds-product.
##'
##' Let \eqn{A} be the binary exposure, \eqn{V} the set of covariates, and
##' \eqn{Y} the binary response variable, and define
##' \eqn{p_a(v) = P(Y=1 \mid A=a, V=v), a\in\{0,1\}}{pa(v) = P(Y=1|A=a,V=v), a=0,1}.
##' \eqn{Y} the binary response variable, and define \eqn{p_a(v) = P(Y=1 \mid
##' A=a, V=v), a\in\{0,1\}}{pa(v) = P(Y=1|A=a,V=v), a=0,1}.
##'
##' The \bold{target parameter} is either the \emph{relative risk}
##' \deqn{\mathrm{RR}(v) = \frac{p_1(v)}{p_0(v)}}{RR(v) = p1(v)/p0(v)}
##' or the \emph{risk difference}
##' \deqn{\mathrm{RD}(v) = p_1(v)-p_0(v)}{RD(v)=p1(v)-p0(v)}
##'
##' We assume a target parameter model given by either
##' \deqn{\log\{RR(v)\} = \alpha^t v}{log[RR(v)] = a'v}
##' or
##' \deqn{\mathrm{arctanh}\{RD(v)\} = \alpha^t v}{arctanh[RD(v)] = a'v}
##' and similarly a working linear \bold{nuisance model} for the \emph{odds-product}
##' \deqn{\phi(v) = \log\left(\frac{p_{0}(v)p_{1}(v)}{(1-p_{0}(v))(1-p_{1}(v))}\right)
##' = \beta^t v}{log[p0(v)p1(v)/{(1-p0(v))(1-p1(v))}] = b'v}.
##' We assume a target parameter model given by either \deqn{\log\{RR(v)\} =
##' \alpha^t v}{log[RR(v)] = a'v} or \deqn{\mathrm{arctanh}\{RD(v)\} = \alpha^t
##' v}{arctanh[RD(v)] = a'v} and similarly a working linear \bold{nuisance
##' model} for the \emph{odds-product} \deqn{\phi(v) =
##' \log\left(\frac{p_{0}(v)p_{1}(v)}{(1-p_{0}(v))(1-p_{1}(v))}\right) = \beta^t
##' v}{log[p0(v)p1(v)/{(1-p0(v))(1-p1(v))}] = b'v}.
##'
##' A \bold{propensity model} for \eqn{E(A=1|V)} is also fitted using a logistic regression working model
##' \deqn{\mathrm{logit}\{E(A=1\mid V=v)\} = \gamma^t v.}{logit[E(A=1|V=v)] = c'v.}
##' A \bold{propensity model} for \eqn{E(A=1|V)} is also fitted using a logistic
##' regression working model \deqn{\mathrm{logit}\{E(A=1\mid V=v)\} = \gamma^t
##' v.}{logit[E(A=1|V=v)] = c'v.}
##'
##' If both the odds-product model and the propensity model are correct the estimator is efficient.
##' Further, the estimator is consistent in the union model, i.e., the estimator is
##' double-robust in the sense that only one of the two models needs to be correctly specified
##' to get a consistent estimate.
##' If both the odds-product model and the propensity model are correct the
##' estimator is efficient. Further, the estimator is consistent in the union
##' model, i.e., the estimator is double-robust in the sense that only one of
##' the two models needs to be correctly specified to get a consistent estimate.
##'
##' @title Risk regression
##' @param formula formula (see details below)
Expand All @@ -37,25 +38,26 @@
##' @param std.err If TRUE standard errors are calculated
##' @param start optional starting values
##' @param mle Semi-parametric (double-robust) estimate or MLE (TRUE gives MLE)
##' @param ... additional arguments to unconstrained optimization routine (nlminb)
##' @return An object of class '\code{riskreg.targeted}' is returned. See \code{\link{targeted-class}}
##' for more details about this class and its generic functions.
##' @references Richardson, T. S., Robins, J. M., & Wang, L. (2017). On modeling and
##' estimation for the relative risk and risk difference. Journal of the
##' American Statistical Association, 112(519),
##' 1121–1130. http://dx.doi.org/10.1080/01621459.2016.1192546
##' @details
##' The 'formula' argument should be given as
##' \code{response ~ exposure | target-formula | nuisance-formula}
##' or
##' \code{response ~ exposure | target | nuisance | propensity}
##' @param ... additional arguments to unconstrained optimization routine
##' (nlminb)
##' @return An object of class '\code{riskreg.targeted}' is returned. See
##' \code{\link{targeted-class}} for more details about this class and its
##' generic functions.
##' @references Richardson, T. S., Robins, J. M., & Wang, L. (2017). On modeling
##' and estimation for the relative risk and risk difference. Journal of the
##' American Statistical Association, 112(519), 1121–1130.
##' http://dx.doi.org/10.1080/01621459.2016.1192546
##' @details The 'formula' argument should be given as \code{response ~ exposure
##' | target-formula | nuisance-formula} or \code{response ~ exposure | target
##' | nuisance | propensity}
##'
##' E.g., \code{riskreg(y ~ a | 1 | x+z | x+z, data=...)}
##'
##' Alternatively, the model can specifed using the target, nuisance and propensity arguments:
##' \code{riskreg(y ~ a, target=~1, nuisance=~x+z, ...)}
##' Alternatively, the model can specifed using the target, nuisance and
##' propensity arguments: \code{riskreg(y ~ a, target=~1, nuisance=~x+z, ...)}
##'
##' The \code{riskreg_fit} function can be used with matrix inputs rather than formulas.
##' The \code{riskreg_fit} function can be used with matrix inputs rather than
##' formulas.
##'
##' @export
##' @aliases riskreg riskreg_fit riskreg_mle
Expand Down
6 changes: 3 additions & 3 deletions man/aipw.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 35 additions & 32 deletions man/riskreg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 581e7d5

Please sign in to comment.