Skip to content

DRWN-1503 non replicate support#63

Merged
certara-jcraig merged 6 commits intomasterfrom
drwn_1503_non_replicate
Mar 21, 2025
Merged

DRWN-1503 non replicate support#63
certara-jcraig merged 6 commits intomasterfrom
drwn_1503_non_replicate

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
  • Both binning() and binless() are supported

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)

@certara-jcraig certara-jcraig marked this pull request as ready for review March 21, 2025 19:20
@certara-jcraig certara-jcraig merged commit 449fe3f into master Mar 21, 2025
4 checks passed
@certara-jcraig certara-jcraig deleted the drwn_1503_non_replicate branch March 21, 2025 19:28
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