Shuanghe
★★  

Spain,
2025-12-14 18:35
(171 d 10:16 ago)

Posting: # 24532
Views: 2,498
 

 Simulation of inter-subject variability in replicate study [RSABE / ABEL]

Hi all,

I have several questions regarding the simulation of the inter-subject variability in the 2x2x4 replicate study. It's a long post, so let's use concrete example so it's easier to discuss.

Imagine I need to simulate a 2x2x4 study with n = 24 subjects (so 12 for TRTR and 12 for RTRT). The mean Cmax of test and reference is 100 ng/mL, intra-subject variability for test is sd.t = 0.2 and for reference is sd.r = 0.1. Here the variability is expressed as standard deviation (SD), not CV.
cmax.r <- rnorm(48, mean = log(100), sd = 0.1)
cmax.t <- rnorm(48, mean = log(100), sd = 0.2)

This will simulate 48 Cmax values for T and R. With a bit coding, we can generate TRTR/RTRT sequences and randomly assign 24 subjects to those sequences with corresponding period and Cmax values. We can back-calculate the within-subject variability of T and R either using EMA's method (e.g., using only reference data for within-subject variability of reference as described in Clinical pharmacology and pharmacokinetics: questions and answers.) or FDA's method (e.g., described in the appendix C of the BE guidance). Easy enough, so far so good.

Q1: In this case, based on those population parameters described above, what is the expected inter-subject variability? Is there mathematical formula to get the between-subject SD of T and R? or pooled SD?

Q2: If there's no mathematical derivation for between-subject SD, I think that we can estimate them using R. But how?

One way that I am thinking is to use EMA's method, removing test product from the data set and do ANOVA as described in EMA's Q&A.
m.ref <- anova(lm(log(cmax) ~ sequence + subject %in% sequence + period, data = d.ref))
The code above should give us the within and between-subject SD of reference with swr = sqrt(MSResidual) and sbr = sqrt((MSSubject(seq) - MSResidual)/2), where swr and sbr are within-and between-SD of reference, respectively. Similarly we can do it for the test. And in case MSSubject(seq) < MSResidual, we can try what Detlew described in another post to avoid negative variance.

Q3: Is this a correct approach? If not, what's the correct one?

Now comes to simulation. Imagine in addition to what I described above for simulating Cmax of T and R with mean value of 100 ng/mL, sd.t = 0.2 and sd.r = 0.1, I also want to introduce between-subject SD for T and R, say sd.bt = 0.4 and sd.br = 0.2, where sd.bt and sd.br are between-subject SD for T and R.

Q4: How do we do it?

I saw that Helmut did it as follows in one of his articles (Helmut, it's Simulations 101 but the link causes Error 406 :confused:.) for simulating the 2x2x2 crossover study.
T  <- rnorm(n = n, mean = log(theta0), sd = sd)
R  <- rnorm(n = n, mean = 0, sd = sd)
TR <- rnorm(n = n, mean = 0, sd = sd.b)
T  <- T + TR
R  <- R + TR

where sd.b is the between-subject SD if I understood it correctly.

However, when I tried to do it similarly for 2x2x4 as follows and back-calculate the within and between SD, the results doesn't match expectation at all because the between-subject SD fromANOVA is extremely small, instead of around the expected values of 0.2 or 0.4.
cmax.r <- rnorm(48, mean = log(100), sd = 0.1)
cmax.t <- rnorm(48, mean = log(100), sd = 0.2)
cmax.br <- rnorm(48, mean = log(100), sd = 0.2) # for reference
cmax.bt <- rnorm(48, mean = log(100), sd = 0.4) # for test
# I need the concentration in original scale, not log-transformed
cmax.r <- exp(cmax.r + cmax.br)
cmax.t <- exp(cmax.t + cmax.bt)

Q5: What went wrong? Should the mean value for between-subject SD of T and R always 0 instead of using the same value as T and R?


Edit: Category changed. [Helmut]

All the best,
Shuanghe
mittyri
★★  

Russia,
2025-12-18 15:07
(167 d 13:44 ago)

@ Shuanghe
Posting: # 24534
Views: 2,003
 

 Simulation of inter-subject variability in replicate study

Dear Shuanghe!

I started to write my answer, then pasted your question to ChatGPT... I realized that its detailed answer is much better than anything I can do :angry:. But I don't want to spread AI here.
So I just retain the correct code for simulation. It is based on genius Detlew's code.
Just for your 1st question - betweensubject variability is (theoretically) 0.

library(PowerTOST)

set.seed(1234)
seqs  <- c("TRTR", "RTRT")
nseq  <- c(12, 12)
muR   <- log(100)
ldiff <- 0 # log(GMR)
s2wT  <- 0.2^2
s2wR  <- 0.1^2
# see Detlew's comment https://github.com/Detlew/PowerTOST/blob/master/R/simulate_replicate_fixed.R
dat <- PowerTOST:::prep_data2(seqs = seqs,
                              nseq = nseq,
                              muR = muR,
                              ldiff = ldiff,
                              s2wT = s2wT,
                              s2wR = s2wR)

# BSW
sd.b      <- 0.3
n.subj    <- length(unique(dat$subject))
b.subj    <- rnorm(n.subj, 0, sd.b)
dat$logCmax <- dat$logval + b.subj[dat$subject]
dat$Cmax     <- exp(dat$logCmax)

# Check
d.ref <- subset(dat, tmt == "R")
d.ref$subject <- as.factor(d.ref$subject)
d.ref$sequence <- as.factor(d.ref$sequence)
d.ref$period <- as.factor(d.ref$period)
d.ref$tmt <- as.factor(d.ref$tmt)

m.ref  <- lm(logCmax ~ sequence + subject %in% sequence + period, data = d.ref)
aov.ref <- anova(m.ref)
aov.ref
MS_res <- aov.ref["Residuals", "Mean Sq"]
MS_subj <- aov.ref["sequence:subject", "Mean Sq"]

s2_wR_hat <- MS_res
s2_bR_hat <- (MS_subj - MS_res) / 2

sqrt(s2_wR_hat)
sqrt(s2_bR_hat)

Kind regards,
Mittyri
Shuanghe
★★  

Spain,
2025-12-30 11:22
(155 d 17:28 ago)

@ mittyri
Posting: # 24543
Views: 1,803
 

 Simulation of inter-subject variability in replicate study

Dear mittyri!

Many thanks! I've been using PowerTOST for quite long time but haven't noticed the simulation functions. I must've been :sleeping:

You are right, the between subject variability is effectively zero in my original code. And I also asked chatGPT, it did provide quite detailed answer. It seems that AI is getting better every day.

Your mention of chatGPT reminds me that we still haven't been able to reproduce the FDA's unscaled ABE using the following SAS code, which was also summarised in one of Helmut's post. Maybe we can ask chatGPT to come up with R code to reproduce the result from SAS? I'll play it when I got some time and report back here.
PROC MIXED;                                 
  CLASSES SEQ SUBJ PER TRT;                   
  MODEL Y = SEQ PER TRT/ DDFM = SATTERTH;     
  RANDOM TRT/TYPE = FA0(2) SUB = SUBJ G;     
  REPEATED/GRP=TRT SUB = SUBJ;               
  ESTIMATE 'T vs. R' TRT 1 -1/CL ALPHA = 0.1;

All the best,
Shuanghe
Helmut
★★★
avatar
Homepage
Vienna, Austria,
2025-12-30 12:11
(155 d 16:40 ago)

@ Shuanghe
Posting: # 24544
Views: 1,808
 

 ABE for partial replicate design acc. to the FDA

Hi Shuanghe,

❝ I must've been :sleeping:

You are awake! This function is undocumented. Thus you don’t find it in the man-pages – only in the sources on GitHub: https://github.com/Detlew/PowerTOST/tree/master/R.

❝ Your mention of chatGPT reminds me that we still haven't been able to reproduce the FDA's unscaled ABE using the […] SAS code, which was also summarised in one of Helmut's post.

It would be interesting whether it would be possible with Pumas* for Julia. At least it is claimed in this tutorial. Perhaps useful as well:
https://github.com/camontefusco/pumas-bioequivalence-course-project-reference-scaling-and-narrow-therapeutic-index-drugs
Pumas is free for Academic Research & Training. Don’t know the costs of a commercial license.

❝ Maybe we can ask chatGPT to come up with R code to reproduce the result from SAS? I'll play it when I got some time and report back here.

Good luck!


  • Rackauckas C, Ma Y, Noack A, Dixit V, Mogensen PK, Byrne S, Maddhashiya S, Bayoán Santiago Cal­de­rón J, Ny­berg J, Gobburu JVS, Ivaturi V. Accelerated Predictive Healthcare Analytics with Pumas, a High Per­for­mance Phar­ma­ceu­ti­cal Modeling and Simulation Platform. Nov 30, 2020. doi:10.1101/2020.11.28.402297. Preprint bioRxiv 2020.11.28.40229.

Dif-tor heh smusma 🖖🏼 Довге життя Україна! [image]
Helmut Schütz
[image]

The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
Nirali
★    

India,
2026-02-18 13:04
(105 d 15:47 ago)

(edited on 2026-02-19 04:57)
@ Helmut
Posting: # 24576
Views: 1,065
 

 ABE for partial replicate design acc. to the FDA

Hello Helmut,
Have you got a chance to work on it later?
Have a great Day:-)

Nirali Mehta
(PHARMA-STATS)
UA Flag
Activity
 Admin contact
23,653 posts in 4,991 threads, 1,571 registered users;
540 visitors (0 registered, 540 guests [including 19 identified bots]).
Forum time: 05:51 CEST (Europe/Vienna)

I’m all in favor of the democratic principle
that one idiot is as good as one genius, but I draw the line
when someone takes the next step and concludes
that two idiots are better than one genius.    Leo Szilard

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5