1
$\begingroup$

I am modelling a longitudinal dataset consisting of a continuous response variable (mutation count) with a binary predictor (medical history, ie previous medications) while accounting for time and each individual with fixed effects.

My aim is to measure the extent to which the health measures can predict mutation prevalence. Due to non-normal distributions in mutation counts, I am using a generalized linear mixed model. In a related question (below), that notes the problems of using a log transformed response variable, I was wondering what are some issues to be aware of if a log transformed random/fixed effect, in my case, time, is used? I only ask because when time is log transformed, I get significantly better model fit values that don't effect the distribution of residuals.

My model in lme4 is:

glmer(Mutations ~ Medication + (1 | TimeLog) + (1 | Sample), 
      data = inputdata, family = Gamma(link = "log"))

Linear model with log-transformed response vs. generalized linear model with log link

$\endgroup$
5
  • 1
    $\begingroup$ If your outcome variable, Mutations, is a count, why not use a glmer with poisson family and log link? The Gamma distribution is typically used in situations where the outcome variable is continuous rather than a count. See this link for a nice discussion - albeit in the context of glm rather than glmer models - on when to use the Gamma distribution: stats.stackexchange.com/questions/67547/when-to-use-gamma-glms. $\endgroup$ Commented Sep 6, 2019 at 23:45
  • $\begingroup$ The random grouping factors in a glmer model such as yours - namely, TimeLog and Sample - should both be categorical variables. However, TimeLog is a continuous variable so it is incorrect to use it as a random grouping factor as you have done through the (1|TimeLog) term. You may consider posting a separate question on this forum about the correct specification of your model given your study design and research questions. $\endgroup$ Commented Sep 6, 2019 at 23:51
  • $\begingroup$ Thank you for the link and info. It is my understanding that although using continuous random effects is not typical, it is not incorrect (link below). Regardless, assuming the model met your specifications, what about my question regarding log transformation? cell.com/trends/ecology-evolution/fulltext/… $\endgroup$
    – user250071
    Commented Sep 7, 2019 at 0:15
  • $\begingroup$ Let me read the article you suggested. $\endgroup$ Commented Sep 7, 2019 at 1:41
  • $\begingroup$ In order to help narrow the focus, please just apply the question of how a log transformed fixed/random effect would impact a log-linked model to a model that meets your specifications. $\endgroup$
    – user250071
    Commented Sep 9, 2019 at 20:14

2 Answers 2

2
$\begingroup$

I sense two areas of confusion here.

One is the logarithmic data transformation of predictor variables (like mapping Time to TimeLog) versus the logarithmic link function used in the generalized linear model. The former has to do with the predictor variables, the second with the response variable and its relationship to the linear part of the model.

In ordinary least-squares linear regression, it is standard practice to transform predictor variables as necessary to meet desirable characteristics like linearity, constant variance of the residuals between predictions and observed outcome values, and so on. So a log transform of time (as a predictor variable) might be called for regardless of the type of linear model you are pursuing. The linear regression provides, for any case of interest, a single linear predictor that is a linear combination of all the (potentially transformed) predictor-variable values for that case.

A generalized linear model allows such linear modeling of outcome variables that might not be adequately handled without further transformation of a linear predictor, which in principle could provide predicted values over all of $(-\infty,\infty)$. The link function in a generalized linear model has to do with mapping between the linear predictor and the response variable; it doesn't directly care whether the original predictor variables were somehow transformed before they were combined into the overall linear predictor. So from that perspective you don't have to worry.

The second area of confusion is in your formulation of the generalized linear mixed model. As Isabella Ghement and Dimitris Rizopoulos have both mentioned, there are two problems here. First, unless you are dealing with such large numbers of mutations that they effectively have a continuous distribution, count data should be modeled as count data with Poisson or negative-binomial generalized linear models. Second, the way you have treated your time variable as a random effect (you say "fixed effects" in the question but you evidently meant "random effects" from the formulation of your model) would only rarely make sense. Please make sure that you fully understand the implications of treating time as a random effect in the way that you have, as others have noted. Did you perhaps intend to treat time as a fixed effect but with a different slope versus time for different individuals? If so, please consult the lmer cheat sheet for the correct way to code that.

In response to comment:

The best way to capture a change of Mutations with Time is to include Time as a fixed effect. (Including Time, however transformed, as a random effect as in your model doesn't accomplish that in any useful way that I see.) The regression coefficient for Time then gives a direct measure of the rate of increase of Mutations with Time. (For simplicity, I'm assuming Mutations to increase linearly over Time, and ignoring for now the link function of the generalized model.) Your model doesn't presently include a fixed effect for Time in any way.

If you think that Medication will affect the rate of increase of Mutations with Time, as opposed to simply affecting the number of Mutations at Time=0, then you need also to include an interaction term between the two fixed effects of Mutations and Time. The intercept of the model (under default R handling) is then the value of Mutations at Time=0 for whatever Medication you have specified as the reference category.

Your (1|Sample) term then allows that intercept to differ among Samples. For the rate of change of Mutations also to differ among Samples (beyond any effects due to Medication differences among samples), add a term involving (Time|Sample). That's precisely how the web page you linked in your comment allowed Time to contribute to a random effect term even though it is a fixed effect. This answer on the lmer cheat sheet shows how to specify such a term depending on the assumptions that you are willing to make.

$\endgroup$
3
  • $\begingroup$ Great explanation, thank you! $\endgroup$
    – user250071
    Commented Sep 10, 2019 at 18:23
  • $\begingroup$ As per the time variable, it is an important variable to include in the model as this data set mutations accumulate with time. I am attempting to allow for the intercepts to change with time, not the slopes. Using a variable as a fixed effect as well as a random effect is from what I gather not out of the ordinary. This is not my area of expertise, but, what about this explanation here? theanalysisfactor.com/mixed-models-predictor-both-fixed-random $\endgroup$
    – user250071
    Commented Sep 10, 2019 at 18:36
  • $\begingroup$ @user250071 I had more to add than would fit into a comment, so I expanded the answer. What I added is all about forming the linear predictor of a mixed model, not about its "generalized" aspect. I'd recommend getting someone local who has statistical expertise involved in the project, as formulating (generalized) mixed linear models is often not straightforward. You want to make sure that the model that you write actually tests the hypothesis that you want to test. $\endgroup$
    – EdM
    Commented Sep 10, 2019 at 19:59
3
$\begingroup$

As Isabella Ghement also mentioned in her comments, it seems that you have a count variable. Hence, you could instead try fitting a Poisson or negative binomial mixed effects model. Both typically specify a log link function, resulting in the same type of model for the mean as the one you specify with the Gamma mixed model. In some implementations, such as in the GLMMadaptive package I have written, these models can also work with non-integer outcomes.

Moreover, to evaluate the fit of GLMMs it is most often better to use the simulated residuals provided by the DHARMa package.

Finally, you have not explained what variable TimeLog is, but note that by including a random intercept for it implies that measurements at the same level of TimeLog are correlated. If this is time, it means that measurements at the same time point, and even though may come from different sample units (e.g., subjects/patients) are correlated. Often this is not a plausible assumption.

$\endgroup$
1
  • $\begingroup$ TimeLog is the log transformed time measurement. Again, while I appreciate your general input regarding this model, my question only concerns the pros/cons of having a log transformed fixed/random effect when using a log-linked model and not the areas you specified. I am wondering if it will be akin to log transforming an already log transformed variable or something. If the above model is not satisfactory, then apply the same question to a model that you believe is. Do you have any thoughts on this? I cannot find too much information on it in general. $\endgroup$
    – user250071
    Commented Sep 9, 2019 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.