# Confused about what is fixed and what is random in my dataset

I am a graduate student and quite new to the concept of linear mixed effects analysis. I have a longitudinal data with repeated measurements, which was collected every three years for more than 20 years. Apart from my (continuous) outcome variable, I have variables that I wanted to look at to estimate their effect on the outcome variable. I did some reading prior to starting my analysis in R (linear mixed models) and defined some variables: age, sex, BMI, smoking pack years etc... as fixed effects. Based on my rather limited understanding, a fixed effect is something that is expected to have a systematic and predictable effect on the data hence I believed the above mentioned variables fitted that category.

Secondly, there are the random effects which I believe are expected to have a random and unpredictable effect on the data. One rather conspicuous candidate for this is the subject ID (coded differently for each subject).

In relation to this, I have difficulties in proceeding further as there are some doubts as what qualifies as what. Here are two of my major questions:

1. There is a variable called time which is defined in relative to the first time point of data collection, specifically the year. For example, for subject no 1 who has a measurement every three years starting from the baseline year in 1988 (follow-up years 1991 and 1994), the variable is defined as 0,3 and 6 respectively (for 1988,1991 and 1994). Similarly, for other participants some follow up measures are NA (missing). Thus, to reuse the example above, the years where data is available might be 1988 and 1994 and time will then be coded as 0 and 4 respectively. I believe this variable (time) is integral in telling the model to take into account the changing status of certain variables but I am lacking the theoretical standing relating to this. Is this a proper approach? Will the linear mixed model inherently take variability into consideration without telling it to account for time?

2. Regarding certain variables, e.g. sex and age, is it also proper to simultaneously treat them as random? Or is this totally subjective based on the researcher? In my understanding, the sampled population in the data doesn't completely take this into consideration (the obvious one being that not all men and women are in the dataset - and the same applying to age) which makes me think that this nuanced randomness qualifies them as random effects too.

Please help me in any way, shape or form regarding this. Any suggestion is welcome and I will add details/clarifications to questions posed (if necessary).

Thanks!

The quick answer is that (1) you must put in time and (2) you don't need the other variables to be 'random' by design (e.g., 50/50 men and women) to use them successfully in regression.

But I think a big part of your question shows you you are struggling with the basic ideas.

In regression, what we have are dependent and independent variables, not random and fixed ones. Independent variables are the 'inputs' - like sex, age, packs per day, etc. What you are trying to do is 'fit' or 'predict' the dependent variable. So, for example, you may want to see if you can predict the incidence of lung cancer given all the independent variables.

Let's suppose all you have is what is called cross-sectional data. This means only one set of readings, at one time, for all people in the study. Then you would see if you could find a linear formula that gave the 'best' fit, in the form of an equation like so:

$cancerrate = c+a_1\cdot age+a_2\cdot yearssmoking + a_3\cdot sex+...$

Now, things like age and years_smoking would be numbers. Sex you would use a dummy variable for: 0 for male, 1 for female. Then, once you have a regression, you can 'predict' the likelihood of cancer for new people by plugging in their values with the $c$ and $a_i$'s that you get from the regression.

What you are wandering into is called time-series regression, however. The concept for time-series data is the same. However, it is much more subtle and complicated. In cross-sectional data there aren't many 'philosophical' issues, but there are with time series. For example, you have the relative year at which observations were made, as well as the calendar year. Should you use one or the other, or both? My gut tells me (based on your description) that you would use relative year. However, suppose one of the effects might be that new drugs were introduced in some calendar year that made it easier to quit smoking. If that were true, then calendar year probably matters more.

But there is more to worry about with time series. Roughly speaking, with cross-sectional data, throwing more variables in is not a problem (though it can be). This is much more problematic with time-series: a big problem with time-series is colinearity. Suppose people were followed over 20 years, with data taken every year, but that every subject started in 1995, 1996, or 1997. The calendar year and relative year are almost the same thing, and you probably need to choose. If you don't, you can get problems because the regression can't cleanly assign impact to two variables that move in lock step.

Another issue that you are not seeing right away is if certain independent variables themselves should work the same over time or might 'move around'. Most likely you want the simpler model, where the effect does not change with time. It is a very different problem if, for example, an increase of a pack a day of smoking increases your risk by 10% for each pack for all time, versus that holds true for the first 10 years, but then it changes to 20% after 10 years.

Here is a subtle one: age. In fact, if you have either relative year or calendar year, you probably don't want to include age in each reading. Why? Collinearity. But, you could include year of birth (or age today, neither of which will change from observation to observation). If all works well, that will capture the true age effect.

The problem you are working with, by the way, is called a panel data problem. The techniques are complex and sophisticated to get these right, since a lot of things are moving around at once. I am trying to give you a brief intro to it, so sorry to be so wordy.

So, were I you, here is what I would do:

1) I would identify anything I think might matter - age, sex, weight, consumption, etc. - and put them in, using dummy variables for things like sex.

2) I would decide if calendar year (2015, 2016,...) or relative year (0, 1, 2,..) seems more sensible and put that in

3) I would try to run it and see how good a model you get

4) I would then, if it made sense, fiddle with the time variable (if you used calendar year, try relative and see what happens). Ideally it comes out the same, and you are golden.

Make sense?

• Thank you for the reply. It does certainly help in understanding the key elements and the care I must take going forward. Commented Oct 17, 2017 at 20:10
• It is a bit of art that goes into these, often trial and error. Good luck. Commented Oct 18, 2017 at 1:55