Skip to content

Commit

Permalink
move testthat to 3rd ed. and update vignette with info on interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
JWiley committed Feb 10, 2023
1 parent d5bad11 commit 2e49dbb
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 172 deletions.
79 changes: 40 additions & 39 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
Package: multilevelTools
Title: Multilevel and Mixed Effects Model Diagnostics and Effect Sizes
Version: 0.1.3
Date: 2023-02-10
Authors@R:
person(given = "Joshua F.",
family = "Wiley",
role = c("aut", "cre"),
email = "jwiley.psych@gmail.com",
comment = c(ORCID = "0000-0002-0271-6702"))
URL: http://joshuawiley.com/multilevelTools, https://github.com/JWiley/multilevelTools
BugReports: https://github.com/JWiley/multilevelTools/issues
Description: Effect sizes, diagnostics and performance metrics for
multilevel and mixed effects models.
Includes marginal and conditional 'R2' estimates for linear mixed effects models
based on Johnson (2014) <doi:10.1111/2041-210X.12225>.
License: GPL (>= 3)
Depends:
R (>= 3.5.0)
Imports:
lme4,
lmerTest,
data.table (>= 1.12.0),
nlme,
extraoperators (>= 0.1.1),
JWileymisc (>= 1.1.0),
cowplot,
ggplot2,
lavaan,
zoo
Suggests:
testthat (>= 2.1.0),
covr,
knitr,
rmarkdown
Encoding: UTF-8
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 7.1.0
Package: multilevelTools
Title: Multilevel and Mixed Effects Model Diagnostics and Effect Sizes
Version: 0.1.3
Date: 2023-02-10
Authors@R:
person(given = "Joshua F.",
family = "Wiley",
role = c("aut", "cre"),
email = "jwiley.psych@gmail.com",
comment = c(ORCID = "0000-0002-0271-6702"))
URL: https://joshuawiley.com/multilevelTools, https://github.com/JWiley/multilevelTools
BugReports: https://github.com/JWiley/multilevelTools/issues
Description: Effect sizes, diagnostics and performance metrics for
multilevel and mixed effects models.
Includes marginal and conditional 'R2' estimates for linear mixed effects models
based on Johnson (2014) <doi:10.1111/2041-210X.12225>.
License: GPL (>= 3)
Depends:
R (>= 4.0.0)
Imports:
lme4,
lmerTest,
data.table (>= 1.14.6),
nlme,
extraoperators (>= 0.1.1),
JWileymisc (>= 1.4.0),
cowplot,
ggplot2,
lavaan,
zoo
Suggests:
testthat (>= 3.1.0),
covr,
knitr,
rmarkdown
Encoding: UTF-8
LazyData: true
Config/testthat/edition: 3
VignetteBuilder: knitr
RoxygenNote: 7.2.3
15 changes: 15 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# multilevelTools 0.1.3

## Bug Fixes

* `modelTest()` no longer fails for models with a continuous x categorical interaction.
Estimates for dropping the "simple" effect of the continuous variable are still
not calculable, but the rest of the calculations are still performed and that line
is simply set to NA.

## Changes

* moved to testthat 3rd edition
* moved CI to GitHub actions
* use preferably for package website

# multilevelTools 0.1.2

## New Features
Expand Down
15 changes: 11 additions & 4 deletions R/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,21 @@ modelTest.merMod <- function(object, method = c("Wald", "profile", "boot"), cont
objreduced <- testm[[i]]
v <- labs.levels$Terms[[i]]
nparreduced <- attr(logLik(objreduced), "df")

if (!isTRUE(inherits(objreduced, "merMod")) | nparreduced >= nparfull) {

if (nparreduced >= nparfull) {
msg <- sprintf("The full and reduced model had %d and %d parameters, respectively.\nThe reduced model should have fewer parameters.\nThis usually happens when there are interactions with categorical variables.\nFor an explanation, see:\nhttps://joshuawiley.com/multilevelTools/articles/lmer-vignette.html", nparfull, nparreduced)
message(msg)
tmp <- copy(NAtemplate)
} else {
tmp <- modelCompare(object, objreduced)$Comparison[3]

if (!isTRUE(inherits(objreduced, "merMod"))) {
tmp <- copy(NAtemplate)
} else {
tmp <- modelCompare(object, objreduced)$Comparison[3]
}
}
tmp$Model <- v

setnames(tmp, old = "Model", new = "Variable")
return(tmp)
}))
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ multilevelTools
===============

<!-- badges: start -->
[![Build
Status](https://travis-ci.com/JWiley/multilevelTools.svg?branch=master)](https://travis-ci.com/JWiley/multilevelTools)
[![Codecov test coverage](https://codecov.io/gh/JWiley/multilevelTools/branch/master/graph/badge.svg)](https://codecov.io/gh/JWiley/multilevelTools?branch=master)
[![CRAN_status](https://www.r-pkg.org/badges/version/multilevelTools)](https://cran.r-project.org/package=multilevelTools)
[![R-CMD-check](https://github.com/JWiley/multilevelTools/workflows/R-CMD-check/badge.svg)](https://github.com/JWiley/multilevelTools/actions)
[![codecov](https://codecov.io/gh/JWiley/multilevelTools/branch/main/graph/badge.svg?token=HK1Ns92mfB)](https://codecov.io/gh/JWiley/multilevelTools)
[![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
<!-- badges: end -->


Effect sizes, diagnostics and performance metrics for
multilevel and mixed effects models.
Includes marginal and conditional *R2* estimates for linear mixed
Expand Down
35 changes: 0 additions & 35 deletions tests/testthat/#test-styler.R#

This file was deleted.

54 changes: 27 additions & 27 deletions tests/testthat/test-descriptives.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ test_that("meanDecompose works with one grouping factor", {
expect_length(md, 2L)

## residuals are same as original data
expect_equivalent(nrow(md[[length(md)]]), nrow(mtcars))
expect_equal(nrow(md[[length(md)]]), nrow(mtcars))

## cyl means are equal to unique cyl
expect_equivalent(nrow(md[[1]]), length(unique(mtcars$cyl)))
expect_equal(nrow(md[[1]]), length(unique(mtcars$cyl)))

## residuals have mean about 0
expect_equivalent(mean(md[[length(md)]]$X, na.rm = TRUE),
expect_equal(mean(md[[length(md)]]$X, na.rm = TRUE),
0, tolerance = .05)
})

Expand All @@ -22,61 +22,61 @@ test_that("meanDecompose works with two grouping factors", {
expect_length(md, 3L)

## residuals are same as original data
expect_equivalent(nrow(md[[length(md)]]), nrow(mtcars))
expect_identical(nrow(md[[length(md)]]), nrow(mtcars))

## vs means are equal to unique vs
expect_equivalent(nrow(md[[1]]), length(unique(mtcars$vs)))
expect_identical(nrow(md[[1]]), length(unique(mtcars$vs)))

## vs by cyl means are equal to unique vs x cyl
expect_equivalent(nrow(md[[2]]), length(unique(paste0(mtcars$vs, mtcars$cyl))))
expect_identical(nrow(md[[2]]), length(unique(paste0(mtcars$vs, mtcars$cyl))))

## residuals have mean about 0
expect_equivalent(mean(md[[length(md)]]$X, na.rm = TRUE),
expect_equal(mean(md[[length(md)]]$X, na.rm = TRUE),
0, tolerance = .05)
})


test_that("iccMixed works with one grouping factor", {
icc <- iccMixed("mpg", "cyl", mtcars)

expect_equivalent(nrow(icc), 2)
expect_equivalent(
expect_identical(nrow(icc), 2L)
expect_equal(
sum(icc$ICC, na.rm = TRUE),
1, tolerance = .02)
})

test_that("iccMixed works with one grouping factor and data.table", {
icc <- iccMixed("mpg", "cyl", data.table::as.data.table(mtcars))

expect_equivalent(nrow(icc), 2)
expect_equivalent(
expect_identical(nrow(icc), 2L)
expect_equal(
sum(icc$ICC, na.rm = TRUE),
1, tolerance = .02)
})

test_that("iccMixed works with two grouping factors", {
icc <- iccMixed("mpg", c("cyl", "am"), mtcars)

expect_equivalent(nrow(icc), 3)
expect_equivalent(
expect_identical(nrow(icc), 3L)
expect_equal(
sum(icc$ICC, na.rm = TRUE),
1, tolerance = .02)
})

test_that("iccMixed works with two grouping factors and data.table", {
icc <- iccMixed("mpg", c("cyl", "am"), data.table::as.data.table(mtcars))

expect_equivalent(nrow(icc), 3)
expect_equivalent(
expect_identical(nrow(icc), 3L)
expect_equal(
sum(icc$ICC, na.rm = TRUE),
1, tolerance = .02)
})

test_that("iccMixed works with one grouping factor and binomial family", {
icc <- iccMixed("am", "cyl", mtcars)

expect_equivalent(nrow(icc), 2)
expect_equivalent(
expect_identical(nrow(icc), 2L)
expect_equal(
sum(icc$ICC, na.rm = TRUE),
1, tolerance = .02)
})
Expand All @@ -85,35 +85,35 @@ test_that("iccMixed works with one grouping factor and binomial family", {
test_that("nEffective works with data & gaussian (default) & data.frame", {
nk <- nEffective(dv = "mpg", id = "cyl", data = mtcars)

expect_equivalent(nrow(nk), 3)
expect_identical(nrow(nk), 3L)
expect_true(all(nk$N[1:2] <= nk$N[3]))
})

test_that("nEffective works with data & binomial & data.frame", {
nk <- nEffective(dv = "am", id = "cyl", data = mtcars, family = "binomial")

expect_equivalent(nrow(nk), 3)
expect_identical(nrow(nk), 3L)
expect_true(all(nk$N[1:2] <= nk$N[3]))
})

test_that("nEffective works with data & gaussian (default) & data.table", {
nk <- nEffective(dv = "mpg", id = "cyl", data = data.table::as.data.table(mtcars))

expect_equivalent(nrow(nk), 3)
expect_identical(nrow(nk), 3L)
expect_true(all(nk$N[1:2] <= nk$N[3]))
})

test_that("nEffective works with inputs & gaussian (default)", {
nk <- nEffective(n = 60, k = 10, icc = .6)

expect_equivalent(nrow(nk), 3)
expect_identical(nrow(nk), 3L)
expect_true(all(nk$N[1:2] <= nk$N[3]))
})

test_that("nEffective works with inputs & binomial", {
nk <- nEffective(n = 60, k = 10, icc = .6, family = "binomial")

expect_equivalent(nrow(nk), 3)
expect_identical(nrow(nk), 3L)
expect_true(all(nk$N[1:2] <= nk$N[3]))
})

Expand All @@ -122,9 +122,9 @@ test_that("meanDeviations works", {

expect_length(md, 2)

expect_equivalent(md[[1]], 5.5, tolerance = .1)
expect_equal(md[[1]], 5.5, tolerance = .1)

expect_equivalent(mean(md[[2]], na.rm = TRUE),
expect_equal(mean(md[[2]], na.rm = TRUE),
0, tolerance = .1)
})

Expand All @@ -141,7 +141,7 @@ test_that("acfByID works", {
ac <- acfByID("x", "time", "id", data = dat, lag.max = 10L)

## should have 10 + 1 rows for lag 0 to 10
expect_equivalent(nrow(ac), 10 + 1)
expect_equal(nrow(ac), 10 + 1)
## correlations so expect between +/- 1
## add .1 for tolerance
expect_true(all(ac$AutoCorrelation >= -1.1 & ac$AutoCorrelation <= 1.1))
Expand All @@ -150,7 +150,7 @@ test_that("acfByID works", {
ac <- acfByID("x", "time", data = dat, lag.max = 10L)

## should have 10 + 1 rows for lag 0 to 10
expect_equivalent(nrow(ac), 10 + 1)
expect_equal(nrow(ac), 10 + 1)
## correlations so expect between +/- 1
## add .1 for tolerance
expect_true(all(ac$AutoCorrelation >= -1.1 & ac$AutoCorrelation <= 1.1))
Expand All @@ -160,7 +160,7 @@ test_that("acfByID works", {
ac <- acfByID("x", "time", "id", data = as.data.frame(dat), lag.max = 10L)

## should have 10 + 1 rows for lag 0 to 10
expect_equivalent(nrow(ac), 10 + 1)
expect_equal(nrow(ac), 10 + 1)
## correlations so expect between +/- 1
## add .1 for tolerance
expect_true(all(ac$AutoCorrelation >= -1.1 & ac$AutoCorrelation <= 1.1))
Expand Down
Loading

0 comments on commit 2e49dbb

Please sign in to comment.