Skip to content

Commit

Permalink
use broom instead of generics
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Dec 15, 2018
1 parent 1c1731d commit 677c7de
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Depends:
stats,
utils
Imports:
generics,
broom,
dplyr (>= 0.7.5),
forcats,
ggeffects (>= 0.7.0),
Expand Down
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export(view_df)
import(ggplot2)
importFrom(MASS,glm.nb)
importFrom(MASS,lda)
importFrom(broom,augment)
importFrom(broom,tidy)
importFrom(dplyr,"%>%")
importFrom(dplyr,arrange)
importFrom(dplyr,between)
Expand All @@ -95,8 +97,6 @@ importFrom(dplyr,summarize)
importFrom(dplyr,ungroup)
importFrom(forcats,fct_reorder)
importFrom(forcats,fct_rev)
importFrom(generics,augment)
importFrom(generics,tidy)
importFrom(ggeffects,ggeffect)
importFrom(ggeffects,ggpredict)
importFrom(glmmTMB,fixef)
Expand Down
1 change: 0 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## General

* Revised some help-files and vignettes.
* Replaced package dependency **broom** with **generics**.

## Removed / Defunct

Expand Down
4 changes: 2 additions & 2 deletions R/sjPlotKfoldCV.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#' @importFrom modelr crossv_kfold
#' @importFrom dplyr mutate ungroup summarise
#' @importFrom purrr map map2
#' @importFrom generics augment
#' @importFrom broom augment
#' @importFrom tidyr unnest
#' @importFrom graphics plot
#' @importFrom stats as.formula formula family poisson glm lm
Expand Down Expand Up @@ -113,7 +113,7 @@ sjp.kfold_cv <- function(data, formula, k = 5, fit) {
# train data
res <- modelr::crossv_kfold(data, k = k) %>%
dplyr::mutate(model = purrr::map(.data$train, ~ stats::lm(formula, data = .))) %>%
dplyr::mutate(predicted = purrr::map2(.data$model, .data$test, ~ generics::augment(.x, newdata = .y))) %>%
dplyr::mutate(predicted = purrr::map2(.data$model, .data$test, ~ broom::augment(.x, newdata = .y))) %>%
tidyr::unnest(.data$predicted)

# make sure that response vector has an identifiably name
Expand Down
18 changes: 9 additions & 9 deletions R/tidiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ get_tidy_data <- function(model, ci.lvl, tf, type, bpe, facets, show.zeroinf, p.
}


#' @importFrom generics tidy
#' @importFrom broom tidy
#' @importFrom sjstats p_value
#' @importFrom stats coef qnorm
#' @importFrom dplyr mutate
Expand All @@ -77,7 +77,7 @@ tidy_generic <- function(model, ci.lvl, facets, p.val) {
if (inherits(stats::coef(summary(model)), "listof")) {

# get estimates, as data frame
dat <- generics::tidy(model, conf.int = FALSE, exponentiate = FALSE)
dat <- broom::tidy(model, conf.int = FALSE, exponentiate = FALSE)

# check whether each category should be printed in facets, or
# in a single graph (with dodged geoms)
Expand All @@ -94,7 +94,7 @@ tidy_generic <- function(model, ci.lvl, facets, p.val) {
if (inherits(model, "lmerModLmerTest")) {
dat <- tidy_lmerModLmerTest(model, ci.lvl)
} else {
dat <- generics::tidy(model, conf.int = FALSE, effects = "fixed")
dat <- broom::tidy(model, conf.int = FALSE, effects = "fixed")
}


Expand Down Expand Up @@ -185,11 +185,11 @@ tidy_svynb_model <- function(model, ci.lvl) {
}


#' @importFrom generics tidy
#' @importFrom broom tidy
#' @importFrom sjstats p_value
tidy_cox_model <- function(model, ci.lvl) {
# tidy the model
dat <- generics::tidy(model, conf.int = ci.lvl)
dat <- broom::tidy(model, conf.int = ci.lvl)

# see if we have p-values. if not, add them
if (!obj_has_name(dat, "p.value"))
Expand Down Expand Up @@ -527,14 +527,14 @@ tidy_stan_model <- function(model, ci.lvl, tf, type, bpe, show.zeroinf, facets,
}


#' @importFrom generics tidy
#' @importFrom broom tidy
#' @importFrom sjstats p_value
#' @importFrom nlme intervals
tidy_lme_model <- function(model, ci.lvl) {
# get tidy summary. for lme, this excludes CI,
# so we compute them separately

dat <- generics::tidy(model, conf.int = TRUE, conf.level = ci.lvl, effects = "fixed")
dat <- broom::tidy(model, conf.int = TRUE, conf.level = ci.lvl, effects = "fixed")
ci <- as.data.frame(nlme::intervals(model, level = ci.lvl, which = "fixed")$fixed)

dat$conf.low <- ci$lower
Expand Down Expand Up @@ -798,7 +798,7 @@ tidy_polr_model <- function(model, ci.lvl) {
#' @importFrom stats qnorm pnorm
#' @importFrom rlang .data
#' @importFrom dplyr mutate
#' @importFrom generics tidy
#' @importFrom broom tidy
#' @importFrom sjmisc var_rename
tidy_multinom_model <- function(model, ci.lvl, facets) {

Expand All @@ -811,7 +811,7 @@ tidy_multinom_model <- function(model, ci.lvl, facets) {


# get estimates, as data frame
dat <- generics::tidy(model, conf.int = FALSE, exponentiate = FALSE)
dat <- broom::tidy(model, conf.int = FALSE, exponentiate = FALSE)


# add conf. int.
Expand Down

0 comments on commit 677c7de

Please sign in to comment.