Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
Package: simcausal
Type: Package
Version: 0.5.5
Version: 0.5.7
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
Expand Down Expand Up @@ -38,4 +39,5 @@ Suggests:
bindata
VignetteBuilder: knitr
License: GPL-2
RoxygenNote: 6.1.1
RoxygenNote: 7.3.1
Encoding: UTF-8
4 changes: 2 additions & 2 deletions R/network.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -371,4 +371,4 @@ NetIndClass <- R6Class("NetIndClass",
invisible(self)
}
)
)
)
2 changes: 1 addition & 1 deletion R/simcausal-package.r
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions R/targetparam.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -23,8 +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:

Expand All @@ -51,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)) +
Expand All @@ -70,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) +
Expand All @@ -84,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
Expand All @@ -100,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))
```

Expand Down
5 changes: 3 additions & 2 deletions man/DF.to.long.Rd

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

5 changes: 3 additions & 2 deletions man/DF.to.longDT.Rd

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

100 changes: 96 additions & 4 deletions man/Define_sVar.Rd

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

73 changes: 70 additions & 3 deletions man/NetIndClass.Rd

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

2 changes: 1 addition & 1 deletion man/add.action.Rd

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

5 changes: 3 additions & 2 deletions man/doLTCF.Rd

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

10 changes: 8 additions & 2 deletions man/eval.target.Rd

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

3 changes: 1 addition & 2 deletions man/node.Rd

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

Loading