-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
137 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
##' @importFrom dplyr bind_rows tibble | ||
##' @importFrom stats vcov | ||
##' @export | ||
tidy.glmm <- function(x, effects = "fixed") { | ||
|
||
estimate <- std.error <- statistic <- p.value <- NULL ## avoid check warnings for NSE | ||
fix_nm <- names(coef(x)) | ||
ran_nm <- x$varcomps.names | ||
res <- list() | ||
if ("fixed" %in% effects) { | ||
res[["fixed"]] <- | ||
tibble( | ||
term = fix_nm, | ||
estimate = coef(x), | ||
std.error = sqrt(diag(vcov(x)))[fix_nm]) |> | ||
mutate(statistic = estimate/std.error, | ||
p.value = 2*pnorm(-abs(statistic))) | ||
} | ||
if ("ran_pars" %in% effects) { | ||
res[["fixed"]] <- | ||
tibble( | ||
term = ran_nm, | ||
estimate = x$nu, | ||
std.error = sqrt(diag(vcov(x)))[ran_nm]) |> | ||
mutate(statistic = NA_real_, | ||
p.value = NA_real_) | ||
} | ||
bind_rows(res, .id = "effect") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
predict.clmm <- function(object, ...) { | ||
## hack clmm object so it looks sufficiently like a clm[m]2 object | ||
## for the predict.clm2 method to work ... | ||
object$location <- object$formula | ||
if (object$link == "logit") object$link <- "logistic" | ||
attr(object$location, "terms") <- object$terms | ||
class(object) <- c("clm2") | ||
predict(object, ...) | ||
} | ||
|
||
## predict values for every level in an ordinal response | ||
## copied/modified from | ||
predict.all.clmm <- function(object, newdata, ...) { | ||
respvar <- attr(object$terms, "response") | ||
mf <- model.frame(object) | ||
nlev <- length(levels(mf[[respvar]])) | ||
if (!missing(newdata)) mf <- model.frame(object$formula, data = newdata) | ||
ndat <- do.call(rbind, | ||
replicate(nlev, mf, simplify = FALSE)) | ||
ndat[[respvar]] <- ordered(rep(seq(nlev), each = nrow(mf))) | ||
res <- matrix(predict(object, newdata = ndat), ncol=nlev) | ||
} | ||
|
||
#' name ordinal_tidiers | ||
#' | ||
#' the \code{tidy} method for \code{clmm} objects (from the | ||
#' \code{ordinal} package) lives in the \code{broom} package. | ||
#' | ||
#' @importFrom tibble tibble | ||
#' @export | ||
augment.clmm <- function(..., | ||
data = stats::model.frame(x), newdata, ...) { | ||
|
||
if (!missing(newdata)) data <- newdata | ||
|
||
} | ||
|
||
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) | ||
stopifnot(all.equal(predict(fmm1), predict(fmm2), | ||
tolerance = 1e-6)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters