Implications of Interactions in Treatment Comparisons

Transportability of treatment effect estimates depends on the nature of interactions. In the absence of interactions, an effect estimated on a highly selected sample will apply to a much different population. In an observational study, the corresponding condition is that there need be no overlap in the baseline distribution of non-interacting factors. When there is an interaction, one can live with only a small to moderate amount of overlap in characteristics (between randomized vs. population target or between characteristics of treated vs. non-treated patients in an observational study) if the interaction is of a simple form. With more overlap, interactions can be complex (if modeled) and results from analysis of the sample will allow estimation of treatment effect in a different population. In the absence of significant overlap, confidence bands allowing for interaction properly inform the researcher about uncertainties in treatment effects.

Randomized clinical trials do not require representative patients; they require representative treatment effects. Generalizability of randomized trial findings for relative efficacy comes from one of three things: (1) true absence of interactions, (2) interacting factors have a similar distribution in the RCT as in the target population, or (3) the RCT sample has enough representation of the distribution of interacting factors to allow them to be modeled and used to estimate treatment effects in target patients, and the researcher knows to include these interactions in her model.

Note: For shaded boxes marked with ⮩ click on the box to view the associated text.

Table of Contents ⮩

Background

It is a commonly held belief that clinical trials, to provide treatment effects that are generalizable to a population, must use a sample that reflects that population’s characteristics. The confusion stems from the fact that if one were interested in estimating an average outcome for patients given treatment A, one would need a random sample from the target population. But clinical trials are not designed to estimate absolutes; they are designed to estimate differences as discussed further here. These differences, when measured on a scale for which treatment differences are allowed mathematically to be constant (e.g., difference in means, odds ratios, hazard ratios), show remarkable constancy as judged by a large number of published forest plots. What would make a treatment estimate (relative efficacy) not be transportable to another population? A requirement for non-generalizability is the existence of interactions with treatment such that the interacting factors have a distribution in the sample that is much different from the distribution in the population.

A related problem is the issue of overlap in observational studies. Researchers are taught that non-overlap makes observational treatment comparisons impossible. This is only true when the characteristic whose distributions don’t overlap between treatment groups interacts with treatment. The purpose of this article is to explore interactions in these contexts.

As a side note, if there is an interaction between treatment and a covariate, standard propensity score analysis will completely miss it.

For the following I assume that there is at most one variable (patient age) interacting with treatment effect. The data generating and analysis models are logistic models containing only age and treatment. I also assume that the goal is to assess efficacy isolated from net clinical benefit, e.g., we are not taking side effects into account.

Situations addressed below come from the following 2 × 2 × 2 × 3 combinations:

  • randomized vs. observational study
  • true data generating process has no interaction with age vs. has a linear interaction
  • overlap in ages between RCT sample and target population (or between treatments in an observational study) is completely absent vs. partial overlap in the age distribution
  • fitted model is linear with no interaction, has a linear interaction, or has a spline function of age interacting with treatment

I’ll explore what happens when interaction should be included in a model but is omitted, when an interaction is not needed but is included in the model, and when the interaction is simple but is allowed to be complex.

Generalizability of Randomized Clinical Trials

When the outcome generating process in a randomized clinical trial (RCT) is such that treatment does not interact with any baseline patient characteristic over the range of characteristics seen in the union of the RCT and the population, the estimate of relative efficacy (e.g., odds ratio) of treatment applies to every patient in the population. In addition to computing patient-specific odds ratios (ORs), one can easily compute patient-specific absolute risk reductions from treatment as shown here. If one allows for needless interaction terms, it is possible to get poor extrapolation of treatment benefit in unrepresented patient groups, unless the estimated interaction effects are very small (not guaranteed until the sample size is very large).

True Model Has No Treatment Interactions

Estimation of Treatment Effect in Population With No Overlap

As an example, consider a simulated study of about 2500 patients with a binary outcome where the model contains only age and treatment, the age effect is linear, and there is no interaction. The following R code simulates the data from a hypothetical population, fits a binary logistic model, and displays estimated log odds of outcome vs. age and treatment (left panel) and the estimated age-specific treatment effect (right panel), along with the true population values for both panels over the whole range of age. The RCT excluded those with age < 50 but the target population is exactly those patients. Tick marks on fitted curves display treatment-specific raw data spike histograms.

The original age range is 13.3 - 88.1 in 5000 subjects, and the clinical trial includes 2461 of the subjects.

Age distributions in the target population as compared to the RCT sample are shown below.

No-Interaction Model ⮩

Model Without Interaction

This is the correct model.
Logistic Regression Model
 lrm(formula = y ~ tx + age, data = d)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 2539    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2461LR χ2 211.90R2 0.117C 0.679
0 1735d.f. 2g 0.773Dxy 0.357
1 726Pr(>χ2) <0.0001gr 2.167γ 0.357
max |∂log L/∂β| 2×10-7gp 0.150τa 0.149
Brier 0.190
βS.E.Wald ZPr(>|Z|)
Intercept -4.3508 0.4387-9.92<0.0001
tx=b -1.0992 0.0959-11.46<0.0001
age  0.0674 0.00749.05<0.0001
Wald Statistics for y
χ2d.f.P
tx131.301<0.0001
age81.951<0.0001
TOTAL189.632<0.0001

Extrapolation to the younger population is fine even with no younger patients in the RCT. Confidence bands are computed under the assumption of an additive linear age effect.



Linear Interaction Model ⮩

Model With Linear Interaction

This model included an unnecessary linear interaction term.
Logistic Regression Model
 lrm(formula = y ~ tx * age, data = d)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 2539    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2461LR χ2 212.02R2 0.117C 0.679
0 1735d.f. 3g 0.778Dxy 0.357
1 726Pr(>χ2) <0.0001gr 2.176γ 0.357
max |∂log L/∂β| 5×10-6gp 0.150τa 0.149
Brier 0.190
βS.E.Wald ZPr(>|Z|)
Intercept -4.2193 0.5852-7.21<0.0001
tx=b -1.3998 0.8939-1.570.1174
age  0.0652 0.01006.53<0.0001
tx=b × age  0.0051 0.01500.340.7351
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)131.112<0.0001
All Interactions0.1110.7351
age (Factor+Higher Order Factors)82.192<0.0001
All Interactions0.1110.7351
tx × age (Factor+Higher Order Factors)0.1110.7351
TOTAL188.873<0.0001

Note that the close-to-zero estimated interaction in the trial sample led to an appropriate extrapolation to the target population of age < 50, with the confidence bands getting wider.

Now see what happens when age is unnecessarily allowed to have a nonlinear non-additive effect, by fitting a model that is quadratic in age interacting with treatment.



Spline Interaction Model ⮩

Model with Spline Interaction

This model included unnecessary linear and nonlinear interaction terms.
Logistic Regression Model
 lrm(formula = form, data = d, tol = 1e-12)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 2539    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2461LR χ2 214.13R2 0.119C 0.679
0 1735d.f. 7g 0.771Dxy 0.358
1 726Pr(>χ2) <0.0001gr 2.162γ 0.358
max |∂log L/∂β| 2×10-5gp 0.149τa 0.149
Brier 0.190
βS.E.Wald ZPr(>|Z|)
Intercept -3.0988 1.2779-2.420.0153
tx=b -1.3609 2.0910-0.650.5151
age  0.0445 0.02311.930.0542
age'  0.2124 0.22130.960.3372
age'' -0.4384 0.4906-0.890.3716
tx=b × age  0.0043 0.03760.110.9087
tx=b × age'  0.0067 0.31360.020.9829
tx=b × age'' -0.0141 0.6574-0.020.9829
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)131.334<0.0001
All Interactions0.1130.9910
age (Factor+Higher Order Factors)85.266<0.0001
All Interactions0.1130.9910
Nonlinear (Factor+Higher Order Factors)2.1140.7151
tx × age (Factor+Higher Order Factors)0.1130.9910
Nonlinear0.0020.9998
Nonlinear Interaction : f(A,B) vs. AB0.0020.9998
TOTAL NONLINEAR2.1140.7151
TOTAL NONLINEAR + INTERACTION2.2350.8162
TOTAL190.787<0.0001

By allowing not only an unnecessary interaction but also allowing the interaction to be nonlinear, when the predicted values are for a region completely outside the sample data, the extrapolation is still reasonable but the (honest) confidence intervals are much wider. We don’t know much at all about the relative treatment effect with age < 50 when we allowed the two treatments to have differently shaped age effects in the trial data. A Bayesian model that put a skeptical prior on either the nonlinear or the interaction effect would have credible intervals that are not so wide on the left.



RCT Sample Partially Overlaps with Target Population

Instead of having non-overlapping age distributions between the RCT sample and the target population, let’s include screened patients with probabilities that are functions of age as shown in the first graph below. Then again consider the simplest logistic model.

The original age range is 13.3 - 88.1 in 5000 subjects, and the clinical trial includes 3556 of the subjects.

Age distributions in the target population as compared to the RCT sample are shown below.

No-Interaction Model ⮩

Model Without Interaction

This is the correct model.
Logistic Regression Model
 lrm(formula = y ~ tx + age, data = d)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 1444    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3556LR χ2 329.69R2 0.131C 0.697
0 2658d.f. 2g 0.856Dxy 0.394
1 898Pr(>χ2) <0.0001gr 2.353γ 0.394
max |∂log L/∂β| 4×10-12gp 0.148τa 0.149
Brier 0.171
βS.E.Wald ZPr(>|Z|)
Intercept -4.4121 0.2941-15.00<0.0001
tx=b -1.0470 0.0846-12.38<0.0001
age  0.0682 0.005213.04<0.0001
Wald Statistics for y
χ2d.f.P
tx153.171<0.0001
age169.921<0.0001
TOTAL286.932<0.0001



Linear Interaction Model ⮩

Model With Linear Interaction

This model included an unnecessary linear interaction term.
Logistic Regression Model
 lrm(formula = y ~ tx * age, data = d)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 1444    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3556LR χ2 330.73R2 0.131C 0.697
0 2658d.f. 3g 0.840Dxy 0.394
1 898Pr(>χ2) <0.0001gr 2.317γ 0.394
max |∂log L/∂β| 6×10-12gp 0.147τa 0.149
Brier 0.171
βS.E.Wald ZPr(>|Z|)
Intercept -4.6606 0.3849-12.11<0.0001
tx=b -0.4360 0.6056-0.720.4715
age  0.0726 0.006910.56<0.0001
tx=b × age -0.0108 0.0106-1.020.3089
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)154.982<0.0001
All Interactions1.0410.3089
age (Factor+Higher Order Factors)169.902<0.0001
All Interactions1.0410.3089
tx × age (Factor+Higher Order Factors)1.0410.3089
TOTAL292.053<0.0001



Spline Interaction Model ⮩

Model with Spline Interaction

This model included unnecessary linear and nonlinear interaction terms.
Logistic Regression Model
 lrm(formula = form, data = d, tol = 1e-12)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 1444    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3556LR χ2 333.43R2 0.132C 0.697
0 2658d.f. 7g 0.834Dxy 0.395
1 898Pr(>χ2) <0.0001gr 2.302γ 0.395
max |∂log L/∂β| 2×10-11gp 0.149τa 0.149
Brier 0.171
βS.E.Wald ZPr(>|Z|)
Intercept -4.7933 0.5949-8.06<0.0001
tx=b  0.6350 0.97000.650.5127
age  0.0752 0.01136.67<0.0001
age' -0.0274 0.1673-0.160.8699
age''  0.0392 0.40110.100.9221
tx=b × age -0.0319 0.0183-1.740.0820
tx=b × age'  0.2854 0.23211.230.2188
tx=b × age'' -0.5634 0.5254-1.070.2836
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)155.864<0.0001
All Interactions3.0330.3873
age (Factor+Higher Order Factors)175.896<0.0001
All Interactions3.0330.3873
Nonlinear (Factor+Higher Order Factors)2.7340.6041
tx × age (Factor+Higher Order Factors)3.0330.3873
Nonlinear1.9320.3813
Nonlinear Interaction : f(A,B) vs. AB1.9320.3813
TOTAL NONLINEAR2.7340.6041
TOTAL NONLINEAR + INTERACTION3.8250.5755
TOTAL299.447<0.0001



Case Where Treatment Truly Interacts with Age

Estimation of Treatment Effect in Population With No Overlap

Next turn to the case where the true data generating model has a linear treatment by age interaction which we may or may not include in our model. The true model has a treatment effect of -1.0 for age 50 patients, and each year below 50 results in a further reduction by 0.03 in the effect.

No-Interaction Model ⮩

Model Without Interaction

This model failed to include a needed interaction term.
Logistic Regression Model
 lrm(formula = y ~ tx + age, data = d)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 2539    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2461LR χ2 257.32R2 0.144C 0.701
0 1787d.f. 2g 0.888Dxy 0.403
1 674Pr(>χ2) <0.0001gr 2.429γ 0.403
max |∂log L/∂β| 9×10-6gp 0.161τa 0.160
Brier 0.178
βS.E.Wald ZPr(>|Z|)
Intercept -3.8181 0.4509-8.47<0.0001
tx=b -1.4027 0.1020-13.76<0.0001
age  0.0583 0.00777.61<0.0001
Wald Statistics for y
χ2d.f.P
tx189.241<0.0001
age57.921<0.0001
TOTAL223.452<0.0001



Linear Interaction Model ⮩

Model With Linear Interaction

This is the correct model.
Logistic Regression Model
 lrm(formula = y ~ tx * age, data = d)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 2539    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2461LR χ2 258.51R2 0.144C 0.702
0 1787d.f. 3g 0.873Dxy 0.403
1 674Pr(>χ2) <0.0001gr 2.394γ 0.403
max |∂log L/∂β| 3×10-12gp 0.162τa 0.160
Brier 0.178
βS.E.Wald ZPr(>|Z|)
Intercept -4.2193 0.5852-7.21<0.0001
tx=b -0.3879 0.9367-0.410.6788
age  0.0652 0.01006.53<0.0001
tx=b × age -0.0171 0.0157-1.090.2765
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)191.472<0.0001
All Interactions1.1810.2765
age (Factor+Higher Order Factors)58.352<0.0001
All Interactions1.1810.2765
tx × age (Factor+Higher Order Factors)1.1810.2765
TOTAL228.303<0.0001

Because of the more limited age range in the trial there was insufficient power to provide definitive statistical evidence for an interaction, but the point estimate for the interaction effect is not unreasonable. Though confidence bands are wide because of no overlap, the extrapolated treatment effects are reasonable as a result.



Spline Interaction Model ⮩

Model with Spline Interaction

This model correctly captures linear interaction, but also allows for unnecessary nonlinear interaction.
Logistic Regression Model
 lrm(formula = form, data = d, tol = 1e-12)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 2539    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2461LR χ2 261.24R2 0.146C 0.702
0 1787d.f. 7g 0.866Dxy 0.403
1 674Pr(>χ2) <0.0001gr 2.377γ 0.404
max |∂log L/∂β| 4×10-13gp 0.161τa 0.161
Brier 0.178
βS.E.Wald ZPr(>|Z|)
Intercept -3.0988 1.2779-2.420.0153
tx=b  0.1305 2.19460.060.9526
age  0.0445 0.02311.930.0542
age'  0.2124 0.22130.960.3372
age'' -0.4384 0.4906-0.890.3716
tx=b × age -0.0267 0.0396-0.680.4996
tx=b × age'  0.0955 0.33130.290.7731
tx=b × age'' -0.1934 0.6939-0.280.7805
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)191.144<0.0001
All Interactions1.1930.7545
age (Factor+Higher Order Factors)61.606<0.0001
All Interactions1.1930.7545
Nonlinear (Factor+Higher Order Factors)2.6740.6150
tx × age (Factor+Higher Order Factors)1.1930.7545
Nonlinear0.0820.9590
Nonlinear Interaction : f(A,B) vs. AB0.0820.9590
TOTAL NONLINEAR2.6740.6150
TOTAL NONLINEAR + INTERACTION3.7850.5816
TOTAL229.687<0.0001



RCT Sample Partially Overlaps with Target Population

Sticking with the true treatment effect interacting with age, we generate data with the same partial overlap as before, and repeat the same analyses. We start by fitting a model that is oblivious to interaction.

No-Interaction Model ⮩

Model Without Interaction

This model failed to include a needed interaction term.
Logistic Regression Model
 lrm(formula = y ~ tx + age, data = d)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 1444    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3556LR χ2 323.95R2 0.130C 0.699
0 2702d.f. 2g 0.870Dxy 0.397
1 854Pr(>χ2) <0.0001gr 2.387γ 0.397
max |∂log L/∂β| 1×10-11gp 0.145τa 0.145
Brier 0.165
βS.E.Wald ZPr(>|Z|)
Intercept -3.7735 0.2939-12.84<0.0001
tx=b -1.2305 0.0876-14.04<0.0001
age  0.0566 0.005210.80<0.0001
Wald Statistics for y
χ2d.f.P
tx197.201<0.0001
age116.731<0.0001
TOTAL281.792<0.0001



Linear Interaction Model ⮩

Model With Linear Interaction

This is the correct model.
Logistic Regression Model
 lrm(formula = y ~ tx * age, data = d)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 1444    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3556LR χ2 338.39R2 0.136C 0.700
0 2702d.f. 3g 0.818Dxy 0.400
1 854Pr(>χ2) <0.0001gr 2.265γ 0.401
max |∂log L/∂β| 8×10-12gp 0.145τa 0.146
Brier 0.164
βS.E.Wald ZPr(>|Z|)
Intercept -4.6606 0.3849-12.11<0.0001
tx=b  1.0820 0.61291.770.0775
age  0.0726 0.006910.56<0.0001
tx=b × age -0.0412 0.0109-3.790.0002
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)210.592<0.0001
All Interactions14.3610.0002
age (Factor+Higher Order Factors)125.472<0.0001
All Interactions14.3610.0002
tx × age (Factor+Higher Order Factors)14.3610.0002
TOTAL310.443<0.0001

The amount of interaction estimated from the larger older sample extrapolated well to the younger target population.



Spline Interaction Model ⮩

Model with Spline Interaction

This model correctly captures linear interaction, but also allows for unnecessary nonlinear interaction.
Logistic Regression Model
 lrm(formula = form, data = d, tol = 1e-12)
 

Frequencies of Missing Values Due to Each Variable

    y   tx  age 
 1444    0    0 
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3556LR χ2 343.94R2 0.138C 0.700
0 2702d.f. 7g 0.813Dxy 0.401
1 854Pr(>χ2) <0.0001gr 2.255γ 0.401
max |∂log L/∂β| 4×10-12gp 0.146τa 0.146
Brier 0.164
βS.E.Wald ZPr(>|Z|)
Intercept -4.7933 0.5949-8.06<0.0001
tx=b  2.5181 0.93682.690.0072
age  0.0752 0.01136.67<0.0001
age' -0.0274 0.1673-0.160.8699
age''  0.0392 0.40110.100.9221
tx=b × age -0.0698 0.0179-3.91<0.0001
tx=b × age'  0.4148 0.23981.730.0836
tx=b × age'' -0.8163 0.5469-1.490.1355
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)211.504<0.0001
All Interactions19.0630.0003
age (Factor+Higher Order Factors)132.656<0.0001
All Interactions19.0630.0003
Nonlinear (Factor+Higher Order Factors)5.6640.2263
tx × age (Factor+Higher Order Factors)19.0630.0003
Nonlinear3.9720.1374
Nonlinear Interaction : f(A,B) vs. AB3.9720.1374
TOTAL NONLINEAR5.6640.2263
TOTAL NONLINEAR + INTERACTION20.9150.0008
TOTAL316.287<0.0001

The spline interaction estimates did not extrapolate well to the very young.



Ability to Compare Treatments in Observational Studies

When a categorical baseline characteristic has all of the patients in one of its categories getting a single treatment, one cannot estimate efficacy in that category unless (1) there is no interaction between treatment and the variable or (2) the baseline variable does not relate to outcome. If one of these conditions is not satisfied, one would have to do a conditional analysis, i.e., to estimate efficacy in patients not in the offending category. If a continuous baseline variable has an interval for which every patient in that interval received only one treatment, then one cannot estimate the treatment effect in that interval unless (1) there is no interaction (linear or nonlinear) between the variable and treatment or (2) the variable is irrelevant to outcome. So when you hear that non-overlap implies that only a conditional treatment comparison can be done, be aware of the true underlying assumptions. Note that non-overlap on a variable implies non-overlap for one or more values of a propensity score.

To illustrate these points, consider an observational study where the data generating process is from the same population logistic model as used above, but instead of considering generalizability to a population, consider the in-sample comparison of treatments a and b adjusted for age. We start with a sample in which all those with age ≥ 50 got treatment b and all those with age < 50 got treatment a.

True Model Has No Treatment Interactions

No Overlap Between Treatment Groups

All patients age < 50 had treatment a, and those ≥ 50 had b.

Age distributions in the observed treatment groups are shown below.

No-Interaction Model ⮩

Model Without Interaction

This is the correct model.
Logistic Regression Model
 lrm(formula = y ~ tx + age, data = d)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2999LR χ2 87.42R2 0.046C 0.616
0 2431d.f. 2g 0.496Dxy 0.232
1 568Pr(>χ2) <0.0001gr 1.643γ 0.232
max |∂log L/∂β| 8×10-9gp 0.073τa 0.071
Brier 0.149
βS.E.Wald ZPr(>|Z|)
Intercept -4.5743 0.3532-12.95<0.0001
tx=b -1.0283 0.1608-6.40<0.0001
age  0.0714 0.00808.96<0.0001
Wald Statistics for y
χ2d.f.P
tx40.901<0.0001
age80.261<0.0001
TOTAL82.332<0.0001

The model-based covariate adjustment provided the correct estimate of the treatment effect even with no overlap, since the specified model is the correct model.



Linear Interaction Model ⮩

Model With Linear Interaction

This model included an unnecessary linear interaction term.
Logistic Regression Model
 lrm(formula = y ~ tx * age, data = d)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2999LR χ2 88.00R2 0.047C 0.616
0 2431d.f. 3g 0.486Dxy 0.231
1 568Pr(>χ2) <0.0001gr 1.626γ 0.232
max |∂log L/∂β| 5×10-7gp 0.073τa 0.071
Brier 0.149
βS.E.Wald ZPr(>|Z|)
Intercept -4.2550 0.5399-7.88<0.0001
tx=b -1.6471 0.8237-2.000.0455
age  0.0641 0.01245.19<0.0001
tx=b × age  0.0124 0.01610.770.4430
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)40.982<0.0001
All Interactions0.5910.4430
age (Factor+Higher Order Factors)81.732<0.0001
All Interactions0.5910.4430
tx × age (Factor+Higher Order Factors)0.5910.4430
TOTAL84.333<0.0001

With no age overlap, the treatment by age interaction is estimated very inefficiently and in this case incorrectly. Wide confidence bands correctly capture the difficulty of the task of estimating age-specific treatment effects.



Spline Interaction Model ⮩

Model with Spline Interaction

This model included unnecessary linear and nonlinear interaction terms.
Logistic Regression Model
 lrm(formula = form, data = d, tol = 1e-12)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2999LR χ2 89.34R2 0.047C 0.617
0 2431d.f. 5g 0.492Dxy 0.233
1 568Pr(>χ2) <0.0001gr 1.635γ 0.234
max |∂log L/∂β| 4×10-12gp 0.072τa 0.072
Brier 0.149
βS.E.Wald ZPr(>|Z|)
Intercept -5.0833 0.9349-5.44<0.0001
tx=b  0.4348 7.17190.060.9517
age  0.0868 0.02413.600.0003
age' -0.1233 0.1090-1.130.2580
tx=b × age -0.0361 0.1482-0.240.8073
tx=b × age'  0.1420 0.15200.930.3502
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)40.983<0.0001
All Interactions1.5020.4734
age (Factor+Higher Order Factors)80.924<0.0001
All Interactions1.5020.4734
Nonlinear (Factor+Higher Order Factors)1.3120.5193
tx × age (Factor+Higher Order Factors)1.5020.4734
Nonlinear0.8710.3502
Nonlinear Interaction : f(A,B) vs. AB0.8710.3502
TOTAL NONLINEAR1.3120.5193
TOTAL NONLINEAR + INTERACTION1.9030.5925
TOTAL83.335<0.0001



Some Overlap in Ages Between Treatments

Now consider an observational study, again with confounding by indication, related to age. Partial overlap is defined by specifying separate study inclusion probability functions. Given the age and treatment these functions specify the probability that a patient would be included in the observational study. The first plot shows the inclusion probabilities separately for treatments a and b. Then the result of a linear no-interaction model are shown. As before, blue curves depict true data-generating model log odds.

The graph below shows the probability of selection into each of the observed treatment groups as a function of age.

Age distributions in the observed treatment groups are shown below.

No-Interaction Model ⮩

Model Without Interaction

This is the correct model.
Logistic Regression Model
 lrm(formula = y ~ tx + age, data = d)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3031LR χ2 474.99R2 0.212C 0.744
0 2236d.f. 2g 1.257Dxy 0.488
1 795Pr(>χ2) <0.0001gr 3.514γ 0.489
max |∂log L/∂β| 9×10-6gp 0.190τa 0.189
Brier 0.166
βS.E.Wald ZPr(>|Z|)
Intercept -4.8959 0.3443-14.22<0.0001
tx=b -1.0104 0.1787-5.65<0.0001
age  0.0769 0.006112.53<0.0001
Wald Statistics for y
χ2d.f.P
tx31.981<0.0001
age156.931<0.0001
TOTAL335.252<0.0001



Linear Interaction Model ⮩

Model With Linear Interaction

This model included an unnecessary linear interaction term.
Logistic Regression Model
 lrm(formula = y ~ tx * age, data = d)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3031LR χ2 475.20R2 0.212C 0.744
0 2236d.f. 3g 1.273Dxy 0.488
1 795Pr(>χ2) <0.0001gr 3.572γ 0.489
max |∂log L/∂β| 1×10-8gp 0.190τa 0.189
Brier 0.166
βS.E.Wald ZPr(>|Z|)
Intercept -4.8638 0.3512-13.85<0.0001
tx=b -1.6044 1.3432-1.190.2323
age  0.0763 0.006312.18<0.0001
tx=b × age  0.0141 0.03140.450.6546
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)32.332<0.0001
All Interactions0.2010.6546
age (Factor+Higher Order Factors)157.042<0.0001
All Interactions0.2010.6546
tx × age (Factor+Higher Order Factors)0.2010.6546
TOTAL330.683<0.0001

The confidence bands are correctly registering that there is little information about the treatment effect outside of the heavier overlap region.



Spline Interaction Model ⮩

Model with Spline Interaction

This model included unnecessary linear and nonlinear interaction terms.
Logistic Regression Model
 lrm(formula = form, data = d, tol = 1e-12)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3031LR χ2 476.54R2 0.213C 0.744
0 2236d.f. 5g 1.279Dxy 0.489
1 795Pr(>χ2) <0.0001gr 3.591γ 0.489
max |∂log L/∂β| 2×10-7gp 0.190τa 0.189
Brier 0.166
βS.E.Wald ZPr(>|Z|)
Intercept -6.2165 1.3037-4.77<0.0001
tx=b  0.2424 2.33470.100.9173
age  0.1058 0.02803.780.0002
age' -0.0262 0.0240-1.090.2761
tx=b × age -0.0291 0.0579-0.500.6155
tx=b × age'  0.1247 0.29740.420.6749
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)20.2530.0002
All Interactions0.2620.8794
age (Factor+Higher Order Factors)154.874<0.0001
All Interactions0.2620.8794
Nonlinear (Factor+Higher Order Factors)1.3020.5229
tx × age (Factor+Higher Order Factors)0.2620.8794
Nonlinear0.1810.6749
Nonlinear Interaction : f(A,B) vs. AB0.1810.6749
TOTAL NONLINEAR1.3020.5229
TOTAL NONLINEAR + INTERACTION1.5130.6793
TOTAL330.065<0.0001



Case Where Treatment Truly Interacts with Age

No Overlap Between Treatment Groups

Return to the data generating model used in the RCT simulation, for which there is truly a linear interaction with treatment, and start with the no overlap case.

No-Interaction Model ⮩

Model Without Interaction

This model failed to include a needed interaction term.
Logistic Regression Model
 lrm(formula = y ~ tx + age, data = d)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2999LR χ2 39.09R2 0.022C 0.591
0 2493d.f. 2g 0.353Dxy 0.181
1 506Pr(>χ2) <0.0001gr 1.424γ 0.181
max |∂log L/∂β| 4×10-11gp 0.048τa 0.051
Brier 0.139
βS.E.Wald ZPr(>|Z|)
Intercept -3.5659 0.3538-10.08<0.0001
tx=b -0.9499 0.1661-5.72<0.0001
age  0.0481 0.00815.96<0.0001
Wald Statistics for y
χ2d.f.P
tx32.711<0.0001
age35.511<0.0001
TOTAL37.942<0.0001

The treatment effect is incorrect example at age=50.



Linear Interaction Model ⮩

Model With Linear Interaction

This is the correct model.
Logistic Regression Model
 lrm(formula = y ~ tx * age, data = d)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2999LR χ2 42.28R2 0.023C 0.592
0 2493d.f. 3g 0.369Dxy 0.184
1 506Pr(>χ2) <0.0001gr 1.446γ 0.185
max |∂log L/∂β| 3×10-8gp 0.050τa 0.052
Brier 0.138
βS.E.Wald ZPr(>|Z|)
Intercept -4.2550 0.5399-7.88<0.0001
tx=b  0.5441 0.85780.630.5259
age  0.0641 0.01245.19<0.0001
tx=b × age -0.0295 0.0167-1.770.0767
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)36.262<0.0001
All Interactions3.1310.0767
age (Factor+Higher Order Factors)36.452<0.0001
All Interactions3.1310.0767
tx × age (Factor+Higher Order Factors)3.1310.0767
TOTAL40.053<0.0001

The extrapolation is excellent. Now try the overkill model.



Spline Interaction Model ⮩

Model with Spline Interaction

This model correctly captures linear interaction, but also allows for unnecessary nonlinear interaction.
Logistic Regression Model
 lrm(formula = form, data = d, tol = 1e-12)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 2999LR χ2 44.02R2 0.024C 0.592
0 2493d.f. 5g 0.387Dxy 0.184
1 506Pr(>χ2) <0.0001gr 1.473γ 0.185
max |∂log L/∂β| 2×10-5gp 0.050τa 0.052
Brier 0.138
βS.E.Wald ZPr(>|Z|)
Intercept -5.0833 0.9349-5.44<0.0001
tx=b -3.5002 7.5833-0.460.6444
age  0.0868 0.02413.600.0003
age' -0.1233 0.1090-1.130.2580
tx=b × age  0.0483 0.15680.310.7581
tx=b × age'  0.0498 0.15690.320.7508
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)32.653<0.0001
All Interactions0.9720.6143
age (Factor+Higher Order Factors)35.524<0.0001
All Interactions0.9720.6143
Nonlinear (Factor+Higher Order Factors)1.7020.4269
tx × age (Factor+Higher Order Factors)0.9720.6143
Nonlinear0.1010.7508
Nonlinear Interaction : f(A,B) vs. AB0.1010.7508
TOTAL NONLINEAR1.7020.4269
TOTAL NONLINEAR + INTERACTION4.5930.2041
TOTAL39.245<0.0001

Extrapolation failed, and the failure was thankfully signaled by very wide confidence bands for age-specific treatment effects.



Some Overlap in Ages Between Treatments

No-Interaction Model ⮩

Model Without Interaction

This model failed to include a needed interaction term.
Logistic Regression Model
 lrm(formula = y ~ tx + age, data = d)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3031LR χ2 421.49R2 0.189C 0.732
0 2221d.f. 2g 1.131Dxy 0.464
1 810Pr(>χ2) <0.0001gr 3.098γ 0.464
max |∂log L/∂β| 1×10-7gp 0.182τa 0.182
Brier 0.170
βS.E.Wald ZPr(>|Z|)
Intercept -4.7976 0.3406-14.09<0.0001
tx=b -0.7412 0.1640-4.52<0.0001
age  0.0751 0.006112.37<0.0001
Wald Statistics for y
χ2d.f.P
tx20.411<0.0001
age153.011<0.0001
TOTAL319.212<0.0001

The no-interaction model missed the boat. Now fit the correct linear interaction model.



Linear Interaction Model ⮩

Model With Linear Interaction

This is the correct model.
Logistic Regression Model
 lrm(formula = y ~ tx * age, data = d)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3031LR χ2 422.14R2 0.189C 0.732
0 2221d.f. 3g 1.112Dxy 0.464
1 810Pr(>χ2) <0.0001gr 3.040γ 0.464
max |∂log L/∂β| 1×10-5gp 0.182τa 0.182
Brier 0.170
βS.E.Wald ZPr(>|Z|)
Intercept -4.8638 0.3512-13.85<0.0001
tx=b  0.1333 1.08130.120.9019
age  0.0763 0.006312.18<0.0001
tx=b × age -0.0208 0.0255-0.810.4151
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)20.562<0.0001
All Interactions0.6610.4151
age (Factor+Higher Order Factors)153.462<0.0001
All Interactions0.6610.4151
tx × age (Factor+Higher Order Factors)0.6610.4151
TOTAL326.023<0.0001

There is reasonable extrapolation. Now for the overkill model.



Spline Interaction Model ⮩

Model with Spline Interaction

This model correctly captures linear interaction, but also allows for unnecessary nonlinear interaction.
Logistic Regression Model
 lrm(formula = form, data = d, tol = 1e-12)
 
Model Likelihood
Ratio Test
Discrimination
Indexes
Rank Discrim.
Indexes
Obs 3031LR χ2 423.48R2 0.190C 0.732
0 2221d.f. 5g 1.121Dxy 0.464
1 810Pr(>χ2) <0.0001gr 3.069γ 0.464
max |∂log L/∂β| 3×10-5gp 0.183τa 0.182
Brier 0.170
βS.E.Wald ZPr(>|Z|)
Intercept -6.2165 1.3037-4.77<0.0001
tx=b  1.8369 1.95270.940.3468
age  0.1058 0.02803.780.0002
age' -0.0262 0.0240-1.090.2761
tx=b × age -0.0602 0.0477-1.260.2067
tx=b × age'  0.1114 0.25920.430.6672
Wald Statistics for y
χ2d.f.P
tx (Factor+Higher Order Factors)16.3230.0010
All Interactions1.9420.3784
age (Factor+Higher Order Factors)151.014<0.0001
All Interactions1.9420.3784
Nonlinear (Factor+Higher Order Factors)1.3020.5233
tx × age (Factor+Higher Order Factors)1.9420.3784
Nonlinear0.1810.6672
Nonlinear Interaction : f(A,B) vs. AB0.1810.6672
TOTAL NONLINEAR1.3020.5233
TOTAL NONLINEAR + INTERACTION1.9830.5774
TOTAL325.315<0.0001

Extrapolated treatment effect estimates are so-so.



Summary

With respect to relative efficacy (or both relative and absolute efficacy for continuous repsonse variables), clinical trials do not require having a representative sample of the target clinical population if there are no interactions with treatment. If there are interactions, let M denote the levels of interacting factors that are well represented in the target population. In our examples, M represents younger patients. Even with interaction present, the randomized trial still does not need to be on a representative patient sample if either (1) the trial sample is representative with respect to M (in which case omitting interactions from the model is not fatal), or (2) there is just enough representation in the sample with respect to M, and those interacting factors are appropriately modeled in the randomized trial. Unless M is richly represented in the trial, using statistical testing to decide on which interactions to include in the model is not advised, due to low power of such interaction tests. Suspected interactions, even statistically weak ones, should be included in the model when some degree of extrapolation is sought. When M is very poorly represented in the trial, extrapolation to the target population makes strong model assumptions. Thankfully confidence intervals for extrapolated efficacy estimates will be properly wide to reflect the weak basis for such extrapolation.

In a similar vein, observational treatment comparisons can be appropriate if factors that do not overlap between treatment groups do not interact with treatment. So a key to understanding both overlap and clinical trial generalizability is interactions.


Further Reading


Questions and Discussion

Go here.


R Code | R Markdown

Code ⮩
gendatrct <- function(n, popmodel, inclusion, pr=TRUE) {
    set.seed(1)
    age <- rnorm(n, 50, 10)
		ager <- round(range(age), 1)
    tx  <- sample(c('a', 'b'), n, replace=TRUE)
    y   <- ifelse(runif(n) <= plogis(popmodel(age, tx)), 1, 0)
    # Inclusion in the RCT is marked by having non-missing outcome
    # inclusion is a function of age computing P(include in RCT)
    y   <- ifelse(inclusion(age) >= runif(n), y, NA)
    d   <- data.frame(age, tx, y)
		if(pr)
    cat('The original age range is', ager[1], '-', ager[2], 'in', n,
        'subjects, and the clinical trial includes', sum(! is.na(d$y)),
        'of the subjects.<br>')
    d
}

gendatobs <- function(n, popmodel, incla, inclb) {
    set.seed(1)
    age <- rnorm(n, 50, 10)
    tx  <- sample(c('a', 'b'), n, replace=TRUE)
    y   <- ifelse(runif(n) <= plogis(popmodel(age, tx)), 1, 0)
    # incla is a function of age computing P(include in study if a)
    # inclb is the same for tx=b
    prob <- ifelse(tx == 'a', incla(age), inclb(age))
    i <- runif(n) <= prob
    data.frame(age, tx, y)[i, ]
}


# Plot fitted relationship between logit(y) and age by treatment
# along with theoretical true relationship
pl <- function(popmodel, ylim=NULL) {
    ar <- range(d$age)
    g <- ggplot(Predict(f, age=seq(ar[1], ar[2], length=100), tx),
           rdata=subset(d, ! is.na(y)), ylim=ylim) +
         annotate('line', x=ar, y=popmodel(ar, 'a'), col='blue', alpha=.4) +
         annotate('line', x=ar, y=popmodel(ar, 'b'), col='blue', alpha=.4) +
         theme(legend.position=c(.9, .17)) +
         labs(caption='Estimated log odds of outcome along with true (blue) values.\nTick marks show raw data density stratified by treatment')
    g
}

# Estimated and true treatment effect as a function of age
plc <- function(popmodel, ages=10:80, ylim=c(-3, 1)) {
    k <- contrast(f, list(tx='b', age=ages),
                     list(tx='a', age=ages))
    w <- as.data.frame(k[c('age','Contrast','Lower','Upper')])
    g <- ggplot(w, aes(x=age, y=Contrast)) +
        geom_ribbon(aes(ymin=Lower, ymax=Upper), fill='grey80') +
        geom_line() +
        xlab('Age') + ylab('b - a Treatment Difference') +
        annotate('line', x=ages,
                 y=popmodel(ages, 'b') - popmodel(ages, 'a'),   
                 col='blue', alpha=.4) +
        ylim(ylim) +
        labs(caption='Estimated (black) and true (blue)\ntreatment effect as a function of age\nBands are 0.95 confidence bands')
		g
}

plb <- function(popmodel) {
    g <- cowplot::plot_grid(pl(popmodel), plc(popmodel))
		cat('\n')
    print(g)
		cat('\n\n')
    invisible()
    }
ct <- function(...) cat('\n\n', ..., '\n\n', sep='')

# Function to manually output html figure inclusion markup
# With loops even with fig.show='asis' knitr doesn't always output
# figures soon enough.  Taking control in this way also allows
# figure sizes to vary within the loop

figincl <- function(figno, type='svg', width=672) {
  cname <- knitr::opts_current$get('label')
  filename <- knitr::fig_chunk(cname, type, figno)
  cat('\n<img src="', filename, '" width="', width, '" />\n\n', sep='')
	invisible()
}
# <img src="/post/ia_files/figure-html/main-30.svg" width="672" />


# Function to enclose a left margin note in a div and to open a div for the
# usual right hand side content
lmargin  <- function(x) c('<div id="boxes"><div id="leftbox">', x,
                          '</div><div id="rightbox">')
closebox <- function() ct('<br></div></div><div class="clear"></div><br>')

h1 <- c(rct = 'Generalizability of Randomized Clinical Trials',
        obs = 'Ability to Compare Treatments in Observational Studies')
h2 <- c(noia = 'True Model Has No Treatment Interactions',
        ia   = 'Case Where Treatment Truly Interacts with Age')

figno <- 0
for(design in c('rct', 'obs')) {
  ct('# ', h1[design])
  h3 <- switch(design,
               rct = c(none    = 'Estimation of Treatment Effect in Population With No Overlap',
                       partial = 'RCT Sample Partially Overlaps with Target Population'),
               obs = c(none    = 'No Overlap Between Treatment Groups',
                       partial = 'Some Overlap in Ages Between Treatments'))
  txt(design)
  for(model in c('noia', 'ia')) {
    ct('## ', h2[model])
    popmodel <- switch(model,
                       noia = function(age, tx) -1 + (age - 50) / 15 - 1.0 * (tx == 'b'),
                       ia   = function(age, tx) -1 + (age - 50) / 15 +
                                 (tx == 'b') * (-1 - 0.03 * (age - 50)) )

    for(overlap in c('none', 'partial')) {
      ct('### ', h3[overlap])
      txt(design, model, overlap)

      # Function if age that is P(inclusion in RCT)
      incl <- switch(overlap,
                     none    = function(age) ifelse(age >= 50, 1, 0),
                     partial = function(age)
                        approx(c(0,    25,   40,  45, 50),
                               c(0, 0.075, 0.15, 0.5,  1), rule=2, xout=age)$y)
      # Functions of age that are P(selection to be in tx a group) and also for b group
      incla <- switch(overlap,
                      none    = function(age) ifelse(age < 50, 1, 0),
                      partial = function(age)
                         approx(c(0,    25,   40,  45, 50, 55),
                                c(0, 0.075, 0.15, 0.5,  1,  1),
                                xout=age, rule=2)$y)
      inclb <- function(age) 1 - incla(age)

      if(model == 'noia') {
        switch(overlap,
          none = switch(design,
                        rct = '',
                        obs = ct('All patients age < 50 had treatment a, and those ≥ 50 had b.')),
          partial = {
            a <- seq(10, 80, length=100)
            switch(design,
              rct = {
              plot(a, incl(a), type='l', xlab='Age', ylab='P(Inclusion)', ylim=c(0,1))
							figno <- figno + 1; figincl(figno, width=500)
              },
            obs = {
              ct('The graph below shows the probability of selection into each of the observed treatment groups as a function of age.')
              w <- list(a=list(x=a, y=incla(a)), b=list(x=a, y=inclb(a)))
              labcurve(w, pl=TRUE, xlab='Age', ylab='P(Inclusion)')
							figno <- figno + 1; figincl(figno, width=500)
            })}) 
        }
     # Generate a sample that meets our requirements
     d <- switch(design,
                 rct = gendatrct(5000, popmodel, inclusion=incl,
                                 pr=model == 'noia'),
                 obs = gendatobs(6000, popmodel, incla=incla, inclb=inclb))
     dd <- datadist(d, q.display=c(0,1)); options(datadist='dd')
		 if(model == 'noia') switch(design,
		        rct = {ct('Age distributions in the target population as compared to the RCT sample are shown below.')
						       with(d, histbackback(age[is.na(y)], age[! is.na(y)],
                        brks=13:89, xlab=c('Target Population','RCT'), ylab='Age'))
                   figno <- figno + 1; figincl(figno, width=500) },
            obs = {ct('Age distributions in the observed treatment groups are shown below.')
                   with(d, histbackback(age[tx == 'a'], age[tx == 'b'],
                        brks=13:89, xlab=c('a','b'), ylab='Age'))
                   figno <- figno + 1; figincl(figno, width=500) }
     )

     ct('<details><summary>No-Interaction Model ⮩</summary>\n\n#### Model Without Interaction')
		 marg <- switch(model,
		   noia = 'This is the correct model.',
		   ia   = 'This model failed to include a needed interaction term.')
     f <- lrm(y ~ tx + age, data=d)
     # To render html from a chunk in a loop, must create html character strings
     # with print() then output the strings with cat() (called by ct())
     # Earlier options(prType='html') made print() create html for fit objects, anova
     ct(lmargin(marg), print(f))
     ct(print(anova(f)))
		 plb(popmodel)
		 figno <- figno + 1; figincl(figno)
     txt(design, model, overlap, part='interp additive fit')
		 closebox()
		 ct('</details>')

		 ct('<details><summary>Linear Interaction Model ⮩</summary>\n\n#### Model With Linear Interaction')
		 marg <- switch(model,
       noia = 'This model included an unnecessary linear interaction term.',
       ia   = 'This is the correct model.')
     f <- lrm(y ~ tx * age, data=d)
     ct(lmargin(marg), print(f))
     ct(print(anova(f)))
     plb(popmodel)
		 figno <- figno + 1; figincl(figno)

     txt(design, model, overlap, part='interp linear ia')
     closebox()
     ct('</details>')

     ct('<details><summary>Spline Interaction Model ⮩</summary>\n\n#### Model with Spline Interaction')
     marg <- switch(model,
       noia = 'This model included unnecessary linear and nonlinear interaction terms.',
       ia   = 'This model correctly captures linear interaction, but also allows for unnecessary nonlinear interaction.')

     form <- switch(design,
                    rct = y ~ tx * rcs(age, c(55, 60, 70, 80)),
                    obs = y ~ tx * rcs(age, c(35, 50, 65)))
     f <- lrm(form, tol=1e-12, data=d)
     ct(lmargin(marg), print(f))
     ct(print(anova(f)))
     plb(popmodel)
		 figno <- figno + 1; figincl(figno)
 
     txt(design, model, overlap, part='interp nonlinear ia')
     closebox()
     ct('</details>')
    }
  }
}

Portion of the txt Function

Here is part of the txt function, which is called by the code above to insert sentences at appropriate places.

txt <- function(design, model='', overlap='', part='') {
  w <- list(
    list(design='rct', text='When the outcome generating process in a randomized clinical trial (RCT) is such that treatment does not interact with any baseline patient characteristic over the range of characteristics seen in the union of the RCT and the population ...'),

    list(design='rct', model='noia', overlap='none', text='As an example consider a simulated study of about 2500 patients with a ...')

  # Several more lists are defined in txt
  )
  g <- function(x, y) (! length(x) && y == '') || (length(x) && y == x)

  for(x in w) {
    if(g(x$design, design) && g(x$model, model) && g(x$overlap, overlap) &&
		   g(x$part,   part)) {
      ct(x$text)
      break
    }
  }
  return(invisible())
}
Frank Harrell
Frank Harrell
Professor of Biostatistics

My research interests include Bayesian statistics, predictive modeling and model validation, statistical computing and graphics, biomedical research, clinical trials, health services research, cardiology, and COVID-19 therapeutics.

comments powered by Disqus

Related