I am using linear mixed-effect model (run with the
lme() function in the
nlme package in R) that has one fixed effect, one random intercept term (to account for groups) and an AR(1) correlation structure to account for temporal autocorrelation. The model is a cubic polynomial model specified as so:
d2 = df$iv^2 d3 = df$iv^3 M1 = lme(dv ~ iv + d2 + d3, data=df, random= ~1|group, method="ML", correlation = corAR1(form =~iv|group))
Unfortunately, the fitted values from this model do not give me a nice smooth curve (instead I get what looks like a number of joined straight-line segments).
I have searched for a way to make the curve look smoother (less disjointed) and have found that the
bs() function returns slightly smoother curves. From my understand, the
bs function fits polynomial splines. I am firstly wondering whether the use of B-splines from
bs() is technically correct within a linear mixed-effects model? If so, why do the fitted values differ between the two approaches when
bs also seems to use cubic polynomials as a default?
M2 = lme(dv ~ bs(iv, df=5), data=df, random= ~1|group, method="ML", correlation = corAR1(form =~iv|group))
Any advice would be much appreciated!