Skip to content

Commit

Permalink
Update tidiers.R
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Dec 15, 2018
1 parent 677c7de commit 88926f4
Showing 1 changed file with 19 additions and 65 deletions.
84 changes: 19 additions & 65 deletions R/tidiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ tidy_model <- function(model, ci.lvl, tf, type, bpe, se, facets, show.zeroinf, p
dat[["std.error"]] <- std.err[["std.error"]]

# also fix CI and p-value after robust SE

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975
ci <- get_confint(ci.lvl)

dat$conf.low <- dat$estimate - stats::qnorm(ci) * dat$std.error
dat$conf.high <- dat$estimate + stats::qnorm(ci) * dat$std.error
Expand Down Expand Up @@ -65,12 +61,7 @@ get_tidy_data <- function(model, ci.lvl, tf, type, bpe, facets, show.zeroinf, p.
tidy_generic <- function(model, ci.lvl, facets, p.val) {

# compute ci, two-ways

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975

ci <- get_confint(ci.lvl)

# check for multiple reponse levels

Expand Down Expand Up @@ -161,12 +152,7 @@ tidy_svynb_model <- function(model, ci.lvl) {


# compute ci, two-ways

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975

ci <- get_confint(ci.lvl)

# keep original value, not rounded

Expand Down Expand Up @@ -581,12 +567,7 @@ tidy_gls_model <- function(model, ci.lvl) {
tidy_glmmTMB_model <- function(model, ci.lvl, show.zeroinf) {

# compute ci, two-ways

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975

ci <- get_confint(ci.lvl)

# get fixed effects

Expand Down Expand Up @@ -656,12 +637,7 @@ tidy_glmmTMB_model <- function(model, ci.lvl, show.zeroinf) {
tidy_hurdle_model <- function(model, ci.lvl) {

# compute ci, two-ways

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975

ci <- get_confint(ci.lvl)

# get estimates

Expand Down Expand Up @@ -692,12 +668,7 @@ tidy_hurdle_model <- function(model, ci.lvl) {
tidy_logistf_model <- function(model, ci.lvl) {

# compute ci, two-ways

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975

ci <- get_confint(ci.lvl)

# get estimates

Expand All @@ -723,12 +694,7 @@ tidy_logistf_model <- function(model, ci.lvl) {
tidy_clm_model <- function(model, ci.lvl) {

# compute ci, two-ways

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975

ci <- get_confint(ci.lvl)

# get estimates, as data frame

Expand Down Expand Up @@ -763,12 +729,7 @@ tidy_clm_model <- function(model, ci.lvl) {
tidy_polr_model <- function(model, ci.lvl) {

# compute ci, two-ways

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975

ci <- get_confint(ci.lvl)

# get estimates, as data frame

Expand Down Expand Up @@ -803,12 +764,7 @@ tidy_polr_model <- function(model, ci.lvl) {
tidy_multinom_model <- function(model, ci.lvl, facets) {

# compute ci, two-ways

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975

ci <- get_confint(ci.lvl)

# get estimates, as data frame
dat <- broom::tidy(model, conf.int = FALSE, exponentiate = FALSE)
Expand Down Expand Up @@ -840,12 +796,7 @@ tidy_multinom_model <- function(model, ci.lvl, facets) {
tidy_gam_model <- function(model, ci.lvl) {

# compute ci, two-ways

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975

ci <- get_confint(ci.lvl)

# get estimates

Expand All @@ -870,12 +821,7 @@ tidy_gam_model <- function(model, ci.lvl) {
tidy_zelig_model <- function(model, ci.lvl) {

# compute ci, two-ways

if (!is.null(ci.lvl) && !is.na(ci.lvl))
ci <- 1 - ((1 - ci.lvl) / 2)
else
ci <- .975

ci <- get_confint(ci.lvl)

if (!requireNamespace("Zelig"))
stop("Package `Zelig` required. Please install", call. = F)
Expand All @@ -895,3 +841,11 @@ tidy_zelig_model <- function(model, ci.lvl) {
p.value = unname(unlist(Zelig::get_pvalue(model)))
)
}


get_confint <- function(ci.lvl = .95) {
if (!is.null(ci.lvl) && !is.na(ci.lvl))
(1 + ci.lvl) / 2
else
.975
}

0 comments on commit 88926f4

Please sign in to comment.