Dear Statalist users,
With thanks to Kit Baum, I would like to introduce a new package mixedpower. As the title suggests, the synonymous program calculates power and sample size analytically for linear mixed models, typically for use in planning of an RCT with longitudinal continuous outcomes.
There is flexibility in specifying the treatment effects, even allowing user-specified functions of the schedule time list (which needn't actually represent time), as well as the random effects or within-subject error structure. These aspects can even differ between treatment and control groups.
All variance parameter inputs may be entered manually or instead 'automatically' read-in from a 'suitable' mixed model in memory, saving on both time and risk of a mistake.
One may calculate power/sample size accounting for both a) the amount of longitudinal data collected at a given timepoint due to staggered recruitment and b) dropout, simultaneously. Dropout rates may differ between control and treatment groups, as can the allocation ratio.
One may also estimate power under situation where the nature of the treatment effect is mis-specified. For example, what is the power when you assume a proportionate slope effect for the treatment group in the analysis model, if the true treatment effect in fact changed non-linearly over time. mixedpower will also provide the subsequent slope effect estimate.
Additional programs in the package calculate power and sample size for 1) a multivariate mixed model (mvmixedpower) when you might want to synthesis multiple continuous outcomes to increase power, especially for an interim analysis and 2) a mixed model for 'directly measured' difference data (dmmixedpower). These programs come with less features.
The help files are unapologetically extensive and come with lots of examples. Here are some below:
1) First load Stata's pig dataset, and create a fake treatment group, as well as set week to starting at time zero. If we fit an unstructured marginal model, sometimes known as a mixed model for repeated measures (MMRM) on the first 5 measures (if week<=4) we may calculate power for a similarly scheduled trial but with n=100, testing just the final difference effect (which equals 2) whilst automatically loading all the variance parameters.
This will give the following output, including the mixed model syntax for the implied analysis.
2) An example emphasising the generalisability of mixedpower by recreating Stata's own power command for a cluster-randomised trial (output supressed):
3) An example incorporating partial follow-up due to both staggered recruitment and dropout. Note, the output will also give the number of subjects reaching each visit of the schedule list:
with output...
4) An example employing the user-supplied functions, where linear slopes are assumed for both groups but in fact the disease progression shows an 'early decline' with a long plateau from about year 2 to the end and the treatment effect is actually proportional to this complex function of time. This example recreates a result from a simulation study by Morgan et al**
Output:
Please feel free to ask questions about the package, either here or by email (including any bugs spotted).
Matthew Burnell
MRC Centre of Research Excellence in Clinical Trial Innovation
University College London
London, UK
[email protected]
** Katy E. Morgan, Ian R. White, Chris Frost. How important is the linearity assumption in a sample size calculation for a randomised controlled trial where treatment is anticipated to affect a rate of change? BMC Medical Research Methodology (2023) 23:274 https://doi.org/10.1186/s12874-023-02093-2
With thanks to Kit Baum, I would like to introduce a new package mixedpower. As the title suggests, the synonymous program calculates power and sample size analytically for linear mixed models, typically for use in planning of an RCT with longitudinal continuous outcomes.
Code:
ssc install mixedpower
All variance parameter inputs may be entered manually or instead 'automatically' read-in from a 'suitable' mixed model in memory, saving on both time and risk of a mistake.
One may calculate power/sample size accounting for both a) the amount of longitudinal data collected at a given timepoint due to staggered recruitment and b) dropout, simultaneously. Dropout rates may differ between control and treatment groups, as can the allocation ratio.
One may also estimate power under situation where the nature of the treatment effect is mis-specified. For example, what is the power when you assume a proportionate slope effect for the treatment group in the analysis model, if the true treatment effect in fact changed non-linearly over time. mixedpower will also provide the subsequent slope effect estimate.
Additional programs in the package calculate power and sample size for 1) a multivariate mixed model (mvmixedpower) when you might want to synthesis multiple continuous outcomes to increase power, especially for an interim analysis and 2) a mixed model for 'directly measured' difference data (dmmixedpower). These programs come with less features.
The help files are unapologetically extensive and come with lots of examples. Here are some below:
1) First load Stata's pig dataset, and create a fake treatment group, as well as set week to starting at time zero. If we fit an unstructured marginal model, sometimes known as a mixed model for repeated measures (MMRM) on the first 5 measures (if week<=4) we may calculate power for a similarly scheduled trial but with n=100, testing just the final difference effect (which equals 2) whilst automatically loading all the variance parameters.
Code:
webuse pig , clear gen trt=id>=25 replace week=week-1 mixed weight i.week i.week#1.trt if week<=4 || id: ,nocons resid(unstr, t(week)) reml mixedpower, trtspec(factor) sched(0 1 2 3 4) altcont(factor) diff(0.5(0.5)2) lctest(0 0 0 1) n(100) marginal errxt(auto) nohead
Code:
Mixed model syntax: constraint 1 _b[0.time#1.trt]=0 mixed depvar i.time i.time#1.trt , constraints(1) || id_level2: , nocons resid(unstructured , t(time)) ------------------------------------------------------------------------------------------------------------------------- Calculating power for a 2-level mixed model with factor treatment effect parameterisation: visit schedule = 0 1 2 3 4 treatment effect(s) = 0.5 1 1.5 2 alpha = 0.050 total sample size = 100 n in control arm = 50 n in treatment arm = 50 power = 0.9147
Code:
power twomeans 0 0.4, power(0.9) m1(25) m2(25) sd(2) rho(0.1) kratio(2) mixedpower, schedule(1(1)25) trtspec(intercept) altcont(noslope) difference(0.4) marginal errxt(input(exchangeable 4 0.1)) power(0.9) arat(1 2)
Code:
mixedpower, trtspec(slope) schedule(0 1 2 3 4) diff(0.5) cov(10, 1\1, 2) error(10) n(500) alpha(0.1) strec(0.05 0.1 0.15 0.2 0.4) drop(0.1 0.05 0.05 0.05 0.75)
Code:
-------------------------------------------------------------------------------------------------------------------------
Mixed model syntax:
mixed depvar c.time c.time#1.trt || id_level2: time , cov(unstr) resid(independent , t(time))
-------------------------------------------------------------------------------------------------------------------------
Calculating power for a 2-level mixed model with slope treatment effect parameterisation:
visit schedule = 0 1 2 3 4
treatment effect(s) = 0.5
alpha = 0.100
total sample size = 500
n in control arm = 250
n in treatment arm = 250
power = 0.7718
Table of control and treatment group numbers (rounded) reaching each visit:
| visit 1 visit 2 visit 3 visit 4 visit 5
| time=0 time=1 time=2 time=3 time=4
-----------+-------------------------------------------------
control | 225 191 159 120 75
treatment | 225 191 159 120 75
Code:
mixedpower, trtspec(slope) sched(0(1)5) diff(-0.05) cov(0.5, .0354\.0354, 0.01) error(0.15) n(230) actualcont(user(-5*exp(-2*x)+5)) cbeta(6 0.2) actualtrt(user(-5*exp(-2*x)+5)) nosyn
Code:
Calculating power for a 2-level mixed model with slope treatment effect parameterisation but with actual user treatment effect: visit schedule = 0 1 2 3 4 5 treatment effect(s) = -0.05 alpha = 0.050 total sample size = 230 n in control arm = 115 n in treatment arm = 115 power = 0.5287
Matthew Burnell
MRC Centre of Research Excellence in Clinical Trial Innovation
University College London
London, UK
[email protected]
** Katy E. Morgan, Ian R. White, Chris Frost. How important is the linearity assumption in a sample size calculation for a randomised controlled trial where treatment is anticipated to affect a rate of change? BMC Medical Research Methodology (2023) 23:274 https://doi.org/10.1186/s12874-023-02093-2

Comment