# Ways of modeling the same variable as both a time-invariant and time-varying predictor

I am building a model attempting to predict heroin use over time in patients based on their use of amphetamine-type substances (ATS). ATS use and heroin use are measured in the same questionnaire and therefore any time heroin use is recorded, ATS use is also recorded. There are two potential models I am considering.

# Model 1

Model 1 is a three-predictor model. The predictors are:

(i) ATSUseAtBaseline (a time-invariant categorical predictor based on days of ATS use in the 28 days previous to baseline, with three levels of ATS use, none (0 days), low (1-12 days' use), and high (13-28 days' use); the none category is the reference category)

(ii) yearsFromStart a continuous variable indicating how many years from start of treatment the measurement was made

(iii) ATSUseAtBaseline x yearsFromStart interaction

This is the output from the model, a longitudinal mixed effects repeated measures regression with the above predictors as fixed factors and random slopes (i.e. yearsFromStart|participant id. The model was fit in R using the lme() function in the nlme package.

Linear mixed-effects model fit by maximum likelihood
Data: workDF
AIC      BIC    logLik
33606.85 33672.54 -16793.42

Random effects:
Formula: ~yearsFromStart | pID
Structure: General positive-definite, Log-Cholesky parametrization
StdDev   Corr
(Intercept)    4.018394 (Intr)
yearsFromStart 2.992416 -0.871
Residual       4.777283

Fixed effects: heroin ~ yearsFromStart + ATSUseAtBaseline + yearsFromStart:ATSUseAtBaseline
Value Std.Error   DF   t-value p-value
(Intercept)                          1.331320 0.1153107 3335 11.545503  0.0000
yearsFromStart                      -0.741715 0.2332848 1924 -3.179440  0.0015
ATSUseAtBaselinelow                  2.853880 0.2878873 3335  9.913185  0.0000
ATSUseAtBaselinehigh                 4.308878 0.5171080 3335  8.332647  0.0000
yearsFromStart:ATSUseAtBaselinelow  -2.594455 0.5637359 1924 -4.602252  0.0000
yearsFromStart:ATSUseAtBaselinehigh -7.339846 1.8286941 1924 -4.013709  0.0001
Correlation:
(Intr) yrsFrS ATSUsAtBslnl ATSUsAtBslnh
yearsFromStart                      -0.410
ATSUseAtBaselinelow                 -0.401  0.164
ATSUseAtBaselinehigh                -0.223  0.091  0.089
yearsFromStart:ATSUseAtBaselinelow   0.170 -0.414 -0.428       -0.038
yearsFromStart:ATSUseAtBaselinehigh  0.052 -0.128 -0.021       -0.327
yrsFrmStrt:ATSUsAtBslnl
yearsFromStart
ATSUseAtBaselinelow
ATSUseAtBaselinehigh
yearsFromStart:ATSUseAtBaselinelow
yearsFromStart:ATSUseAtBaselinehigh  0.053

Standardized Within-Group Residuals:
Min          Q1         Med          Q3         Max
-2.49102026 -0.16320514 -0.16320514 -0.08182908  5.11315552

Number of Observations: 5265
Number of Groups: 3338


So far so good. All predictors are significant, with no ATS use predicting less heroin use at baseline than low ATS use or high ATS use. The rate of reduction in heroin use (in days use in the previous 28 days) each year of treatment is lowest in the group using no ATS at baseline and highest in the group with high ATS use at baseline. There are 3338 participants with 5265 observations (i.e. the overwhelming majority only have one measurement, at baseline).

# Model 2

Model 2 is a four-predictor model, including the three predictors in the first model and

(iv) atsFactor: the time-varying equivalent of ATSUseAtBaseline, with the same three levels, none, low, and high.

Here is the output

Linear mixed-effects model fit by maximum likelihood
Data: workDF
AIC      BIC    logLik
33560.04 33638.87 -16768.02

Random effects:
Formula: ~yearsFromStart | pID
Structure: General positive-definite, Log-Cholesky parametrization
StdDev   Corr
(Intercept)    4.085715 (Intr)
yearsFromStart 2.892861 -0.89
Residual       4.716549

Fixed effects: heroin ~ yearsFromStart + ATSUseAtBaseline + atsFactor + yearsFromStart:ATSUseAtBaseline
Value Std.Error   DF   t-value p-value
(Intercept)                          1.299861 0.1154830 3335 11.255865  0.0000
yearsFromStart                      -0.877436 0.2253863 1922 -3.893033  0.0001
ATSUseAtBaselinelow                  0.818656 0.4252261 3335  1.925226  0.0543
ATSUseAtBaselinehigh                 0.933265 0.8938787 3335  1.044062  0.2965
atsFactorlow                         2.312577 0.3586254 1922  6.448447  0.0000
atsFactorhigh                        3.584153 0.7797614 1922  4.596473  0.0000
yearsFromStart:ATSUseAtBaselinelow  -1.346094 0.5846532 1922 -2.302381  0.0214
yearsFromStart:ATSUseAtBaselinehigh -5.079803 1.9771895 1922 -2.569204  0.0103
Correlation:
(Intr) yrsFrS ATSUsAtBslnl ATSUsAtBslnh atsFctrl atsFctrh
yearsFromStart                      -0.408
ATSUseAtBaselinelow                 -0.248  0.180
ATSUseAtBaselinehigh                -0.116  0.080  0.179
atsFactorlow                        -0.032 -0.093 -0.735       -0.182
atsFactorhigh                       -0.016 -0.033 -0.173       -0.816        0.219
yearsFromStart:ATSUseAtBaselinelow   0.148 -0.415 -0.536       -0.017        0.363   -0.006
yearsFromStart:ATSUseAtBaselinehigh  0.044 -0.114  0.013       -0.499       -0.042    0.405
yrsFrmStrt:ATSUsAtBslnl
yearsFromStart
ATSUseAtBaselinelow
ATSUseAtBaselinehigh
atsFactorlow
atsFactorhigh
yearsFromStart:ATSUseAtBaselinelow
yearsFromStart:ATSUseAtBaselinehigh -0.009

Standardized Within-Group Residuals:
Min          Q1         Med          Q3         Max
-2.52320797 -0.15744819 -0.15744819 -0.06879067  5.32278040

Number of Observations: 5265
Number of Groups: 3338


The addition of the time-varying predictor has changed things. The significant differences in intercept coefficients for the time-invariant ATS use predictor ATSUseAtBaseline are no longer significant. Even the interaction coefficients for these time-invariant versions of the predictor are no longer as strong. The time-varying predictor is a strong predictor in this model. Low ATS use at any time is associated with an increase in heroin use of 2.31 days, and high ATS use is associated with an increase heroin use of 3.6 days!

A likelihood ratio test of the two models...

         Model df      AIC      BIC    logLik   Test  L.Ratio p-value
tiModel1     1 10 33606.85 33672.54 -16793.42
tvModel2     2 12 33560.04 33638.87 -16768.02 1 vs 2 50.80377  <.0001


...shows that the addition of the time-varying predictor in tvModel2 has increased the predictive power of the first model (tvModel1) considerably.

However the problem for interpreting this model is that the values of the time-invariant predictor ATSUseAtBaseline and the time-varying predictor atsFactor at time = 0 are identical. The fact that these baseline measurement make up 3338/5265 = 64% of all observations makes me think that there is some serious confounding of the two predictors going on, making interpretation of either variable very tricky.

So my questions are:

1. Is it ok to use the same variable as both a time-invariant and a time-varying predictor in the same model?

Even if the answer is "No." that will help.

2. If it is ok to include both, how do I resolve the ambiguities between the time-invariant and the time-varying predictors?

• It is a bit difficult to understand how atsusebaseline and atsfactor are exactly related.. baseline is the first observation of atsfactor? Or the mean over atsfactor over individual observations? Or other? – Alex. C-L - Reinstate Monica Dec 9 '19 at 7:22
• @Alex.C-L-ReinstateMonica I have the same thought, though it would appear your suggestion would not be true otherwise the there would be perfect multicolinearity between ATSUseAtBaseline and the atsFactor0 dummy which should generate a warning. @llewmills, please can you clarify and also include the actual model output for both models. – Robert Long Dec 9 '19 at 8:14
• ...I mean including the model formula, random effects estimation etc..and an 'str(data and summary(data)' would also be useful. – Robert Long Dec 9 '19 at 8:29
• thanks for commenting everyone. Yes @Alex. C-L - Reinstate Monica (who is Monica by the way, have seen this tag many times?), ATSUseAtBaseiline is the first observation of atsFactor. It is compulsory for all patients being admitted to the drug and alcohol treatment service where this study was conducted to have their frequency of drug and alcohol use in the previous 28 days recorded on the first day of treatment. Follow-up measurements during treatment are far less common as they are not compulsory. – llewmills Dec 9 '19 at 9:30
• @Robert Long I have added the full summary output to my origonal post. – llewmills Dec 9 '19 at 9:36

In general, it would not be a problem including the value of ATS at baseline in the model and also its time-varying version. This is also some times done in longitudinal data for the time variable itself. The motivation to do this, for example, when you have a significant increase or decrease in your outcome after baseline (e.g., in patients after an operation).
With that being said, with time-varying covariates, in general, you need to be careful of the functional form, i.e., the type of association you postulate. By simply including the time-varying covariate in the model you assume a kind of a "cross-sectional" association, i.e., the outcome at time $$t$$ is associated with the value to the covariate at the same time point $$t$$. On some occasions, this may not be what you want. For example, it could be more meaningful to include a lagged association postulating that the outcome at time $$t$$ is associated with the value of the covariate at $$t - c$$ or that the outcome at $$t$$ is associated with all past values of the covariate via a cumulative effect.
• Thank you @Dimitiris Rizopoulos that is very heartening news. I think both versions of the predictor would offer slightly different insights. And I love the idea of a lagged predictor. So if one believed that increased ATS use leads to increased heroin use 3 months after the increase in ATS use one would what, create a lagged predictor via something like df$yearsFromStart_lag <- df$yearsFromStart - 0.25(bearing in mind the yearsFromStart variable is in years), is that correct? – llewmills Dec 9 '19 at 9:42