# LOESS using predicted means from a linear mixed model

What aspects do I need to consider when plotting a smooth curve with the LOESS method (geom_smooth) using predicted means from a linear mixed model? My data consists of longitudinal psychological scale scores across 12 timepoints. I treated the timepoints as 12 separate levels of a factor.

I hope to show how psychological symptoms fluctuate during a period. In my data, for example, using the smooth curve (LOESS), one type of these symptoms reduced, but another initially decreased and posteriorly increased. Furthermore, I hope to handle the missing data. When I ran a smooth considering all data, the confidence intervals were very high, seem an imprecise model due to my considerable missing data. I used LOESS due to a low number of observations since I considered the predicted means from LMM of each time point (the time points were treated as factor levels). Would be very important to my data analysis the graphical representation of these symptoms.

• Welcome to Cross Validated! How did you handle the 12 timepoints in your model: did you treat them as 12 separate levels of a factor, or did you model time as some continuous function, for example as a regression spline? Please provide that information by editing the question, as comments are easy to overlook and can be deleted.
– EdM
Mar 6 at 21:02
• Thanks! Edited.
– ACOM
Mar 6 at 21:26

The overall idea of using modeled mean values based on the fixed-factor values to illustrate experimental results is fine. That's what the R emmeans package is designed to do, for example. The question is how to display your confidence intervals, which doesn't work well with a loess fit to all the raw data.

One way to proceed could be to show the confidence intervals for the modeled outcome at each time point along with a piecewise-linear display (or perhaps a smooth loess fit) based on the point estimates.

It might be better if you could re-do the modeling with a smooth continuous treatment of time, instead of separately modeling each time point. Chapter 7 of Frank Harrell's Regression Modeling Strategies recommends regression splines along the time axis for longitudinal data. That gives you a pre-smoothed parametric estimate over time with corresponding confidence intervals, and can save you several degrees of freedom versus your 12-level categorical treatment of time. Unless you have reason to believe that there will be discontinuous jumps in outcome between time points, that might represent your results in an even better way.

• Let me know if I understand correctly. A better representation could be to plot the estimated points and their confidence intervals (using the ggeffect function, for example) along with a smooth curve fitted using LOESS (for this curve, I utilized the geom_smooth function)? In my data, the time points might be associated with significant variations, so I chose to treat them as a factor.
– ACOM
Mar 7 at 15:35
• @MarcosO.C.Alves if you really think that individual "time points might be associated with significant variations" then it might not be a good idea to do any smoothing at all. Plot the modeled point estimates and confidence intervals, and if anything connect adjacent points in time with straight lines. Whether you do parametrically modeled smoothing with a spline or nonparametric smoothing with loess, you are assuming that there aren't rapid jumps between time points and that the individual time-point values just represent sampling from a smooth distribution across time.
– EdM
Mar 7 at 17:18
• Maybe I didn't express myself well. More specifically, my outcome variable is related to the pandemic period (number of cases), which has evolved in waves. That's why the idea of using some smoothing method to represent it.
– ACOM
Mar 7 at 17:27
• @MarcosO.C.Alves then you should be able to do smoothing as part of the model itself, typically with a regression spline in time. That should give you much tighter confidence intervals for the modeled estimates than a loess fit (even if you could figure out a way to do loess appropriately with your data set). Regression splines and loess both do smoothing over time. If loess smoothing is appropriate so is a regression spline, which in turn provides some advantages over the nonparametric loess.
– EdM
Mar 7 at 17:52