Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRWN-1503 non replicate support #63

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

certara-jcraig
Copy link
Collaborator

@certara-jcraig certara-jcraig commented Feb 6, 2025

To support cases where simulated data is not a replicate of the observed data. [#64]

  • Add optional repl argument in simulated.tidyvpcobj to identify replicate column in simulated data
  • Add data.sim argument in stratify.tidyvpcobj to identify strata in simulated data
  • Change existing non-replicate error checks to warnings

Example usage:

library(data.table)
library(tidyvpc)
library(magrittr)

# Can additionally toggle tidyvpc package specific verbosity
options("tidyvpc.verbose" = TRUE)

obs <- tidyvpc::obs_data[MDV==0]
sim <- tidyvpc::sim_data[MDV==0]
sim$GENDER <- rep(obs$GENDER, nrow(sim) / nrow(obs))

sim_rich <- sim[, {
  ntime_seq <- seq(from = min(TIME),
                   to   = max(TIME),
                   by   = 0.01)
  dv_interp <- approx(x = TIME, y = DV, xout = ntime_seq)$y
    data.table(TIME = ntime_seq,
             DV    = dv_interp,
             GENDER = GENDER[1])
}, by = .(ID, REP)]


vpc <- observed(obs, x = TIME, yobs = DV) %>%
  simulated(sim,
            ysim = DV) %>%
  binning(bin = "jenks", nbins = 5) %>%
  vpcstats()

plot(vpc)

vpc_non_rep <-
  observed(obs, x = TIME, yobs = DV) %>%
  simulated(sim_rich,
            xsim = TIME,
            ysim = DV,
            repl = REP) %>%
  binning(bin = "jenks", nbins = 5) %>%
  vpcstats()

plot(vpc_non_rep)

vpc_non_rep_strat <-
  observed(obs, x = TIME, yobs = DV) %>%
  simulated(sim_rich,
            xsim = TIME,
            ysim = DV,
            repl = REP) %>%
  stratify(~ GENDER, data.sim = sim_rich) %>% #specify data.sim arg 
  binning(bin = "jenks", nbins = 5) %>%
  vpcstats()

plot(vpc_non_rep_strat)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant