Skip to content

Commit

Permalink
Pending version 1.10.4, awaiting CRAN opening
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlenth committed Aug 10, 2024
1 parent 5de4cc1 commit 86c7f31
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 24 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: emmeans
Type: Package
Title: Estimated Margin2l Means, aka Least-Squares Means
Version: 1.10.3-090006
Date: 2024-07-22
Version: 1.10.3099
Date: 2024-08-10
Authors@R: c(person("Russell V.", "Lenth", role = c("aut", "cre", "cph"),
email = "[email protected]"),
person("Ben", "Bolker", role = "ctb"),
Expand All @@ -18,8 +18,8 @@ Authors@R: c(person("Russell V.", "Lenth", role = c("aut", "cre", "cph"),
Depends: R (>= 4.1.0)
Imports: estimability (>= 1.4.1), graphics, methods, numDeriv, stats, utils,
mvtnorm
Suggests: bayesplot, bayestestR, biglm, brms, car, coda (>= 0.17), ggplot2, lattice,
logspline, mediation, mgcv, multcomp, multcompView, nlme,
Suggests: bayesplot, bayestestR, biglm, brms, car, coda (>= 0.17), compositions,
ggplot2, lattice, logspline, mediation, mgcv, multcomp, multcompView, nlme,
ordinal (>= 2014.11-12), pbkrtest (>= 0.4-1), lme4, lmerTest (>= 2.0.32),
MASS, MuMIn, rsm, knitr, rmarkdown, sandwich, scales, splines, testthat,
tibble, xtable (>= 1.8-2)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "NEWS for the emmeans package"
---

## emmeans 1.10.3-090xxxx
## emmeans 1.10.4
* Refinements in tracking static offsets
* Made d.f. consistent for `geeglm` and `glmgee` (#496)
* Fixed suggestion for installing from GitHub (#497)
Expand Down
4 changes: 3 additions & 1 deletion R/multinom-support.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ emm_basis.multinom = function(object, trms, xlev, grid,
X = kronecker(pat, X)
nbasis = estimability::all.estble
nbasis = kronecker(rep(1,k), nbasis)
misc = list(tran = "log", inv.lbl = "e^y")
misc = list(tran = "clr") ### misc = list(tran = "log", inv.lbl = "e^y")
dfargs = list(df = object$edf)
dffun = function(k, dfargs) dfargs$df
if(is.null(ylevs <- object$lev))
Expand All @@ -70,6 +70,8 @@ emm_basis.multinom = function(object, trms, xlev, grid,

# post-processing of ref_grid for "prob" mode
# also allows simulated outcomes
## Note - now that we have mvregrid, we could just pass the latent grid
## through with the clrInv transform. But this works so I'm just leaving it here
.multinom.postGrid = function(object, N.sim, ...) {
linfct = object@linfct
misc = object@misc
Expand Down
32 changes: 22 additions & 10 deletions R/multiv.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ mvregrid = function(object, newname = "component", newlevs = seq_len(ncol(newy))
fcn = paste0(tran, "Inv"), ...) {
levels = levels(object)
tran = object@misc$tran
if(is.character(tran))
tran = rev(strsplit(tran, "\\.")[[1]])[1]
by = object@misc$by.vars
if (mult.name != names(levels)[length(levels)]) {
idx = which(names(levels) == mult.name)
if(length(idx) == 0)
Expand All @@ -198,32 +201,41 @@ mvregrid = function(object, newname = "component", newlevs = seq_len(ncol(newy))
}
ord = .std.order(object@grid, levels)
if(any(ord != seq_along(ord)))
object[ord]
object = object[ord] |> update(by.vars = by)

yhat = matrix(predict(object), ncol = length(levels[[mult.name]]))
yhat = matrix(predict(object), ncol = (p <- length(levels[[mult.name]])))
if(is.character(fcn)) {
if(!requireNamespace("compositions"))
if(requireNamespace("compositions"))
fcn = get(fcn, envir = asNamespace("compositions"))
else
stop("The 'compositions' package must be installed to proceed")
fcn = get(fcn, envir = asNamespace("compositions"))
}
newy = fcn(yhat, ...)
if(length(newlevs) != (k <- ncol(newy)))
stop("Nonconforming 'newlevs': Must be of length ", k)
if(!is.na(object@post.beta)) {
pb = apply(object@linfct %*% t(object@post.beta), 2, function(y) {
as.numeric(fcn(matrix(y, ncol = p), ...))
})
object@post.beta = t(pb)
}
Jac = numDeriv::jacobian(\(x) as.numeric(fcn(x)), yhat)
object@V = Jac %*% vcov(object) %*% t(Jac)
object@bhat = as.numeric(newy)
object@linfct = diag(length(object@bhat))
names(levels)[length(levels)] = object@roles$multresp = newname
object@roles$predictors = setdiff(object@roles$predictors, mult.name)
levels[[newname]] = newlevs
object@levels = levels
wgt = object@grid[[".wgt."]]
offs = object@grid[[".offset."]]
object@grid = do.call(expand.grid, levels)
g = object@grid = object@grid[seq_len(n <- nrow(newy)), setdiff(names(object@grid), c(mult.name, ".wgt.", ".offset.")), drop = FALSE]
for (i in seq_len(k - 1)) object@grid = rbind(object@grid, g)
object@grid[["newname"]] = rep(newlevs, each = n)
if(!is.null(wgt))
object@grid[[".wgt."]] = rep(wgt[seq_len(nrow(newy))], k)
if(!is.null(offs))
object@grid[[".offset."]] = rep(offs[seq_len(nrow(newy))], k)
object@misc$tran = object@misc$by = NULL
object@grid[[".wgt."]] = rep(wgt[seq_len(n)], k)
object@misc$tran = object@misc$inv.lbl = object@misc$sigma = NULL
object@misc$pri.vars = setdiff(names(object@grid), c(object@misc$by.vars, ".wgt'"))
object@misc$methDesc = "mvregrid"

object
}
2 changes: 1 addition & 1 deletion R/qdrg.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ qdrg = function(formula, data, coef, vcov, df, mcmc, object,
if (!missing(vcov)) result$vcov = vcov
if(!missing(df)) result$df = df
if(missing(contrasts))
contrasts = attr(model.matrix(result$formula, data = data[1:2, ]), "contrasts")
contrasts = attr(model.matrix(result$formula, data = data), "contrasts")
}
if(!missing(df)) result$df = df
if(is.null(result$df))
Expand Down
12 changes: 10 additions & 2 deletions R/summary.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##############################################################################
# Copyright (c) 2012-2018 Russell V. Lenth #
# Copyright (c) 2012-2024 Russell V. Lenth #
# #
# This file is part of the emmeans package for R (*emmeans*) #
# #
Expand Down Expand Up @@ -154,7 +154,11 @@ as.data.frame.summary_emm = function(x, ...) {
#' \samp{object@misc$inv.lbl}. Any \eqn{t} or \eqn{z} tests are still performed
#' on the scale of the linear predictor, not the inverse-transformed one.
#' Similarly, confidence intervals are computed on the linear-predictor scale,
#' then inverse-transformed.
#' then inverse-transformed.
#'
#' Be aware that only univariate transformations and links are
#' supported in this way. Some multivariate transformations are supported by
#' \code{\link{mvregrid}}.
#'
#' @section Bias adjustment when back-transforming:
#' When \code{bias.adjust} is \code{TRUE}, then back-transformed estimates
Expand Down Expand Up @@ -466,6 +470,10 @@ summary.emmGrid <- function(object, infer, level, adjust, by,
}
else
two.trans = FALSE
# Check if we have a log-ratio transformation. At least then we can guess the problem.
if ((type == "response") && is.character(object@misc$tran) && endsWith(object@misc$tran, "lr"))
warning("It looks like you have a multivariate transformation -- not handled by type = 'response'.\n",
"Perhaps instead you wanted to use 'mvregrid()'?")



Expand Down
10 changes: 6 additions & 4 deletions inst/extexamples/mvregrid.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
data(AnimalVegetation)
data(AnimalVegetation, package = "compositions")
AV <- as.data.frame(AnimalVegetation)

AVmod <- lm(ilr(cbind(disc,spick,din,spin)) ~ regA, data = AV)
AVmod <- lm(compositions::ilr(cbind(disc,spick,din,spin)) ~ regA, data = AV)

AVRG <- ref_grid(AVmod) |> suppressWarnings()
AVrg
AVRG

mvregrid(AVRG, newname = "comp", newlevs = c("disc","spick","din","spin")) |>
mvregrid(AVRG, newname = "comp",
newlevs = c("disc","spick","din","spin"),
fcn = "ilrInv") |>
confint(by = "regA")

6 changes: 5 additions & 1 deletion man/summary.emmGrid.Rd

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

7 changes: 7 additions & 0 deletions vignettes/models.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ typically the tests and confidence intervals are asymptotic. Thus the
Some objects in this group may require that the original or reference dataset
be provided when calling `ref_grid()` or `emmeans()`.

For `coxph` objects, the estimates we obtain are comparable to running
`predict.coxph()` with `reference = "zero"`; that is, no covariate centering is done.
The user may use `at` to specify adjusted covariate values. For example, the
default reference grid sets each covariate to its mean, so estimates comparable
to `predict.coxph(..., reference = "sample")` would be obtained by specifying
`at = list(x = 0)`.

In the case of `mgcv::gam` objects, there are optional `freq` and
`unconditional` arguments as is detailed in the documentation for
`mgcv::vcov.gam()`. Both default to `FALSE`. The value of `unconditional`
Expand Down

0 comments on commit 86c7f31

Please sign in to comment.