The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Package {LongitudinalEvalue}


Type: Package
Title: Sensitivity Analysis for Unmeasured Confounding in Longitudinal Studies
Version: 0.1.0
Maintainer: Andreas Kristian Pedersen <andreaskpedersen@hotmail.com>
Description: Evaluates the sensitivity of a given association to unmeasured confounding. The package consists of three functions. The first starts a 'shiny' app which assesses how strong a time-invariant confounder needs to be associated with the exposure and outcome to explain away a proposed causal association. The second and third functions simulate a time-dependent confounder over time either using a fit from the qmle() function from the 'yuima' package or directly using the observed effect estimate.
URL: https://andreaskpedersen.shinyapps.io/LongitudinalEvalue/
License: GPL-3
Encoding: UTF-8
LazyData: true
Imports: ggplot2, yuima, methods, np, matrixStats, stats, rlang, zoo
Suggests: knitr, rmarkdown, shiny, bookdown
VignetteBuilder: knitr
Depends: R (≥ 3.5)
Config/roxygen2/version: 8.0.0
NeedsCompilation: no
Packaged: 2026-07-23 16:43:38 UTC; afe2eg
Author: Andreas Kristian Pedersen [aut, cre], Anna Mejldal [ctb], Afsaneh M. Nejad [ctb], Kristian Debrabant [aut], Sören Möller [aut]
Repository: CRAN
Date/Publication: 2026-08-03 18:00:30 UTC

COVID example dataset

Description

The Covidexample dataset is a data frame with 30 observations and 5 variables. It contains daily cumulative incidence data of SARS-CoV-2 infections in November 2020 for municipalities under regional lockdown and comparable municipalities without lockdown.

In addition, the dataset includes a temporal average treatment effect (TATE) for the regional lockdown and a hypothetical average treatment effect (ATE) under the assumption of no unmeasured confounding.

Usage

Covidexample

Format

A data frame with 30 rows and 5 variables:

time

Date of the observation.

incidencelockdown

Cumulative incidence in the lockdown municipalities.

incidencenolockdown

Cumulative incidence in the non-lockdown municipalities.

TATE

Temporal average treatment effect on the absolute scale.

ATE

Hypothetical temporal average treatment effect under no unmeasured confounding.

Details

This dataset includes the daily cumulative incidence of SARS Covid-19 in November 2020 for the municipalities which experienced the regional lockdown and those which did not. It also includes the temporal average treatment of the regional lockdown and the hypothetical averagetreatment effect if a confounder could explain the effect of the regional lockdown

Source

Ege, F. (2024). Short, stringent lockdowns halted SARS-CoV-2 transmissions in Danish municipalities.

Examples

"Covidexample"

Sensitivity analysis for unmeasured time-invariant confounders

Description

A launcher for the LongitudinalEvalueApp.

Usage

LongitudinalEvalueApp()

Details

The app is also available online at https://andreaskpedersen.shinyapps.io/LongitudinalEvalue/

The Shiny app contains the following inputs:

Value

Launches the Shiny application. The app allows users to explore and download sensitivity curves describing the strength of association that an unmeasured time-invariant confounder would need to have with both exposure and outcome to fully explain the observed causal effect.

The exposure–confounder association is modeled on a ratio scale, while the confounder–outcome association is expressed on the same scale as the TATE.

Examples

if(interactive()){
LongitudinalEvalueApp()
}


Simulating a time-varying confounder (non-parametric approach)

Description

The SDEconfounderNonparametric is a non-parametric method simulate the confounder which could explain the discrepancy between the observed and causal average treatment. It has a similar syntax to SDEconfounderYuima1d but utilizes the observed data instead of of the fit from qmle from the yuima package

Usage

SDEconfounderNonparametric(
  Observed,
  ATE,
  time,
  EFXU,
  EFUY,
  custom_time = NULL,
  bayesianXU = "No",
  bayesianUY = "No",
  nbayes = 100,
  priors = list(sigmaUY = 1, sigmaXU = 1),
  alpha = 0.05,
  bw_drift = NULL,
  bw_diffusion = NULL,
  bwmethod_drift = "cv.aic",
  bwmethod_diffusion = "cv.aic",
  scheme = "no",
  stiff = "no",
  tol = 1e-08,
  iteration_solver = 5,
  frozenJacobi = TRUE,
  seed = NULL
)

Arguments

Observed

A data frame containing the observed data (excluding the time variable).

ATE

The true average treatment effect on the absolute scale after adjusting for the confounder. Under no confounding, this value equals zero.

time

A vector indicating the time points at which the confounder should be simulated.

EFXU

The association between the confounder and exposure on a ratio scale. Must be a scalar.

EFUY

The association between the confounder and the outcome difference between exposure groups on an absolute scale. Must be a scalar.

custom_time

Optional specification of a custom time scale.

bayesianXU

Logical; if "Yes, the association between confounder and exposure is treated as Bayesian. Default is "No".

bayesianUY

Logical; if "Yes", the association between confounder and outcome is treated as Bayesian. Default is "No".

nbayes

Number of resamples used to approximate the posterior distribution.

priors

A list containing sigmaUY and sigmaXU, specifying the prior variability of the corresponding association parameters.

alpha

Significance level for credibility intervals. Default is 0.05 (corresponding to a 95% credibility interval).

bw_drift

Bandwidth used for kernel density estimation of the drift function.

bw_diffusion

Bandwidth used for kernel density estimation of the diffusion function.

bwmethod_drift

Method used to select the bandwidth for drift estimation. Default is "cv.aic". See np::npreg for details.

bwmethod_diffusion

Method used to select the bandwidth for diffusion estimation. Default is "cv.aic". See np::npreg for details.

scheme

Numerical scheme used to simulate the confounder process. Options are: "no" (data-based, default), "Euler-Maruyama", and "TamedEuler".

stiff

Logical; indicates whether the underlying stochastic differential equation is stiff. If TRUE, implicit schemes are used; otherwise explicit schemes are applied.

tol

The tolerance used in the Newton solver for implicit schemes. Default is 1e-8.

iteration_solver

Number of iterations used in the implicit scheme solver. Default is 5.

frozenJacobi

Logical; if TRUE, the Jacobian matrix in the iterative solver is kept fixed across iterations. Default is TRUE.

seed

Random seed used to ensure reproducibility of the simulation.

Value

A list of two data frames:

Note

The kernel regression predictions are conditional on the observed values of the TATE. This is because we condition on the dataset, where the most expected value of the dataset is the observed value

References

Kloeden, P. E., & Platen, E. (1992). Numerical Solution of Stochastic Differential Equations (1st ed.).

Hutzenthaler, M., Jentzen, A., & Kloeden, P. E. Strong convergence of an explicit numerical method for SDEs with nonglobally Lipschitz continuous coefficients. arXiv preprint.

Examples

## Simulate and plot a latent time-varying confounder where the two 
## assocations from the confounder are both 1.5 and the bandwidth for the 
## kernel regression is based on  least-squares cross-validation and the 
## scheme is based on the explicit Euler-Maruyama scheme.
U_t <- SDEconfounderNonparametric(
  Covidexample$TATE,
  ATE = Covidexample$ATE,
  time = Covidexample$time,
  EFXU = 1.5,
  EFUY = 1.5,
  bwmethod_drift = "cv.ls",
  bwmethod_diffusion = "cv.ls",
  scheme = "Euler-Maruyama"
)
plot(U_t)


S4 class for SDEconfounderResult used by SDEconfounderNonparametric

Description

S4 class for SDEconfounderResult used by SDEconfounderNonparametric

Slots

data

A data frame containing simulated trajectories

trajectories

A matrix of simulated paths

hasCI

Logical indicating whether confidence intervals are included


S4 class for SDEconfounderResultYuima used by SDEconfounderYuima1d

Description

S4 class for SDEconfounderResultYuima used by SDEconfounderYuima1d

Slots

data

A data frame containing simulated trajectories


Simulating time-varying confounder parametrically

Description

SDEconfounderYuima1d uses the fit from the qmle function in the yuima package to simulate the confounder which could explain the discrepancy between the observed and causal average treat ment.

Usage

SDEconfounderYuima1d(
  fit,
  time,
  EFXU,
  EFUY,
  bayesianXU = "No",
  bayesianUY = "No",
  nbayes = 200,
  initial.value = 0,
  priors = list(sigmaUY = 1, sigmaXU = 1),
  alpha = 0.05
)

Arguments

fit

A fitted SDE model object returned by qmle from the yuima package.

time

A vector of time points at which the confounder should be simulated.

EFXU

The association between the confounder and exposure on a ratio scale. Must be a scalar.

EFUY

The association between the confounder and the outcome difference between exposure groups on an absolute scale. Only scalar are accepted

bayesianXU

Logical; if "Yes", the confounder–exposure association is treated as Bayesian. Default is "No". The prior is based on a lognormal distribution.

bayesianUY

Logical; if "Yes", the confounder–outcome association is treated as Bayesian. Default is "No". The prior is based on a normal distribution.

nbayes

Number of resamples used to approximate the posterior distribution.

initial.value

Initial value of the confounder process.

priors

A list containing sigmaUY and sigmaXU, specifying prior variability for the corresponding association parameters.

alpha

Significance level for credibility intervals. Default is 0.05 (corresponding to a 95% credibility interval).

Value

A data frame containing the simulated confounder trajectory along with corresponding 100(1 - \alpha)\% credibility intervals.

Note

The simulation is based on parameter estimates obtained from the qmle function in the yuima package.

References

Iacus, S. M. (2018). Simulation and Inference for Stochastic Processes with YUIMA: A Comprehensive R Framework for SDEs and Other Stochastic Processes (1st ed.). Springer Nature. https://doi.org/10.1007/978-3-319-55569-0

Examples

## Simulate and plot the trajectory of the unmeasured confounder based on the
## fit object from the qmle function from the yuima package.
## For information on how to use the qmle-function we refer to the 
## yuima-package, Iacus, S. M. (2018) and the accompanying vignette for this 
## package.
Delta<-1/3
Covidexample$t<-1:30
mod<-yuima::setModel(drift="a/TATE+c*TATE", diffusion="sigma", 
state.var="TATE", time.var = "t", 
             solve.var = "TATE",xinit = 5.425966)
model<-yuima::setYuima(model=mod, 
data=yuima::setData(zoo::zoo(Covidexample$TATE, order.by = Covidexample$t),
                                       delta=Delta))
fit <- yuima::qmle(model,start = list(a=-5,c = 5,sigma = 0.2),
           lower = list(a=-10,c = -10,sigma = 0), 
           upper = list(a=0,c = 10,sigma =1))

U_t <- SDEconfounderYuima1d(
  fit,
  time = Covidexample$time,
  EFXU = 2,
  EFUY = 1,
  alpha = 0.05
)
plot(U_t)


Plot method for SDEconfounderNonparametric

Description

Plot method for SDEconfounderNonparametric

Usage

## S4 method for signature 'SDEconfounderResult,ANY'
plot(x)

Arguments

x

an object from SDEconfounderNonparametric

Value

A ggplot object showing the confounder trajectory with corresponding credibility intervals if they are specified.


Plot method for SDEconfounderYuima1d

Description

Plot method for SDEconfounderYuima1d

Usage

## S4 method for signature 'SDEconfounderResultYuima,ANY'
plot(x)

Arguments

x

an object from SDEconfounderYuima1d

Value

A ggplot object showing the confounder trajectory with corresponding credibility intervals if they are specified.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.