This document tests the reporting functions created by Alex Danvers for printing APA-style results when using lmerTest.
# load the required libraries
library(lmerTest)
## Loading required package: Matrix
## Loading required package: lme4
##
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
##
## lmer
## The following object is masked from 'package:stats':
##
## step
library(piecewiseSEM)
# load the custom functions I wrote
source("~/Dropbox/R Resources/lmerT_reporting_functions.R")
source("~/Dropbox/R Resources/sim.ml1_func.R")
This generates data with a single continuous predictor and single continuous outcome.
# the first number is measures per cluster, second is number of clusters
test.dat <- sim.ml1(10,30)
int.only <- lmer(y ~ 1 + (1|id), data=test.dat)
fixed.x <- lmer(y ~ x + (1|id), data=test.dat)
random.x <- lmer(y ~ x + (x|id), data=test.dat)
# model comparisons
comp1 <- anova(int.only, fixed.x)
## refitting model(s) with ML (instead of REML)
comp2 <- anova(fixed.x, random.x)
## refitting model(s) with ML (instead of REML)
We found that a model using x as a predictor fit the data significantly better than an intercept-only model (\(\chi^2\) (1) = 312, p < .001). We then tested whether treating the predictor x as a random effect significantly improved model fit. We found that it did (\(\chi^2\) (2) = 258.27, p < .001).
In the fixed effects model, x was a statistically significant predictor (b = 0.64, t (289.08) = 23.65, p = < .001). It was also significant in the random effects model (b = 0.68, t (8.98) = 5.5, p = < .001).