R-Code for Power in 2×2 Cross-over [🇷 for BE/BA]
Dear all,
following this post and just out of curiosity I implemented SAS-code by Jones and Kenward (2000)
To quote the beginning of Jones'/Kenward's SAS-Code (which is copyrighted material and therefore not given here; but you can afford buying a book for sure):
Their example (pp 336-337) yields from a within-subject standard deviation of 0.355 in 58 subjects and a point estimate of 1.00 power=90.4%.
Following R-code gives 90.3988%.
The following code reproduces the power-curves for n=8/12/18/24/30/36/40/60 and CV=20% given in Fig.1c by Diletti et al. (1991)
Values calculated by the R-code for n=24 match Diletti et al.'s Fig.1c:
Please note, this code is not validated, but only a toy you can play around with!
With some ambition you can modify the code (essentially varying the point estimate instead of the sample size) in order to match also Diletti et al.'s Fig.2c.
Now it should be only a small step to re-calculate their table of sample sizes...
following this post and just out of curiosity I implemented SAS-code by Jones and Kenward (2000)
[1]
in R (v2.4.1).To quote the beginning of Jones'/Kenward's SAS-Code (which is copyrighted material and therefore not given here; but you can afford buying a book for sure):
/*** WARNING : PROGRAM OFFERED FOR USE WITHOUT ANY GUARANTEES ***/
/*** NO LIABILITY IS ACCEPTED FOR ANY LOSS RESULTING FROM USE OF ***/
/*** THIS SET OF SAS INTRUCTIONS ***/
Their example (pp 336-337) yields from a within-subject standard deviation of 0.355 in 58 subjects and a point estimate of 1.00 power=90.4%.
Following R-code gives 90.3988%.
# significance level
a <- 0.05
# variance of difference of two observations on log scale
# sigmaW = within-subjects standard deviation
sigmaW <- 0.355
s <- sqrt(2)*sigmaW
# total number of subjects (needs to be a multiple of 2)
# for power calculation
n <- 58
# error degrees of freedom for AB/BA crossover with
# n subjects in total
n2 <- n-2
# ratio = mu_T/mu_R
ratio <- 1.00
# calculate power
t1 <- qt(1-a,n2)
t2 <- -t1
nc1 <- sqrt(n)*(log(ratio)-log(0.8))/s
nc2 <- sqrt(n)*(log(ratio)-log(1.25))/s
df <- sqrt(n2)*(nc1-nc2)/(2*t1)
prob1 <- pt(t1,df,nc1)
prob2 <- pt(t2,df,nc2)
answer <- prob2-prob1
power <- answer*100
power
The following code reproduces the power-curves for n=8/12/18/24/30/36/40/60 and CV=20% given in Fig.1c by Diletti et al. (1991)
[2]
a <- 0.05 # alpha
CV <- 0.20 # intra-subject coefficient of variation
# calculate within-subjects standard deviation
# from CV
sigmaW <- sqrt(log(CV^2+1))
s <- sqrt(2)*sigmaW
Theta1 <- 0.80 # lower acceptance limit
Theta2 <- 1/Theta1 # upper acceptance limit
Step <- 0.005 # Interval
ssx <- 0.65 # x-coordinate of sample size labels in %
CVLabel <- paste("CV =",as.character(CV*100),"%" )
# vector of sample sizes
for (n in c(8,12,18,24,30,36,48,60))
{
n2 <- n-2
# vector of ratios from 'Theta1' to 'Theta2', interval 'Step'
assign("ratio",seq(Theta1,Theta2,Step))
t1 <- qt(1-a,n2)
t2 <- -t1
nc1 <- sqrt(n)*(log(ratio)-log(Theta1))/s
nc2 <- sqrt(n)*(log(ratio)-log(Theta2))/s
df <- sqrt(n2)*(nc1-nc2)/(2*t1)
prob1 <- pt(t1,df,nc1)
prob2 <- pt(t2,df,nc2)
power <- prob2-prob1
if (n == 8) # set-up of plot, first curve
{
plot(ratio, power, axes=F, type="l", lwd=2, col=2,
xlim=c(Theta1,Theta2), ylim=c(0,1),
main="2×2 Cross-over", xlab="µT/µR", ylab="Power" )
text(1, 0.4, CVLabel, cex=1.25, adj=0.5 )
axis(1, at=seq(Theta1,Theta2,Step*10),
labels=seq(Theta1,Theta2,Step*10), pos=0 )
axis(2, at=seq(0,1,0.1), labels=seq(0,1,0.1), las=1 )
abline(h=0.05, col = "black", lty = "dotted" )
abline(h=seq(0.6,1,0.1), col = "black", lty = "dotted" )
abline(v=seq(Theta1,Theta2,Step*10), col = "black", lty = "dotted" )
box()
}
else # add curves to plot
lines(ratio, power, lwd=2, col=2 )
if (ratio[as.integer(length(ratio)*ssx)] )
text(ratio[as.integer(length(ratio)*ssx)],
power[as.integer(length(ratio)*ssx)], n, adj=0.5 )
}
Values calculated by the R-code for n=24 match Diletti et al.'s Fig.1c:
+------+-------+
| PE | Power |
+------+-------+
| 0.85 | 28.16 |
| 0.90 | 64.08 |
| 0.95 | 89.19 |
| 1.00 | 96.28 |
| 1.05 | 89.90 |
| 1.10 | 70.02 |
| 1.15 | 41.92 |
| 1.20 | 18.30 |
+------+-------+
Please note, this code is not validated, but only a toy you can play around with!
With some ambition you can modify the code (essentially varying the point estimate instead of the sample size) in order to match also Diletti et al.'s Fig.2c.
Now it should be only a small step to re-calculate their table of sample sizes...
- Jones B and MG Kenward
Design and Analysis of Cross-Over Trials
Chapman & Hall/CRC, Boca Raton, (2nd Edition 2000)
- Diletti E, Hauschke D and VW Steinijans
Sample size determination for bioequivalence assessment by means of confidence intervals
Int J Clin Pharm Ther Toxicol 29/1, 1-8 (1991)
—
Dif-tor heh smusma 🖖🏼 Довге життя Україна!
Helmut Schütz
The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
Dif-tor heh smusma 🖖🏼 Довге життя Україна!
Helmut Schütz
The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
Complete thread:
- R-Code for Power in 2×2 Cross-overHelmut 2006-12-28 21:33 [🇷 for BE/BA]
- Power in Diletti's sample size table Helmut 2007-01-01 23:59
- Approximate Power Helmut 2007-01-06 15:17
- Power Calculation for replicate crossover design mathews 2008-04-03 13:19
- Power Calculation for replicate crossover design Helmut 2008-04-03 13:49
- Power Calculation for replicate crossover design mathews 2008-04-04 13:21
- Power Calculation for replicate crossover design Helmut 2008-04-03 13:49
- Exact Power Helmut 2009-09-25 19:20
- Exact Power ElMaestro 2009-09-27 23:27
- Software validation Helmut 2009-09-28 15:21
- All the important answers are here! ElMaestro 2009-09-28 19:12
- All the important answers are here! Helmut 2009-09-28 19:52
- All the important answers are here! ElMaestro 2009-09-28 20:18
- All the important answers are here! yjlee168 2009-09-28 21:30
- All the important answers are here! Helmut 2009-09-28 23:18
- 42! SASophylistic power oracle d_labes 2009-09-29 13:37
- Al Gore Rhythms Helmut 2009-09-29 14:52
- Al Gore Rhythms ElMaestro 2009-09-29 18:14
- Al Gore Rhythms yjlee168 2009-09-29 23:55
- Al Gore Rhythms Helmut 2009-09-29 14:52
- 42! SASophylistic power oracle d_labes 2009-09-29 13:37
- All the important answers are here! yjlee168 2009-09-29 23:49
- All the important answers are here! Helmut 2009-09-28 23:18
- All the important answers are here! Helmut 2009-09-28 19:52
- All the important answers are here! ElMaestro 2009-09-28 19:12
- Software validation Helmut 2009-09-28 15:21
- Exact Power ElMaestro 2009-09-27 23:27
- Power Calculation for replicate crossover design mathews 2008-04-03 13:19
- Approximate Power Helmut 2007-01-06 15:17
- R-Code for Power in 2×2 Cross-over KDA 2019-01-23 04:24
- R-Code for Power in 2×2 Cross-over Ohlbe 2019-01-27 18:24
- R-Code for Power in 2×2 Cross-over Brus 2021-12-02 15:00
- R-Code for Power in 2×2 Cross-over ElMaestro 2021-12-02 15:15
- R-Code for Power in 2×2 Cross-over Helmut 2021-12-02 17:30
- R-Code for Power in 2×2 Cross-over Helmut 2021-12-02 16:57
- R-Code for Power in 2×2 Cross-over ElMaestro 2021-12-02 15:15
- Power in Diletti's sample size table Helmut 2007-01-01 23:59