From 574d1c1b38e850cc0f7eb41f3dabcc550c2924ba Mon Sep 17 00:00:00 2001 From: Fred Gruber Date: Thu, 27 Oct 2022 16:08:33 -0400 Subject: [PATCH 1/6] Fixed warnings. updated maintainer. --- DESCRIPTION | 9 +++++---- R/simcausal-package.r | 2 +- R/targetparam.r | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f5cab09..fff8502 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,11 +1,12 @@ Package: simcausal Type: Package -Version: 0.5.5 +Version: 0.5.6 Title: Simulating Longitudinal Data with Causal Inference Applications Authors@R: c( - person("Oleg", "Sofrygin", role=c("aut", "cre"), email="oleg.sofrygin@gmail.com"), + person("Oleg", "Sofrygin", role=c("aut"), email="oleg.sofrygin@gmail.com"), person(c("Mark", "J."), "van der Laan", role="aut", email="laan@berkeley.edu"), - person("Romain", "Neugebauer", role="aut", email="Romain.S.Neugebauer@kp.org")) + person("Romain", "Neugebauer", role="aut", email="Romain.S.Neugebauer@kp.org"), + person("Fred", "Gruber", role=c("ctb","cre"), email="fgruber@gmail.com") ) Description: A flexible tool for simulating complex longitudinal data using structural equations, with emphasis on problems in causal inference. Specify interventions and simulate from intervened data generating @@ -15,7 +16,7 @@ Description: A flexible tool for simulating complex longitudinal data using reproducible simulation studies, and allows concise expression of complex functional dependencies for a large number of time-varying nodes. See the package vignette for more information, documentation and examples. -URL: https://github.com/osofr/simcausal +URL: https://github.com/osofr/simcausal BugReports: https://github.com/osofr/simcausal/issues Depends: R (>= 3.2.0) diff --git a/R/simcausal-package.r b/R/simcausal-package.r index 39dff87..a511fe7 100644 --- a/R/simcausal-package.r +++ b/R/simcausal-package.r @@ -51,7 +51,7 @@ #' } #' #' @section Updates: -#' Check for updates and report bugs at \url{http://github.com/osofr/simcausal}. +#' Check for updates and report bugs at \url{https://github.com/osofr/simcausal}. #' #' @references Sofrygin O, van der Laan MJ, Neugebauer R (2017). #' "simcausal R Package: Conducting Transparent and Reproducible Simulation Studies of Causal Effect Estimation with Complex Longitudinal Data." diff --git a/R/targetparam.r b/R/targetparam.r index c027161..4c2557c 100644 --- a/R/targetparam.r +++ b/R/targetparam.r @@ -176,7 +176,7 @@ set.targetE <- function(DAG, outcome, t, param, ..., attr=list()) { if (missing(t)) t <- NULL attr(DAG, "target")$outnodes <- list(gen_name=as.character(outcome), t=t) - if ((class(param)=="character")&&length(param)==1) { + if (is(param,"character")&&length(param)==1){ res_ratio <- length(gsub("[[:space:]]*","",unlist(strsplit(param, "/", fixed = TRUE)))) > 1 res_diff <- length(gsub("[[:space:]]*","",unlist(strsplit(param, "-", fixed = TRUE)))) > 1 interv_nms <- gsub("[[:space:]]*","",unlist(strsplit(param, "[-/]"))) # names of interventions @@ -308,7 +308,7 @@ eval.target <- function(DAG, n, data, actions, rndseed = NULL, verbose = getOpti if (is.null(params.E)&is.null(params.MSM)) stop("at least one target parameter must be specified (set.targetE,set.targetMSM) ") if (length(outnodes)!=2) stop("outnodes must be a list of length two") - if (class(outnodes)!="list") stop("outnodes must be a list") + if (!is(outnodes,"list")) stop("outnodes must be a list") if (!all(c("gen_name", "t")%in%names(outnodes))) stop("outnodes must contain named items gen_name and t") if (length(outnodes$gen_name)>1) stop("can only specify one generic name in outnodes$gen_name") From f2604f56835255924df24a7820afead7e1602e41 Mon Sep 17 00:00:00 2001 From: Fred Gruber Date: Thu, 27 Oct 2022 16:36:28 -0400 Subject: [PATCH 2/6] updated documentation --- DESCRIPTION | 2 +- man/DF.to.long.Rd | 5 ++- man/DF.to.longDT.Rd | 5 ++- man/Define_sVar.Rd | 100 +++++++++++++++++++++++++++++++++++++++++-- man/NetIndClass.Rd | 73 +++++++++++++++++++++++++++++-- man/add.action.Rd | 2 +- man/doLTCF.Rd | 5 ++- man/eval.target.Rd | 10 ++++- man/node.Rd | 3 +- man/plotDAG.Rd | 15 +++++-- man/plotSurvEst.Rd | 11 ++++- man/set.DAG.Rd | 9 +++- man/set.targetE.Rd | 2 +- man/set.targetMSM.Rd | 12 +++++- man/sim.Rd | 17 ++++++-- man/simcausal.Rd | 3 +- man/simfull.Rd | 16 +++++-- man/simobs.Rd | 16 +++++-- 18 files changed, 263 insertions(+), 43 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fff8502..a874754 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,4 +39,4 @@ Suggests: bindata VignetteBuilder: knitr License: GPL-2 -RoxygenNote: 6.1.1 +RoxygenNote: 7.2.0 diff --git a/man/DF.to.long.Rd b/man/DF.to.long.Rd index ef8dc3a..3dd8b8f 100644 --- a/man/DF.to.long.Rd +++ b/man/DF.to.long.Rd @@ -27,7 +27,8 @@ When removing NA's the time-varying covariates that are attributes (attnames) ar \seealso{ \code{\link{DF.to.longDT}} - a faster version of \code{DF.to.long} that uses \code{data.table} package -Other data manipulation functions: \code{\link{DF.to.longDT}}, - \code{\link{doLTCF}} +Other data manipulation functions: +\code{\link{DF.to.longDT}()}, +\code{\link{doLTCF}()} } \concept{data manipulation functions} diff --git a/man/DF.to.longDT.Rd b/man/DF.to.longDT.Rd index 5f4e43b..06316a0 100644 --- a/man/DF.to.longDT.Rd +++ b/man/DF.to.longDT.Rd @@ -28,7 +28,8 @@ Observations with all NA's for all time-varying covariates are removed. When removing NA's the time-varying covariates that are attributes (attnames) are not considered. } \seealso{ -Other data manipulation functions: \code{\link{DF.to.long}}, - \code{\link{doLTCF}} +Other data manipulation functions: +\code{\link{DF.to.long}()}, +\code{\link{doLTCF}()} } \concept{data manipulation functions} diff --git a/man/Define_sVar.Rd b/man/Define_sVar.Rd index bb7c177..af25ecc 100644 --- a/man/Define_sVar.Rd +++ b/man/Define_sVar.Rd @@ -4,9 +4,8 @@ \name{Define_sVar} \alias{Define_sVar} \title{Class for defining and evaluating user-specified summary measures (exprs_list)} -\format{An R6 class object.} -\usage{ -Define_sVar +\format{ +An R6 class object. } \description{ Evaluates and and stores arbitrary summary measure expressions. The expressions (exprs_list) are evaluated in the environment of the input data.frame. @@ -21,4 +20,97 @@ Following fields are created during initialization \item{Kmax} ... } } -\keyword{datasets} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-Define_sVar-new}{\code{Define_sVar$new()}} +\item \href{#method-Define_sVar-set.new.exprs}{\code{Define_sVar$set.new.exprs()}} +\item \href{#method-Define_sVar-eval.nodeforms}{\code{Define_sVar$eval.nodeforms()}} +\item \href{#method-Define_sVar-eval.EFU}{\code{Define_sVar$eval.EFU()}} +\item \href{#method-Define_sVar-df.names}{\code{Define_sVar$df.names()}} +\item \href{#method-Define_sVar-setnode.setenv}{\code{Define_sVar$setnode.setenv()}} +\item \href{#method-Define_sVar-set.net}{\code{Define_sVar$set.net()}} +\item \href{#method-Define_sVar-clone}{\code{Define_sVar$clone()}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Define_sVar-new}{}}} +\subsection{Method \code{new()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Define_sVar$new()}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Define_sVar-set.new.exprs}{}}} +\subsection{Method \code{set.new.exprs()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Define_sVar$set.new.exprs(exprs_list)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Define_sVar-eval.nodeforms}{}}} +\subsection{Method \code{eval.nodeforms()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Define_sVar$eval.nodeforms(cur.node, data.df)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Define_sVar-eval.EFU}{}}} +\subsection{Method \code{eval.EFU()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Define_sVar$eval.EFU(cur.node, data.df)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Define_sVar-df.names}{}}} +\subsection{Method \code{df.names()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Define_sVar$df.names(data.df)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Define_sVar-setnode.setenv}{}}} +\subsection{Method \code{setnode.setenv()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Define_sVar$setnode.setenv(cur.node)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Define_sVar-set.net}{}}} +\subsection{Method \code{set.net()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Define_sVar$set.net(netind_cl)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Define_sVar-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{Define_sVar$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/man/NetIndClass.Rd b/man/NetIndClass.Rd index 28d1b1f..0966c21 100644 --- a/man/NetIndClass.Rd +++ b/man/NetIndClass.Rd @@ -4,9 +4,8 @@ \name{NetIndClass} \alias{NetIndClass} \title{R6 class for creating and storing a friend matrix (network IDs) for network data} -\format{An \code{\link{R6Class}} generator object} -\usage{ -NetIndClass +\format{ +An \code{\link{R6Class}} generator object } \description{ This R6 class defines fields and methods for creating and storing \code{NetInd_k}, @@ -39,3 +38,71 @@ a matrix of friend indices (network IDs) of \code{dim = (nobs x Kmax)}. \keyword{R6} \keyword{class} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-NetIndClass-new}{\code{NetIndClass$new()}} +\item \href{#method-NetIndClass-makeNetInd.fromIDs}{\code{NetIndClass$makeNetInd.fromIDs()}} +\item \href{#method-NetIndClass-make.nF}{\code{NetIndClass$make.nF()}} +\item \href{#method-NetIndClass-mat.nF}{\code{NetIndClass$mat.nF()}} +\item \href{#method-NetIndClass-clone}{\code{NetIndClass$clone()}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-NetIndClass-new}{}}} +\subsection{Method \code{new()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{NetIndClass$new(nobs, Kmax = 1)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-NetIndClass-makeNetInd.fromIDs}{}}} +\subsection{Method \code{makeNetInd.fromIDs()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{NetIndClass$makeNetInd.fromIDs(Net_str, IDs_str = NULL, sep = " ")}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-NetIndClass-make.nF}{}}} +\subsection{Method \code{make.nF()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{NetIndClass$make.nF( + NetInd_k = self$NetInd_k, + nobs = self$nobs, + Kmax = self$Kmax +)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-NetIndClass-mat.nF}{}}} +\subsection{Method \code{mat.nF()}}{ +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{NetIndClass$mat.nF(nFnode)}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-NetIndClass-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{NetIndClass$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/man/add.action.Rd b/man/add.action.Rd index 2a234ab..6b8c877 100644 --- a/man/add.action.Rd +++ b/man/add.action.Rd @@ -30,7 +30,7 @@ Define and add new action (intervention) to the existing DAG object. Use either In addition to the action name and list of action nodes, both of these functions accept arbitrary named attributes (as additional arguments which must be given a name). This additional attributes can be used to simplify specification of dynamic regimes (actions that depend on the past observed covariates). -The formula of the intervention node is allowed to contain undefined variables, as long as those are later defined as a named argument to \code{action}. +The formula of the intervention node is allowed to contain undefined variables, as long as those are later defined as a named argument to \code{action}. In Example 2 below, \code{node("A",..., mean = ifelse(W1 >= theta, 1, 0))}, defines the mean of the node "A" as a function of some undefined variable \code{theta}, setting \code{A} to 1 if the baseline node \code{W1} is above or equal to \code{theta} and 0 vice versa. diff --git a/man/doLTCF.Rd b/man/doLTCF.Rd index e5165fc..6d9d21f 100644 --- a/man/doLTCF.Rd +++ b/man/doLTCF.Rd @@ -65,7 +65,8 @@ Odat.wideLTCF2[c(21,47), 1:18] \seealso{ \code{\link{sim}}, \code{\link{simobs}} and \code{\link{simfull}} for simulating data with and without carry forward imputation. -Other data manipulation functions: \code{\link{DF.to.longDT}}, - \code{\link{DF.to.long}} +Other data manipulation functions: +\code{\link{DF.to.longDT}()}, +\code{\link{DF.to.long}()} } \concept{data manipulation functions} diff --git a/man/eval.target.Rd b/man/eval.target.Rd index c1e24e4..23feb3d 100644 --- a/man/eval.target.Rd +++ b/man/eval.target.Rd @@ -4,8 +4,14 @@ \alias{eval.target} \title{Evaluate the True Value of the Causal Target Parameter} \usage{ -eval.target(DAG, n, data, actions, rndseed = NULL, - verbose = getOption("simcausal.verbose")) +eval.target( + DAG, + n, + data, + actions, + rndseed = NULL, + verbose = getOption("simcausal.verbose") +) } \arguments{ \item{DAG}{DAG object with target parameter set via \code{set.targetE} or \code{set.targetMSM} functions} diff --git a/man/node.Rd b/man/node.Rd index 70d12f0..d7ad44f 100644 --- a/man/node.Rd +++ b/man/node.Rd @@ -4,8 +4,7 @@ \alias{node} \title{Create Node Object(s)} \usage{ -node(name, t, distr, EFU, order, ..., params = list(), - asis.params = list()) +node(name, t, distr, EFU, order, ..., params = list(), asis.params = list()) } \arguments{ \item{name}{Character node name or a vector of names when specifying a multivariate node. For time-dependent nodes the names will be automatically expanded to a scheme "name_t" for each t provided specified.} diff --git a/man/plotDAG.Rd b/man/plotDAG.Rd index e4b5553..4b14e72 100644 --- a/man/plotDAG.Rd +++ b/man/plotDAG.Rd @@ -4,9 +4,18 @@ \alias{plotDAG} \title{Plot DAG} \usage{ -plotDAG(DAG, tmax = NULL, xjitter, yjitter, node.action.color, - vertex_attrs = list(), edge_attrs = list(), excludeattrs, - customvlabs, verbose = getOption("simcausal.verbose")) +plotDAG( + DAG, + tmax = NULL, + xjitter, + yjitter, + node.action.color, + vertex_attrs = list(), + edge_attrs = list(), + excludeattrs, + customvlabs, + verbose = getOption("simcausal.verbose") +) } \arguments{ \item{DAG}{A DAG object that was specified by calling \code{\link{set.DAG}}} diff --git a/man/plotSurvEst.Rd b/man/plotSurvEst.Rd index 08a082d..8063f02 100644 --- a/man/plotSurvEst.Rd +++ b/man/plotSurvEst.Rd @@ -4,8 +4,15 @@ \alias{plotSurvEst} \title{(EXPERIMENTAL) Plot Discrete Survival Function(s)} \usage{ -plotSurvEst(surv = list(), xindx = NULL, ylab = "", xlab = "t", - ylim = c(0, 1), legend.xyloc = "topright", ...) +plotSurvEst( + surv = list(), + xindx = NULL, + ylab = "", + xlab = "t", + ylim = c(0, 1), + legend.xyloc = "topright", + ... +) } \arguments{ \item{surv}{A list of vectors, each containing action-specific discrete survival probabilities over time.} diff --git a/man/set.DAG.Rd b/man/set.DAG.Rd index b221e29..1f635d8 100644 --- a/man/set.DAG.Rd +++ b/man/set.DAG.Rd @@ -4,8 +4,13 @@ \alias{set.DAG} \title{Create and Lock DAG Object} \usage{ -set.DAG(DAG, vecfun, latent.v, n.test = 10, - verbose = getOption("simcausal.verbose")) +set.DAG( + DAG, + vecfun, + latent.v, + n.test = 10, + verbose = getOption("simcausal.verbose") +) } \arguments{ \item{DAG}{Named list of node objects that together will form a DAG. diff --git a/man/set.targetE.Rd b/man/set.targetE.Rd index f24a548..b012c9d 100644 --- a/man/set.targetE.Rd +++ b/man/set.targetE.Rd @@ -63,7 +63,7 @@ D_WAY <- set.targetE(D_WAY, outcome="Y", param="A1/A0") eval.target(D_WAY, n=10000) # Alternative parameter evaluation by passing already simulated full data to -# \\code{eval.target} +# \code{eval.target} X_dat1 <- simfull(A(D_WAY), n=10000) D_WAY <- set.targetE(D_WAY, outcome="Y", param="A1/A0") eval.target(D_WAY, data=X_dat1) diff --git a/man/set.targetMSM.Rd b/man/set.targetMSM.Rd index 403344e..7e8f758 100644 --- a/man/set.targetMSM.Rd +++ b/man/set.targetMSM.Rd @@ -4,8 +4,16 @@ \alias{set.targetMSM} \title{Define Causal Parameters with a Working Marginal Structural Model (MSM)} \usage{ -set.targetMSM(DAG, outcome, t, formula, family = "quasibinomial", hazard, - ..., attr = list()) +set.targetMSM( + DAG, + outcome, + t, + formula, + family = "quasibinomial", + hazard, + ..., + attr = list() +) } \arguments{ \item{DAG}{Object specifying the directed acyclic graph (DAG) for the observed data} diff --git a/man/sim.Rd b/man/sim.Rd index 3923769..a3704d3 100644 --- a/man/sim.Rd +++ b/man/sim.Rd @@ -4,8 +4,16 @@ \alias{sim} \title{Simulate Observed or Full Data from \code{DAG} Object} \usage{ -sim(DAG, actions, n, wide = TRUE, LTCF = NULL, rndseed = NULL, - rndseed.reset.node = NULL, verbose = getOption("simcausal.verbose")) +sim( + DAG, + actions, + n, + wide = TRUE, + LTCF = NULL, + rndseed = NULL, + rndseed.reset.node = NULL, + verbose = getOption("simcausal.verbose") +) } \arguments{ \item{DAG}{A DAG objects that has been locked with set.DAG(DAG). Observed data from this DAG will be simulated if actions argument is omitted.} @@ -82,7 +90,8 @@ Journal of Statistical Software, 81(2), 1-47. doi: 10.18637/jss.v081.i02. \seealso{ \code{\link{simobs}} - a wrapper function for simulating observed data only; \code{\link{simfull}} - a wrapper function for simulating full data only; \code{\link{doLTCF}} - forward imputation of the missing values in already simulating data; \code{\link{DF.to.long}}, \code{\link{DF.to.longDT}} - converting longitudinal data from wide to long formats. -Other simulation functions: \code{\link{simfull}}, - \code{\link{simobs}} +Other simulation functions: +\code{\link{simfull}()}, +\code{\link{simobs}()} } \concept{simulation functions} diff --git a/man/simcausal.Rd b/man/simcausal.Rd index 7f571d7..bd23ae7 100644 --- a/man/simcausal.Rd +++ b/man/simcausal.Rd @@ -3,7 +3,6 @@ \docType{package} \name{simcausal} \alias{simcausal} -\alias{simcausal-package} \title{Simulating Longitudinal Data with Causal Inference Applications} \description{ The \pkg{simcausal} R package is a tool for specification and simulation of complex longitudinal data structures that are @@ -64,7 +63,7 @@ The following most common types of output are produced by the package: \section{Updates}{ -Check for updates and report bugs at \url{http://github.com/osofr/simcausal}. +Check for updates and report bugs at \url{https://github.com/osofr/simcausal}. } \references{ diff --git a/man/simfull.Rd b/man/simfull.Rd index 8a0c221..460bbdc 100644 --- a/man/simfull.Rd +++ b/man/simfull.Rd @@ -4,8 +4,15 @@ \alias{simfull} \title{Simulate Full Data (From Action DAG(s))} \usage{ -simfull(actions, n, wide = TRUE, LTCF = NULL, rndseed = NULL, - rndseed.reset.node = NULL, verbose = getOption("simcausal.verbose")) +simfull( + actions, + n, + wide = TRUE, + LTCF = NULL, + rndseed = NULL, + rndseed.reset.node = NULL, + verbose = getOption("simcausal.verbose") +) } \arguments{ \item{actions}{Actions specifying the counterfactual DAG. This argument must be either an object of class DAG.action or a list of DAG.action objects.} @@ -34,7 +41,8 @@ This function simulates full data based on a list of intervention DAGs, returnin \seealso{ \code{\link{simobs}} - a wrapper function for simulating observed data only; \code{\link{sim}} - a wrapper function for simulating both types of data; \code{\link{doLTCF}} for forward imputation of the missing values in already simulating data; \code{\link{DF.to.long}}, \code{\link{DF.to.longDT}} - converting longitudinal data from wide to long formats. -Other simulation functions: \code{\link{simobs}}, - \code{\link{sim}} +Other simulation functions: +\code{\link{simobs}()}, +\code{\link{sim}()} } \concept{simulation functions} diff --git a/man/simobs.Rd b/man/simobs.Rd index 1c91e1e..e763cef 100644 --- a/man/simobs.Rd +++ b/man/simobs.Rd @@ -4,8 +4,15 @@ \alias{simobs} \title{Simulate Observed Data} \usage{ -simobs(DAG, n, wide = TRUE, LTCF = NULL, rndseed = NULL, - rndseed.reset.node = NULL, verbose = getOption("simcausal.verbose")) +simobs( + DAG, + n, + wide = TRUE, + LTCF = NULL, + rndseed = NULL, + rndseed.reset.node = NULL, + verbose = getOption("simcausal.verbose") +) } \arguments{ \item{DAG}{A DAG objects that has been locked with set.DAG(DAG). Observed data from this DAG will be simulated.} @@ -34,7 +41,8 @@ This function simulates observed data from a DAG object. \seealso{ \code{\link{simfull}} - a wrapper function for simulating full data only; \code{\link{sim}} - a wrapper function for simulating both types of data; \code{\link{doLTCF}} for forward imputation of the missing values in already simulating data; \code{\link{DF.to.long}}, \code{\link{DF.to.longDT}} - converting longitudinal data from wide to long formats. -Other simulation functions: \code{\link{simfull}}, - \code{\link{sim}} +Other simulation functions: +\code{\link{simfull}()}, +\code{\link{sim}()} } \concept{simulation functions} From a99976cf0184afe20030a15804a3c28cb101d11c Mon Sep 17 00:00:00 2001 From: Fred Gruber Date: Fri, 28 Oct 2022 08:49:24 -0400 Subject: [PATCH 3/6] added link to vignette on the readme --- DESCRIPTION | 3 ++- README.md | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a874754..50ecd4e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,7 +6,7 @@ Authors@R: c( person("Oleg", "Sofrygin", role=c("aut"), email="oleg.sofrygin@gmail.com"), person(c("Mark", "J."), "van der Laan", role="aut", email="laan@berkeley.edu"), person("Romain", "Neugebauer", role="aut", email="Romain.S.Neugebauer@kp.org"), - person("Fred", "Gruber", role=c("ctb","cre"), email="fgruber@gmail.com") ) + person("Fred", "Gruber", role=c("ctb","cre"), email="fgruber@gmail.com")) Description: A flexible tool for simulating complex longitudinal data using structural equations, with emphasis on problems in causal inference. Specify interventions and simulate from intervened data generating @@ -40,3 +40,4 @@ Suggests: VignetteBuilder: knitr License: GPL-2 RoxygenNote: 7.2.0 +Encoding: UTF-8 \ No newline at end of file diff --git a/README.md b/README.md index 404eded..1353441 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ devtools::install_github('osofr/simcausal', build_vignettes = FALSE) ``` ### Documentation - Once the package is installed, see the [vignette](https://CRAN.R-project.org/package=simcausal/vignettes/simcausal_vignette.pdf), consult the internal package documentation and examples. * To see the vignette in R: From d3551960b624cd36d25ffe400a0e74ab057a92f5 Mon Sep 17 00:00:00 2001 From: Fred Gruber Date: Tue, 15 Oct 2024 20:20:04 -0400 Subject: [PATCH 4/6] Updated version --- DESCRIPTION | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 50ecd4e..8770a46 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: simcausal Type: Package -Version: 0.5.6 +Version: 0.5.7 Title: Simulating Longitudinal Data with Causal Inference Applications Authors@R: c( person("Oleg", "Sofrygin", role=c("aut"), email="oleg.sofrygin@gmail.com"), @@ -16,7 +16,7 @@ Description: A flexible tool for simulating complex longitudinal data using reproducible simulation studies, and allows concise expression of complex functional dependencies for a large number of time-varying nodes. See the package vignette for more information, documentation and examples. -URL: https://github.com/osofr/simcausal +URL: https://github.com/osofr/simcausal BugReports: https://github.com/osofr/simcausal/issues Depends: R (>= 3.2.0) @@ -40,4 +40,4 @@ Suggests: VignetteBuilder: knitr License: GPL-2 RoxygenNote: 7.2.0 -Encoding: UTF-8 \ No newline at end of file +Encoding: UTF-8 From 7317f3b3def689536e15a5c920e174c6856fc584 Mon Sep 17 00:00:00 2001 From: Fred Gruber Date: Thu, 17 Oct 2024 09:00:47 -0400 Subject: [PATCH 5/6] removed underscore which gave problem now --- vignettes/{simcausal_vignette.Rnw => simcausalVignette.Rnw} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename vignettes/{simcausal_vignette.Rnw => simcausalVignette.Rnw} (99%) diff --git a/vignettes/simcausal_vignette.Rnw b/vignettes/simcausalVignette.Rnw similarity index 99% rename from vignettes/simcausal_vignette.Rnw rename to vignettes/simcausalVignette.Rnw index 051b3f5..96e2f70 100644 --- a/vignettes/simcausal_vignette.Rnw +++ b/vignettes/simcausalVignette.Rnw @@ -126,7 +126,7 @@ means, the average treatment effects and coefficients from working marginal stru require(knitr) require(simcausal) cache_opt <- TRUE - opts_chunk$set(fig.path='figure/beamer-',fig.align='center',fig.show='hold',size='footnotesize') + opts_chunk$set(fig.path='figure/beamer-',fig.align='center',fig.show='hold',size='footnotesize',escape=TRUE) # to crop white space in output figures: knit_hooks$set(pdfcrop = hook_pdfcrop) # To disable syntax color highlighing of R code in the entire document From c2837c7844306e104be9a52a0d069b0f1c03d133 Mon Sep 17 00:00:00 2001 From: Fred Gruber Date: Fri, 18 Oct 2024 22:45:44 -0400 Subject: [PATCH 6/6] trying to submit --- DESCRIPTION | 2 +- R/network.R | 4 ++-- README.md | 20 ++++++++++---------- man/NetIndClass.Rd | 2 +- man/doLTCF.Rd | 4 ++-- man/rcat.b1.Rd | 8 ++++---- man/rcat.factor.Rd | 4 ++-- man/simcausal.Rd | 20 ++++++++++++++++++++ man/simfull.Rd | 4 ++-- man/simobs.Rd | 4 ++-- 10 files changed, 46 insertions(+), 26 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8770a46..90b1076 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,5 +39,5 @@ Suggests: bindata VignetteBuilder: knitr License: GPL-2 -RoxygenNote: 7.2.0 +RoxygenNote: 7.3.1 Encoding: UTF-8 diff --git a/R/network.R b/R/network.R index 97c6d32..b05ef2b 100644 --- a/R/network.R +++ b/R/network.R @@ -274,7 +274,7 @@ netvar <- function(varnm, fidx) { #' #' @docType class #' @importFrom R6 R6Class -#' @format An \code{\link{R6Class}} generator object +#' @format An \code{\link[R6]{R6Class}} generator object #' @keywords R6 class #' @details #' \itemize{ @@ -371,4 +371,4 @@ NetIndClass <- R6Class("NetIndClass", invisible(self) } ) -) \ No newline at end of file +) diff --git a/README.md b/README.md index 1353441..d91a0b8 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,14 @@ simcausal [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/simcausal)](https://CRAN.R-project.org/package=simcausal) [![](http://cranlogs.r-pkg.org/badges/simcausal)](https://CRAN.R-project.org/package=simcausal) [![](http://cranlogs.r-pkg.org/badges/grand-total/simcausal)](https://CRAN.R-project.org/package=simcausal) -[![Travis-CI Build Status](https://travis-ci.org/osofr/simcausal.svg?branch=master)](https://travis-ci.org/osofr/simcausal) +[![Travis-CI Build Status](https://app.travis-ci.org/osofr/simcausal.svg?branch=master)](https://app.travis-ci.com/osofr/simcausal) [![Coverage Status](https://coveralls.io/repos/osofr/simcausal/badge.svg?branch=master&service=github)](https://coveralls.io/github/osofr/simcausal?branch=master) -The `simcausal` R package is a tool for specification and simulation of complex longitudinal data structures that are based on structural equation models (SEMs). The emphasis is on the types of simulations frequently encountered in causal inference problems, such as, observational data with time-dependent confounding, selection bias, and random monitoring processes. The interface allows for quick expression of dependencies between a large number of time-varying nodes. +The `simcausal` R package is a tool for specification and simulation of complex longitudinal data structures that are based on structural equation models (SEMs). The emphasis is on the types of simulations frequently encountered in causal inference problems, such as, observational data with time-dependent confounding, selection bias, and random monitoring processes. The interface allows for quick expression of dependencies between a large number of time-varying nodes. ### Installation -To install the CRAN release version of `simcausal`: +To install the CRAN release version of `simcausal`: ```R install.packages('simcausal') @@ -23,7 +23,7 @@ devtools::install_github('osofr/simcausal', build_vignettes = FALSE) ``` ### Documentation -Once the package is installed, see the [vignette](https://CRAN.R-project.org/package=simcausal/vignettes/simcausal_vignette.pdf), consult the internal package documentation and examples. +Once the package is installed, see the [vignette](https://CRAN.R-project.org/package=simcausal/vignettes/simcausal_vignette.pdf), consult the internal package documentation and examples. * To see the vignette in R: @@ -50,7 +50,7 @@ Below is an example simulating data with 4 covariates specified by 4 structural ```R library("simcausal") -D <- DAG.empty() + +D <- DAG.empty() + node("CVD", distr="rcat.b1", probs = c(0.5, 0.25, 0.25)) + node("A1C", distr="rnorm", mean = 5 + (CVD > 1)*10 + (CVD > 2)*5) + node("TI", distr="rbern", prob = plogis(-0.5 - 0.3*CVD + 0.2*A1C)) + @@ -69,9 +69,9 @@ To allow the above nodes `A1C`, `TI` and `Y` to change over time, for time point ```R library("simcausal") -D <- DAG.empty() + +D <- DAG.empty() + node("CVD", distr="rcat.b1", probs = c(0.5, 0.25, 0.25)) + - node("A1C", t=0, distr="rnorm", mean=5 + (CVD > 1)*10 + (CVD > 2)*5) + + node("A1C", t=0, distr="rnorm", mean=5 + (CVD > 1)*10 + (CVD > 2)*5) + node("TI", t=0, distr="rbern", prob=plogis(-5 - 0.3*CVD + 0.5*A1C[t])) + node("A1C", t=1:7, distr="rnorm", mean=-TI[t-1]*10 + 5 + (CVD > 1)*10 + (CVD > 2)*5) + @@ -83,7 +83,7 @@ dat.long <- sim(D,n=200) The `+ action` function allows defining counterfactual data under various interventions (e.g., static, dynamic, deterministic, or stochastic), which can be then simulated by calling `sim` function. In particular, the interventions may represent exposures to treatment regimens, the occurrence or non-occurrence of right-censoring events, or of clinical monitoring events. -In addition, the functions `set.targetE`, `set.targetMSM` and `eval.target` provide tools for defining and computing a few selected features of the distribution of the counterfactual data that represent common causal quantities of interest, such as, treatment-specific means, the average treatment effects and coefficients from working marginal structural models. +In addition, the functions `set.targetE`, `set.targetMSM` and `eval.target` provide tools for defining and computing a few selected features of the distribution of the counterfactual data that represent common causal quantities of interest, such as, treatment-specific means, the average treatment effects and coefficients from working marginal structural models. ### Using networks in SEMs @@ -99,8 +99,8 @@ D <- DAG.empty() + network("ER.net", netfun = "rnet.gnm", m_pn = 50) First define two IDD nodes `W1` (categorical) and `W2` (Bernoulli): ```R -D <- D + - node("W1", distr = "rcat.b1", probs = c(0.0494, 0.1823, 0.2806, 0.2680, 0.1651, 0.0546)) + +D <- D + + node("W1", distr = "rcat.b1", probs = c(0.0494, 0.1823, 0.2806, 0.2680, 0.1651, 0.0546)) + node("W2", distr = "rbern", prob = plogis(-0.2 + W1/3)) ``` diff --git a/man/NetIndClass.Rd b/man/NetIndClass.Rd index 0966c21..18194b9 100644 --- a/man/NetIndClass.Rd +++ b/man/NetIndClass.Rd @@ -5,7 +5,7 @@ \alias{NetIndClass} \title{R6 class for creating and storing a friend matrix (network IDs) for network data} \format{ -An \code{\link{R6Class}} generator object +An \code{\link[R6]{R6Class}} generator object } \description{ This R6 class defines fields and methods for creating and storing \code{NetInd_k}, diff --git a/man/doLTCF.Rd b/man/doLTCF.Rd index 6d9d21f..16a73be 100644 --- a/man/doLTCF.Rd +++ b/man/doLTCF.Rd @@ -66,7 +66,7 @@ Odat.wideLTCF2[c(21,47), 1:18] \code{\link{sim}}, \code{\link{simobs}} and \code{\link{simfull}} for simulating data with and without carry forward imputation. Other data manipulation functions: -\code{\link{DF.to.longDT}()}, -\code{\link{DF.to.long}()} +\code{\link{DF.to.long}()}, +\code{\link{DF.to.longDT}()} } \concept{data manipulation functions} diff --git a/man/rcat.b1.Rd b/man/rcat.b1.Rd index 9940feb..e4fc10e 100644 --- a/man/rcat.b1.Rd +++ b/man/rcat.b1.Rd @@ -30,13 +30,13 @@ or range 0, 1, ..., \code{ncol(probs)} for \code{rcat.b0}. For sampling categori } \section{Functions}{ \itemize{ -\item \code{rcategor.int}: (Deperecated) Random Sample from Base 1 Categorical (Integer) Distribution +\item \code{rcategor.int()}: (Deperecated) Random Sample from Base 1 Categorical (Integer) Distribution -\item \code{rcat.b1}: Random Sample from Base 1 Categorical (Integer) Distribution +\item \code{rcat.b1()}: Random Sample from Base 1 Categorical (Integer) Distribution -\item \code{rcat.b0}: Random Sample from Base 0 Categorical (Integer) Distribution -}} +\item \code{rcat.b0()}: Random Sample from Base 0 Categorical (Integer) Distribution +}} \seealso{ \code{\link{rcat.factor}} } diff --git a/man/rcat.factor.Rd b/man/rcat.factor.Rd index 2164606..9387b1d 100644 --- a/man/rcat.factor.Rd +++ b/man/rcat.factor.Rd @@ -28,9 +28,9 @@ The number of categories generated is equal to \code{ncol(probs)+1}, the levels } \section{Functions}{ \itemize{ -\item \code{rcategor}: (Deperecated) Random Sample of a Categorical Factor -}} +\item \code{rcategor()}: (Deperecated) Random Sample of a Categorical Factor +}} \examples{ #--------------------------------------------------------------------------------------- diff --git a/man/simcausal.Rd b/man/simcausal.Rd index bd23ae7..e7d83c2 100644 --- a/man/simcausal.Rd +++ b/man/simcausal.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/simcausal-package.r \docType{package} \name{simcausal} +\alias{simcausal-package} \alias{simcausal} \title{Simulating Longitudinal Data with Causal Inference Applications} \description{ @@ -71,3 +72,22 @@ Sofrygin O, van der Laan MJ, Neugebauer R (2017). "simcausal R Package: Conducting Transparent and Reproducible Simulation Studies of Causal Effect Estimation with Complex Longitudinal Data." Journal of Statistical Software, 81(2), 1-47. doi: 10.18637/jss.v081.i02. } +\seealso{ +Useful links: +\itemize{ + \item \url{https://github.com/osofr/simcausal} + \item Report bugs at \url{https://github.com/osofr/simcausal/issues} +} + +} +\author{ +\strong{Maintainer}: Fred Gruber \email{fgruber@gmail.com} [contributor] + +Authors: +\itemize{ + \item Oleg Sofrygin \email{oleg.sofrygin@gmail.com} + \item Mark J. van der Laan \email{laan@berkeley.edu} + \item Romain Neugebauer \email{Romain.S.Neugebauer@kp.org} +} + +} diff --git a/man/simfull.Rd b/man/simfull.Rd index 460bbdc..6310d8d 100644 --- a/man/simfull.Rd +++ b/man/simfull.Rd @@ -42,7 +42,7 @@ This function simulates full data based on a list of intervention DAGs, returnin \code{\link{simobs}} - a wrapper function for simulating observed data only; \code{\link{sim}} - a wrapper function for simulating both types of data; \code{\link{doLTCF}} for forward imputation of the missing values in already simulating data; \code{\link{DF.to.long}}, \code{\link{DF.to.longDT}} - converting longitudinal data from wide to long formats. Other simulation functions: -\code{\link{simobs}()}, -\code{\link{sim}()} +\code{\link{sim}()}, +\code{\link{simobs}()} } \concept{simulation functions} diff --git a/man/simobs.Rd b/man/simobs.Rd index e763cef..1925a67 100644 --- a/man/simobs.Rd +++ b/man/simobs.Rd @@ -42,7 +42,7 @@ This function simulates observed data from a DAG object. \code{\link{simfull}} - a wrapper function for simulating full data only; \code{\link{sim}} - a wrapper function for simulating both types of data; \code{\link{doLTCF}} for forward imputation of the missing values in already simulating data; \code{\link{DF.to.long}}, \code{\link{DF.to.longDT}} - converting longitudinal data from wide to long formats. Other simulation functions: -\code{\link{simfull}()}, -\code{\link{sim}()} +\code{\link{sim}()}, +\code{\link{simfull}()} } \concept{simulation functions}