Skip to content

Commit

Permalink
more ordinal augment cleanup/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bbolker committed Apr 9, 2024
1 parent 690b742 commit 7c1618c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Expand Up @@ -2,6 +2,7 @@

S3method(as.data.frame,ranef.lme)
S3method(augment,brmsfit)
S3method(augment,clmm)
S3method(augment,gamm4)
S3method(augment,glmmTMB)
S3method(augment,glmmadmb)
Expand All @@ -22,6 +23,7 @@ S3method(glance,lme)
S3method(glance,lqmm)
S3method(glance,merMod)
S3method(glance,stanreg)
S3method(predict,clmm)
S3method(ranef,MCMCglmm)
S3method(sigma,brmsfit)
S3method(tidy,MCMCglmm)
Expand Down Expand Up @@ -87,6 +89,7 @@ importFrom(stats,confint)
importFrom(stats,cov2cor)
importFrom(stats,logLik)
importFrom(stats,median)
importFrom(stats,model.frame)
importFrom(stats,na.omit)
importFrom(stats,plogis)
importFrom(stats,pnorm)
Expand Down
14 changes: 12 additions & 2 deletions R/ordinal_tidiers.R
@@ -1,3 +1,4 @@
#' @export
predict.clmm <- function(object, ...) {
## hack clmm object so it looks sufficiently like a clm[m]2 object
## for the predict.clm2 method to work ...
Expand All @@ -10,7 +11,7 @@ predict.clmm <- function(object, ...) {

## predict values for every level in an ordinal response
## copied/modified from
predict.all.clmm <- function(object, newdata, ...) {
predict_all_clmm <- function(object, newdata, ...) {
respvar <- attr(object$terms, "response")
mf <- model.frame(object)
nlev <- length(levels(mf[[respvar]]))
Expand All @@ -36,16 +37,25 @@ augment.clmm <- function( x,
if (!missing(newdata)) data <- newdata

## STUB
## call predict_all_clmm
## generate mean predictions via
## sweep([pred matrix], MARGIN = 2, FUN = "*", STATS = seq(ncol[pred matrix])) |> rowMeans
## get std dev similarly (sqrt(rowMeans(sweep with (1:n)^2)))
## residuals, pearson residuals?
}

## simulate method will look like this:
## pred_matrix <- predict_all_clmm()
## apply(pred_matrix, 1, \(p) rmultinom(1, size = 1, prob = p))

if (FALSE) {
library(ordinal)

fmm1 <- clmm(rating ~ temp + contact + (1|judge), data = wine)
fmm2 <- clmm2(rating ~ temp + contact, random = judge, data = wine)


mm <- predict.all.clmm(fmm1)
mm <- predict_all_clmm(fmm1)
stopifnot(all.equal(predict(fmm1), predict(fmm2),
tolerance = 1e-6))

Expand Down

0 comments on commit 7c1618c

Please sign in to comment.