Skip to content

Commit

Permalink
Add (undocumented) 'df' argument to anova().
Browse files Browse the repository at this point in the history
  • Loading branch information
wviechtb committed May 31, 2024
1 parent 252122b commit c805881
Show file tree
Hide file tree
Showing 121 changed files with 207 additions and 179 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: metafor
Version: 4.7-12
Version: 4.7-13
Date: 2024-05-31
Title: Meta-Analysis Package for R
Authors@R: person(given = "Wolfgang", family = "Viechtbauer", role = c("aut","cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-3463-4063"))
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# metafor 4.7-12 (2024-05-31)
# metafor 4.7-13 (2024-05-31)

- `rma.mv()` now counts the number of levels of a random effect more appropriately; this may trigger more often the check whether the number of levels is equal to 1, in which case the corresponding variance component is automatically fixed to 0; this check can be omitted with `control=list(check.k.gtr.1=FALSE)`

Expand Down
41 changes: 31 additions & 10 deletions R/anova.rma.r
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anova.rma <- function(object, object2, btt, X, att, Z, rhs, digits, refit=FALSE,

ddd <- list(...)

.chkdots(ddd, c("test", "L", "verbose", "fixed"))
.chkdots(ddd, c("test", "L", "verbose", "fixed", "df"))

if (!is.null(ddd$L))
X <- ddd$L
Expand Down Expand Up @@ -440,6 +440,10 @@ anova.rma <- function(object, object2, btt, X, att, Z, rhs, digits, refit=FALSE,

test <- .chkddd(ddd$test, "LRT", match.arg(ddd$test, c("LRT", "Wald")))

### get df value (NULL if not specified)

df <- ddd$df

### assume 'object' is the full model and 'object2' the reduced model

model.f <- object
Expand All @@ -452,12 +456,12 @@ anova.rma <- function(object, object2, btt, X, att, Z, rhs, digits, refit=FALSE,

### check if they have the same number of parameters

if (parms.f == parms.r)
if (is.null(df) && parms.f == parms.r)
stop(mstyle$stop("Models have the same number of parameters. LRT not meaningful."))

### if parms.f < parms.r, then let 'object' be the reduced model and 'object2' the full model
### if parms.f < parms.r, then let 'object' be the reduced model and 'object2' the full model (only do this if 'df' is not specified)

if (parms.f < parms.r) {
if (is.null(df) && parms.f < parms.r) {
model.f <- object2
model.r <- object
parms.f <- model.f$parms
Expand All @@ -470,20 +474,31 @@ anova.rma <- function(object, object2, btt, X, att, Z, rhs, digits, refit=FALSE,

if (inherits(object, "rma.uni")) {
if (!(identical(as.vector(model.f$yi), as.vector(model.r$yi)) && isTRUE(all.equal(as.vector(model.f$vi), as.vector(model.r$vi)))))
stop(mstyle$stop("Observed outcomes and/or sampling variances not equal in the full and reduced model."))
stop(mstyle$stop("The observed outcomes and/or sampling variances are not equal in the full and reduced model."))
}

if (inherits(object, "rma.mv")) {
if (!(identical(as.vector(model.f$yi), as.vector(model.r$yi)) && isTRUE(all.equal(as.matrix(model.f$V), as.matrix(model.r$V)))))
stop(mstyle$stop("Observed outcomes and/or sampling variances/covariances not equal in the full and reduced model."))
if (is.null(df)) {

if (inherits(object, "rma.mv")) {
if (!(identical(as.vector(model.f$yi), as.vector(model.r$yi)) && isTRUE(all.equal(as.matrix(model.f$V), as.matrix(model.r$V)))))
stop(mstyle$stop("The observed outcomes and/or sampling variances/covariances are not equal in the full and reduced model."))
}

} else {

if (inherits(object, "rma.mv")) {
if (!(identical(as.vector(model.f$yi), as.vector(model.r$yi))))
stop(mstyle$stop("The observed outcomes are not equal in the full and reduced model."))
}

}

### for Wald-type test, both models should be fitted using the same method

if (test == "Wald" && (model.f$method != model.r$method))
stop(mstyle$stop("Full and reduced model must use the same 'method' for the model fitting."))

### for LRTs, reduced model may use method="FE/EE/CE" and full model method="(RE)ML" but the other way around doesn't really make sense
### for LRTs, reduced model may use method="FE/EE/CE" and full model method="(RE)ML" but the other way around is not allowed

if (is.element(model.f$method, c("FE","EE","CE")) && !is.element(model.r$method, c("FE","EE","CE")))
stop(mstyle$stop("Full model uses a fixed- and reduced model uses a random/mixed-effects model."))
Expand All @@ -499,6 +514,7 @@ anova.rma <- function(object, object2, btt, X, att, Z, rhs, digits, refit=FALSE,
warning(mstyle$warning("LRTs should be based on ML/REML estimation."), call.=FALSE)

### for LRTs based on REML estimation, check if fixed effects differ

if (test == "LRT" && model.f$method == "REML" && (!identical(model.f$X, model.r$X))) {
if (refit) {
#message(mstyle$message("Refitting models with ML (instead of REML) estimation ..."))
Expand Down Expand Up @@ -586,7 +602,12 @@ anova.rma <- function(object, object2, btt, X, att, Z, rhs, digits, refit=FALSE,

if (test == "LRT") {

parms.diff <- parms.f - parms.r
if (is.null(df)) {
parms.diff <- parms.f - parms.r
} else {
parms.f <- parms.f + df
parms.diff <- df
}

if (model.f$method == "REML") {

Expand Down
2 changes: 1 addition & 1 deletion R/zzz.r
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.onAttach <- function(libname, pkgname) {

ver <- "4.7-12"
ver <- "4.7-13"

loadmsg <- paste0("\nLoading the 'metafor' package (version ", ver, "). For an\nintroduction to the package please type: help(metafor)\n")

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metafor: A Meta-Analysis Package for R
[![R build status](https://github.com/wviechtb/metafor/workflows/R-CMD-check/badge.svg)](https://github.com/wviechtb/metafor/actions)
[![Code Coverage](https://codecov.io/gh/wviechtb/metafor/branch/master/graph/badge.svg)](https://app.codecov.io/gh/wviechtb/metafor)
[![CRAN Version](https://www.r-pkg.org/badges/version/metafor)](https://cran.r-project.org/package=metafor)
[![devel Version](https://img.shields.io/badge/devel-4.7--12-brightgreen.svg)](https://www.metafor-project.org/doku.php/installation#development_version)
[![devel Version](https://img.shields.io/badge/devel-4.7--13-brightgreen.svg)](https://www.metafor-project.org/doku.php/installation#development_version)
[![Monthly Downloads](https://cranlogs.r-pkg.org/badges/metafor)](https://cranlogs.r-pkg.org/badges/metafor)
[![Total Downloads](https://cranlogs.r-pkg.org/badges/grand-total/metafor)](https://cranlogs.r-pkg.org/badges/grand-total/metafor)

Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/ISSUE_TEMPLATE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/pkgdown/diagram.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pkgdown: 2.0.9
pkgdown_sha: ~
articles:
diagram: pkgdown/diagram.html
last_built: 2024-05-06T14:02Z
last_built: 2024-05-31T10:15Z
urls:
reference: https://wviechtb.github.io/metafor/reference
article: https://wviechtb.github.io/metafor/articles
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/addpoly.default.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/addpoly.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/addpoly.predict.rma.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/addpoly.rma.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/aggregate.escalc.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c805881

Please sign in to comment.