1
$\begingroup$

I've been working on a longitudinal study using a linear mixed-effects model in R. I wonder if there is any way to visualize the results of the linear mixed-effects model. The problem in my situation is both independent and dependent variables are continuous (there is no group in independent variables)

Here, A is the continuous dependent variable and B is the continuous independent variable. There are multiple records for each patient on different dates, which makes it a longitudinal study. I want to figure out the relationship between A and B.

model: lmer(A~B+date|patient_number)

result:

enter image description here

Is there any way to visualize it?

Edit: I fitted another model and I got this.

Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: 
**A ~ B + date +  
    (1 | pNo)**
   Data: brain

REML criterion at convergence: 7140.8

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.8742 -0.5168 -0.0050  0.5118  2.5005 

Random effects:
 Groups   Name        Variance Std.Dev.
 pNo      (Intercept) 23745881 4873    
 Residual             21276522 4613    
Number of obs: 355, groups:  pNo, 150

Fixed effects:
                            Estimate Std. Error      df t value
(Intercept)                  26800.3     3473.9   220.1   7.715
B                            22471.3     3786.1   350.2   5.935
date                         -390.2       50.2   246.2  -7.773
                            Pr(>|t|)    
(Intercept)                 4.17e-13 ***
B                           7.06e-09 ***
date                        2.08e-13 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
abbreviate used with non-ASCII chars               (Intr) B
B             -0.532       
date         -0.865  0.057

And I plotted the qqplot, which was a straight line.

And I tried to draw an effect plot, but I don't really know how to interpret it. enter image description here

enter image description here

$\endgroup$
6
  • 1
    $\begingroup$ Please provide more details, otherwise the question may be closed. Please include the model formula and the output of summary(mymodel) $\endgroup$ Aug 11 at 8:06
  • 1
    $\begingroup$ Which of the many results of this model do you want to visualize, for what purpose, and with what audience in mind? $\endgroup$
    – whuber
    Aug 11 at 14:08
  • $\begingroup$ A~B+date|patient_number is not a valid model formula. Are you sure you didn't mean A ~ B + (date|patient_number) $\endgroup$ Aug 11 at 14:39
  • $\begingroup$ Yes that what I meant. Sorry for the confusion $\endgroup$
    – kellyohhhh
    Aug 11 at 21:55
  • 2
    $\begingroup$ Please visit stats.stackexchange.com/help/merging-accounts to combine your accounts so you can edit your question. Please also take a couple of minutes to read over our help center to learn about asking and editing questions here. $\endgroup$
    – whuber
    Aug 12 at 13:08
1
$\begingroup$

This model has not converged, so there is no point whatsoever in trying to interpret it, or visualise it. Note the warning: Model failed to converge

The model formula:

 A~B+date|patient_number

is not a valid formula for a mixed model. Perhaps you mean:

A ~ B + (date | patient_number)

and I will assume that this is the case, since that's what the output seems to indicate.

So one problem is that you are fitting random slopes for date, but you do not fit this as a fixed effect. This means you are assuming that the overall "effect" of date is zero. This is hardly ever what you want. Insead try this:

A ~ B + date + (date | patient_number)

this way the model estimates an overall effect of date, and allows each patient to have a (normally distributed) offset to that.

If this still doesn't converge then try fitting it without a correlation bwteeen the random slopes and intercepts. This can be achieved with:

A ~ B + date + (date || patient_number)

which is just shorthand for:

A ~ B + date + (0 + date | patient_number) + (1 | patient_number)

(the first random effect term specifies the random slopes for date over patient_number but without random intercepts, and the second term fits the random intercepts for patient_number, the net result being random slopes and intercepts that are not correlated). If this still does not converge then you may need to remove the random slopes altogether. If that does not work then I would suggest asking a question about why it won't converge.

As for visualisation, once you have a fitted model that has converged to a non-singular result, then you have a kot of options depending on what information you think is important that you want to relay to the reader. I would suggest fixing the convergence problems, and then ask a new question, making sure that you include all the output (please post the text not the picture next time), along with what information you want to visualise.

Edit:

I see that you have posted another question which has been closed as a duplicate:
Visualize results of linear mixed effects model of a longitudinal study in R

Looking at the output there:

Random effects:
 Groups   Name           Variance  Std.Dev.  Corr 
 pNo      (Intercept)    2.210e+07 4.701e+03      
          date           2.691e-03 5.187e-02 -1.00

Notice that the variance of the random intercepts is estimated as 10 orders of magnitude larger than the variance of the random slopes. This is a strong indication that the correlated random slopes are unnecessary and not supported by the data. So remove the correlation as I mentioned above and if that doesn'ty work then remove the slopes altogether.

$\endgroup$
1
  • $\begingroup$ Thanks for the reply! I changed my model. I eddited my question ! $\endgroup$
    – kellyohhhh
    Aug 16 at 1:06

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