Description Usage Arguments Details Value Note Author(s) See Also Examples
creates a data set with Y ~ 30+cos(X)
for 10 subjects,
to compare restricted cubic spline in lmer
with the
spline of ols
.
1 | makeSplineData.fnc(intr=0)
|
intr |
integer denoting type of data set: with 0 a data set with simple spline is made, with 1 a data set with a parallel interaction, and with 2 a data set with a crossed interaction. |
Requires rms
package to be attached.
A data frame with as values:
y |
|
X |
ranges from 2 to 8.28 |
Subject |
random-effects factor with 10 levels |
Ranef |
subjects-specific changes to intercept |
Error |
by-observation noise |
Y |
the dependent variable, |
intended for illustration only
R. H. Baayen
See Also as plotLMER.fnc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ## Not run:
require("rms")
require("optimx")
require("lmerTest")
dfr = makeSplineData.fnc()
table(dfr$Subject)
xylowess.fnc(Y ~ X | Subject, data = dfr)
dfr.lmer = lmer(Y ~ rcs(X, 5) + (1|Subject), data = dfr,
control=lmerControl(optimizer="optimx",optCtrl=list(method="nlminb")))
dfr$fittedLMER = as.vector(dfr.lmer@X %*% fixef(dfr.lmer))
dfr.dd = datadist(dfr)
options(datadist='dfr.dd')
dfr.ols = ols(Y~Subject+rcs(X), data=dfr, x=T, y=T)
dfr$fittedOLS = fitted(dfr.ols)
# we plot the lmer() fit in blue, the ols() fit in red (both adjusted for
# subject S1), and plot the underlying model in green
plot(dfr[dfr$Subject=="S1",]$X, dfr[dfr$Subject=="S1",]$fittedLMER +
ranef(dfr.lmer)[[1]]["S1",], type="l", col="blue",
ylim = range(dfr$y + ranef(dfr.lmer)[[1]]["S1",],
dfr[dfr$Subject == "S1",]$fittedLMER,
dfr[dfr$Subject == "S1",]$fittedOLS), xlab="X", ylab="Y")
lines(dfr[dfr$Subject=="S1",]$X, dfr[dfr$Subject=="S1",]$fittedOLS, col="red")
lines(dfr[dfr$Subject=="S1",]$X, dfr[dfr$Subject=="S1",]$y+ranef(dfr.lmer)[[1]]["S1",],
col="green")
legend(2,29,c("30+cos(x)", "lmer (S1)", "ols (S1)"), lty=rep(1,3),
col=c("green", "blue", "red"))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.