# TVEM FAQ

This page addresses FAQs about time-varying effect modeling. For questions about our TVEM software, see the appropriate software users' guide.

### Overview of TVEM

**What is TVEM? **

The time-varying-effect model (TVEM) allows users to discover the nature of changes in the relationship between two variables over time, even if that change happens in an irregular manner. TVEM is an extension of linear regression that allows levels of an outcome (intercepts) as well as associations between predictors and an outcome (slopes) to vary across time. TVEM is a flexible model that does not impose assumptions about the shape of the time-varying effects across time – that is, it does not force time-varying effects to follow a linear, quadratic, cubic, or other parametric function of time.

**I want to read more about TVEM. Can you recommend some articles? **

We maintain a list of recommended publications about TVEM on our website, including both applied examples and technical readings.

### Data

**What type of data do I need in order to use TVEM?**

TVEM can work with multiple data types. Please read the data characteristics appropriate for TVEM webpage for more information.

**How do I prepare my data to run a TVEM? **

Three steps are needed. First, much like data for many other longitudinal models (mixed models, generalized estimating equations), data for TVEM need to be arranged in “long” form, with each row of data containing information for a single person at a single time point. Second, an intercept will need to be manually created in your data set. This can be done by creating a new variable (e.g., “intercept,” “int”) that is equal to 1 for all records in the dataset. Third, one should check the coverage of observations along the time axis. Ideally, there will be a representation of data points for the outcome (i.e., dependent variable) and any time-varying predictors (i.e., independent variables) across the entire time axis.

**There are published examples of TVEM using panel data, such as Add Health. Add Health only has four waves, so how is it possible to get adequate coverage of the time axis?**

One of the main data considerations for running a TVEM is to have coverage of the time axis of interest: that is, to have data from many points across near-continuous time. This does not necessarily mean that any individual in the study has to have data at every point in time, but instead coverage can be obtained through a number of different designs that vary in terms of the number of participants and measurement occasions. For example, in some circumstances a TVEM can be run on cross-sectional data if the data set has a large number of participants who vary on the time axis, to estimate age-varying associations among participants of many different ages (e.g., NESARC). In this case, coverage of the time axis is achieved through a single measurement occasion from a large number of people. On the other extreme, adequate data for TVEM can be obtained from a small number of participants who have many measurement occasions, such as an ecological momentary assessment (EMA) or daily diary study. In this case, coverage is driven primarily by the large number of measurement occasions per person.

The Add Health study is between these two examples. It is a longitudinal panel study with 4 (soon to be 5) waves collected from individuals from adolescence to adulthood. It can be thought of as a cohort sequential or accelerated longitudinal design, which is a design in which individuals at different ages are recruited and followed up at subsequent time points in order to more efficiently sample across a larger age range. For example, individuals could be assessed once in adolescence, when they are 12-18 years old, then again 6 years later, when individuals are 18-24 years old, and again 6 years later, when they are 24-30 years old. Thus, although each participant only has a small number of measurement occasions (three in this hypothetical example), when combining across participants and occasions, there is good coverage across all ages from 12 to 30 years old.

A TVEM can be estimated with all of these different types of data. However, researchers need to be careful with the interpretations of their data when using cross-sectional or accelerated longitudinal designs. If a cross-sectional study includes individuals from a wide range of ages, it can be difficult to disentangle age effects (developmental differences) from cohort effects (differences for individuals born in different time periods). When describing these types of analyses, researchers should be careful in their interpretations, and discuss the limitations inherent in these data. Despite this limitation, these types of data can give us important information when a long-term intensive longitudinal study is not possible.

**What sample size do I need to run a TVEM?**

Power analysis for TVEM remains an open area of research. There is no harm in running a TVEM with a smaller data set, but the confidence intervals will be wider for smaller sample due to larger standard errors of the coefficients. Interestingly, in TVEM, data coverage across the time axis can vary; confidence intervals for the coefficients will widen and narrow across time, in part as a function of the density of data at various points in time.

**What does “time” mean in TVEM? **

Time can mean a wide variety of things in TVEM. Lanza, Vasilenko, & Russell (2016) present examples of four different ways to operationalize time: *historical time*, *biological age*, *time relative to an event*, and *age of onset* of a particular behavior or condition. Because TVEM estimates associations between variables as a continuous function of time, researchers need to have adequate data on the outcome across the entire span of time they are investigating.

This coverage of the time axis can be achieved using several types of data. When intensive longitudinal data, such as ecological momentary assessments (EMA), are used, each person typically has many occasions of data across the time axis. Time can refer to time relative to an event, as in this smoking-cessation example drawn from Shiyko, Lanza, Tan, & Shiffman, (2012). In this study, data were collected at five random times each day on a mobile device for two weeks after a smoking quit attempt. By overlaying all participants' data measured as a function of time since quitting smoking, good coverage over time can be achieved.

As an extreme, cross-sectional data can be used in TVEM if there are a sufficient number of participants in the study assessed at different ages. For example, if you had data from people at many ages from 18-65 years old, you could run a TVEM covering this age period to estimate regression coefficients as a flexible function of biological age.

Time can mean biological age, as in this sexual risk example (drawn from Vasilenko & Lanza, 2014) which examines longitudinal panel data. In this study, participants completed four assessments during adolescence and young adulthood. However, participants were recruited when they were in grades 7-12. Because of this staggered entry into the study, there is adequate coverage across age (measured to the nearest month at each time point) when combining across both people and assessments. Data on sexual behavior was collected at all ages from 14-32. If the study design had, instead, sampled every participant only at ages 14, 22, and 32, there would be large gaps in age coverage, and TVEM would not be an appropriate method.

In fact, “time” need not even refer to actual time. Any continuous variable can be specified as the “time” variable, and associations between predictors and an outcome can be estimated as a continuous, nonparametric function of that specified variable. In this way, TVEM can be used to examine flexible intercepts and slopes as a nuanced function of a continuous moderator. Regardless of how time is conceived, the critical issue is that your data have good coverage across the time axis.

Lanza, S. T., Vasilenko, S. A., & Russell, M. A. (2016). Time-varying effect modeling to address new questions in behavioral research: Examples in marijuana use. *Psychology of Addictive Behaviors, 30*(8), 939.

Shiyko, M. P., Lanza, S. T., Tan, X., Li, R., & Shiffman, S. (2012). Using the time-varying effect model (TVEM) to examine dynamic associations between negative affect and self confidence on smoking urges: Differences between successful quitters and relapsers. *Prevention Science.* PMCID: PMC3372905 doi: 10.1007/s11121-011-0264-z

Vasilenko, S. A., & Lanza, S. T. (2014). Predictors of multiple sexual partners from adolescence through young adulthood. *Journal of Adolescent Health. 55*(4), 491-497.

### About the Model

**How is TVEM similar to or different from linear regression? **

TVEM is an extension of linear regression. In linear regression, all coefficients (i.e., intercept and slopes) are single-number summaries of an expected mean or an association that do not change over time. TVEM allows the regression coefficients to be estimated as flexible, nonparametric functions of time.

Below is the traditional regression equation predicting the outcome, *Y. *

*Y *= *β*_{0} + *β*_{0}*x* + *e
*

The TVEM equation incorporates time.

*Y *= *β*_{0}(*t *) + *β*_{0}(*t *)*x* + *e*

An important feature of TVEM is that it does not make strong assumptions about the form of this change. TVEM does not force an estimated coefficient function to follow a linear, quadratic, cubic, or any other parametric function, and instead estimates the function flexibly over time.

**Can I include covariates and interactions in TVEM the same way I can in regression?**

Yes. Because TVEM is an extension of linear regression, models can include covariates and interactions, just as you would see in a traditional regression model. You do need to specify whether each covariate and interaction term is to have a time-varying or time-invariant effect. See the TVEM Users’ Guide for details.

Li, R., Dziak, J. J., Tan, X., Huang, L., Wagner, A. T., & Yang, J. (2017). *TVEM (time-varying effect model) SAS macro users' guide *(Version 3.1.1). University Park: The Methodology Center, Penn State. Retrieved from http://methodology.psu.edu

**Is it possible to examine moderation of time-varying effects? **

Yes, and often these are the most interesting results! There are two general approaches to moderation analysis in TVEM.

One way is to (a) split the sample into groups, (b) run TVEM separately for each group, and (c) plot the time-varying effect (and its 95% confidence limits) for all groups on the same plot. Time-varying effects are significantly different between groups at all points where the 95% confidence intervals do not overlap. The advantage of this approach is that it is simple and straightforward. A disadvantage is that it only works if you are able to split your moderator into natural groups (e.g., male versus female) or artificial but meaningful groups (e.g., high, moderate, and low levels of depression). Further, this approach does not provide a formal statistical test of moderation; relying on identifying times at which 95% confidence intervals do not overlap is likely to be overly conservative, such that moderation effects may be underreported.

A second way to examine moderation in TVEM is to add to the model an interaction term and specify that is has a time-varying effect. This is set up the same way you would set up a regression: by creating a new variable that reflects the product of the moderator and the predictor of interest. In addition to specifying time-varying effects for the main effects of the predictor and the moderator, the interaction term is specified to have a time-varying effect. As an example, specifying a TVEM that predicts craving from negative affect, gender, and their interaction provides a test of whether the time-varying association between negative affect and craving is significantly different for males and females, and it allows the researcher to identify the specific time points at which the gender difference is significant. Model estimates can then be used to generate “simple effects” showing the time-varying effect for, for example, males and females separately, without splitting the data. Advantages of this approach include the ability to include both categorical (e.g., gender, race/ethnicity) and continuous (e.g., neuroticism) moderators and that this approach produces a statistical test of the interaction effect at all time points. A disadvantage of this approach is that it may be more burdensome for the analyst.

Both approaches have been used successfully in prior studies. The specific approach you choose, of course, should be determined based on your research question and how you wish to present the results.

**If I want to control for race/ethnicity, do I include dummy variables for all categories or eliminate one dummy variable as I would in regression? (In regression the eliminated category would become the reference group.) If I eliminate one dummy variable, how would I interpret the coefficient functions for my variables of interest? **

If you are testing the effects of a categorical variable with more than two categories (such as race/ethnicity), then you would include dummy variables as predictors in your model for all but one of the categories; the excluded category would serve as your reference group, just as in regression. For example, if you were estimating the prevalence of heavy episodic drinking (HED) across age and whether this differs between White, Black, and Hispanic individuals, you could include dummy variables for Black (versus not) and Hispanic (versus not) and allow both of them to have time-varying effects. In this model, the intercept function would be the age-varying prevalence of HED for the reference group (White), the effect of Black would be the age-varying difference in HED prevalence between Black and White (the reference group), and the effect of Hispanic would be the age-varying difference in HED prevalence between Hispanic and White. This approach permits hypothesis tests of group differences across continuous time.

Alternatively, the data could be separated by race/ethnicity and intercept-only models run within each subgroup. This approach facilitates visualization of the prevalence of HED as a function of time for each race/ethnicity group. See Evans-Polce, Vasilenko, & Lanza (2015) for an example that relied on estimating models separately for gender and for racial/ethnic groups.

Evans-Polce, R. J., Vasilenko, S. A., & Lanza, S. T. (2015). Changes in gender and racial/ethnic disparities in rates of cigarette use, regular heavy episodic drinking, and marijuana use: Ages 14 to 32. *Addictive Behaviors,* *41*, 218-222.

**Can TVEM be used when the predictor (i.e., independent variable) does not change over time? How is it that a time-invariant variable (e.g., gender) can have a time-varying effect? **

Although it may seem counterintuitive, a variable that does not vary over time can have effects that do vary over time. This is perhaps easiest to think about when we consider intervention effects. In a randomized controlled trial, a person typically is assigned either to a control group or an intervention group, and their assignment does not change. But the difference between the control and intervention groups–or the treatment effect–can vary over time. This variation is a time-varying effect. For example, the treatment may be more effective early in the trial (producing a larger effect) but become less effective as time goes on.

**How is TVEM different from multilevel modeling? **

Multilevel modeling (MLM), as traditionally used, is a tool that (a) adjusts standard errors to account for the clustering of repeated observations within individuals and (b) partitions the variance in an outcome into between-person variance (the degree to which people differ from each other on average) and within-person variance (the degree to which people differ from themselves over time). MLM allows researchers to model the effects of predictors at both levels. Although one very common use of MLM is the analysis of repeated measures, this approach typically does *not* allow associations between variables to vary with time. For example, in a smoking cessation trial in which individuals are assessed repeatedly after a quit attempt, in MLM the association between negative affect and nicotine craving typically would be assumed to be a constant effect across the entire time interval. TVEM allows analysts to explore the possibility that associations do in fact change as flexible functions of time, and that the shape of change over time may be highly complex. Lanza et al. (2014) demonstrates TVEM to estimate the time-varying association between negative affect and craving as a function of time since smoking quit attempt. Vasilenko et al. (2014) examined data from the same smoking study and provides a direct comparison between MLM and TVEM to analyze the data.

Lanza, S. T., Vasilenko, S., Liu, X., Li, R., & Piper, M. (2014). Advancing the understanding of craving during smoking cessation attempts: A demonstration of the time-varying effect model. *Nicotine and Tobacco Research, 16 Suppl 2*, S127-S134. doi: 10.1093/ntr/ntt128 PMCID: PMC3977629

Vasilenko, S. A., Piper, M. E., Lanza, S. T. Liu, X., Yang, J. & Li, R. (2014). Time-varying processes involved in smoking lapse in a randomized trial of smoking cessation therapies. *Nicotine and Tobacco Research*, *16*, S135-S143. doi: 10.1093/ntr/ntt18. PMCID: PMC3977637

**How do I know if I have selected the optimal number of knots? **

The knots in a TVEM determine the complexity of each coefficient function; a greater number of knots allows the function to be more complex, whereas a smaller number of knots leads to a smoother function. Selecting the number of knots in TVEM requires that a balance be struck between model fit (more knots allows the function to more flexibly match the data at hand) and parsimony (fewer knots leads to a more parsimonious solution that may be more likely to replicate in other random samples). TVEM estimation relies on either B-Spline or P-spline basis functions; depending on which estimation approach the user chooses, model selection may be done automatically or may need to be done manually. For P-spline estimation, the model automatically selects the optimal number of knots based on the minimum Bayesian information criterion (BIC). For B-spline estimation, the user must run a series of models, varying the number of knots for each coefficient function one at a time, and select the model with the lowest Akiake information criterion (AIC) and/or BIC. See Shiyko et. al., (2012) for an empirical example showing the selection of knots based on the B-spline approach.

Shiyko, M. P., Lanza, S. T., Tan, X., Li, R., & Shiffman, S. (2012). Using the time-varying effect model (TVEM) to examine dynamic associations between negative affect and self confidence on smoking urges: Differences between successful quitters and relapsers. Prevention Science*, 13, *288-299. PMCID: PMC3372905 doi: 10.1007/s11121-011-0264-z

**What are B-splines and P-splines, and how do I know which one to use?**

B-spline requires model selection and the curves tend to be more detailed, with less smoothing. Computationally, this approach is more stable. In contrast, P-splines have a smoothing parameter, so model selection is not needed. P-splines can over-smooth as a consequence, and detail can be lost. (See Tan et. al. (2012) for technical details of the P-spline approach.) Also, the P-spline approach is computationally more intensive and thus can take longer to run. The appendix of the TVEM users’ guide (Li et al., 2017) provides technical details for both B-spline and P-spline estimation.

Li, R., Dziak, J. J., Tan, X., Huang, L., Wagner, A. T., & Yang, J. (2017). *TVEM (time-varying effect model) SAS macro users' guide *(Version 3.1.1). University Park: The Methodology Center, Penn State. Retrieved from http://methodology.psu.edu

Tan, X., Shiyko, M., Li, R., Li, Y., & Dierker, L. (2012). A time-varying effect model for intensive longitudinal data. *Psychological Methods, 17*(1), 61-77. doi:10.1037/a0025814 PMCID: PMC3288551