1
$\begingroup$

I have a dataset which has repeated measures for each subject. And the linear-mixed effect model doesn't work well for the dataset. I want to know if there is any smoothing methods (e.g. splines) that works for longitudinal data such that I can find the function to fit the data?

$\endgroup$
5
  • 2
    $\begingroup$ I think you need to provide more information about your data and analysis. $\endgroup$
    – T.E.G.
    Feb 12, 2017 at 16:11
  • 1
    $\begingroup$ have a look at the mgcv r package (with uses nlme) or gamm4 (which uses lme4): both allow mixed-effect spline models $\endgroup$
    – user20650
    Feb 12, 2017 at 19:41
  • $\begingroup$ @user20650 is it possible to get the actual function form for the splines fitted by these packages? $\endgroup$
    – J. Zhu
    Feb 12, 2017 at 20:20
  • $\begingroup$ I dont know.. For natural cubic splines you will be able to pull out the basis, but for smooth splines Im less sure, as they dont use knots. Either way i dont really see how useful the function would be. But to get an answer from someone who knows more than me, you could ask a new question, although its probably better placed at stackoverflow.com/questions/tagged/r. If you ask be sure to add an example to your question (say using an example from ?mgcv::gam) $\endgroup$
    – user20650
    Feb 12, 2017 at 21:27
  • $\begingroup$ There is good documentation for the mgcv package. If you read the help files you will find references to papers. It would be good to know more about what you man when you say "doesn't work well for the dataset", and why you have jumped to splines. $\endgroup$
    – Tim
    Feb 21, 2017 at 4:17

2 Answers 2

3
$\begingroup$

A fundamental method that can be used with any regression model without extra code is that of B-splines.

In these methods, a single covariate is expanded into higher dimensions such that a piece wise polynomial with max degree - 1 continuous derivatives at the knots. Typical usage is a cubic spline, meaning the first and second derivative at the knots are continuous, but the 3rd derivative is allowed to change.

To help illustrate the parameter expansion, I will use an overly simplified example. Suppose we had a covariate in which we wished to fit a piece-wise linear fit with a single knot at 1 for a covariate $x$. Then we could expand $x$ into two new variables; $x^-$ and $x^+$. If $x_i < 1$, then we can set $x_i^- = x_i$ and $x_i^+ = 0$. If $x_i \ge 1$, we set $x_i^- = 1$ and $x_i^+ = x_i - 1$. (Note: this is actually a simplification of what's really done; transformations are performed on the expanded variables to lead to more numeric stability. See De Boor's algorithm if you're really interested). Note that the new fitted model will be continuous in $x$ but allows for different slopes above and below 1.

And most relevantly to this question, note that we have done nothing to the actual regression model itself (i.e. no adding penalties to the likelihood, etc.). So you can expand your parameter space and then plug directly into your regression model.

In R, it's really easy to use B-splines; you just call bs(x,...) in the formula for any regression model. But I suggest reading up on the help file to understand all the options.

Here's a simple example using linear regression. We could easily switch out lm for any other regression model.

library(splines)
x <- sort( rnorm(1000) )  
# sorting just for plotting purposes
y <- sin(x) + rnorm(1000, sd = 0.1)
bspl_fit <- lm(y ~ bs(x, df = 10))
plot(x, y)
lines(x, sin(x), col = 'blue', lwd = 2)
lines(x, predict(bspl_fit), col = 'red', lwd = 2)
legend('topleft', c('True', 'Spline Fit'),
   lwd = 2, col = c('blue', 'red'))

SplineFit

$\endgroup$
6
  • $\begingroup$ Thank you for your reply. The B-splines will work for longitudinal data as well? $\endgroup$
    – J. Zhu
    Feb 12, 2017 at 16:21
  • $\begingroup$ @J.Zhu: B-splines will work with any regression model. So if you are using a regression model for longitudinal data (i.e. random intercept and random slopes) you can expand the covariate space and use B-splines. $\endgroup$
    – Cliff AB
    Feb 12, 2017 at 16:24
  • $\begingroup$ So if I write this in R using lmer, I just need to change my covariates to the basis I have? $\endgroup$
    – J. Zhu
    Feb 12, 2017 at 16:27
  • $\begingroup$ Great post on splines, bu seems OP's question is repeated measure and longitudinal data. $\endgroup$
    – Haitao Du
    Feb 12, 2017 at 16:38
  • $\begingroup$ @hxd1011: the OP asked for smoothing methods that can be applied to longitudinal models. B-splines can be applied to any regression model, including longitudinal/repeated measure regression models (i.e. mixed effects models). $\endgroup$
    – Cliff AB
    Feb 12, 2017 at 16:55
0
$\begingroup$

It is several years later, but the R package sme developed by Maurice Berk can do a very good job. https://rdrr.io/cran/sme/f/inst/doc/Tutorial.pdf

Also the initial.lambda.mu and initial.lambda.v values should be correctly selected for your data.

devtools::install_github("mberk/sme")
library(sme)
data(MTB)
fit <- sme(MTB[MTB$variable==6031,c("y","tme","ind")],criteria="AIC")
plot(fit,type="model",xlab="Hour",ylab="Gene Expression")

Also look over Maurice Berk thesis for additional information.

$\endgroup$

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.