Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed May 10, 2024
1 parent 82417ca commit 70ce5f2
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 59 deletions.
3 changes: 0 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ Imports:
performance
Suggests:
brms,
broom,
car,
coin,
ggplot2,
graphics,
MASS,
pscl,
pwr,
sjPlot,
survey,
rstan,
testthat
URL: https://strengejacke.github.io/sjstats/
BugReports: https://github.com/strengejacke/sjstats/issues
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ importFrom(datawizard,weighted_sd)
importFrom(insight,export_table)
importFrom(insight,format_p)
importFrom(insight,format_value)
importFrom(insight,get_response)
importFrom(insight,link_inverse)
importFrom(insight,print_color)
importFrom(performance,mse)
Expand Down
14 changes: 9 additions & 5 deletions R/S3-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ tidy_svyglm.nb <- function(x, digits = 4, v_se = c("robust", "model")) {
estimate = round(est, digits),
irr = round(exp(est), digits),
std.error = round(se, digits),
conf.low = round(exp(est - stats::qnorm(.975) * se), digits),
conf.high = round(exp(est + stats::qnorm(.975) * se), digits),
conf.low = round(exp(est - stats::qnorm(0.975) * se), digits),
conf.high = round(exp(est + stats::qnorm(0.975) * se), digits),
p.value = round(2 * stats::pnorm(abs(est / se), lower.tail = FALSE), digits)
)
}
Expand Down Expand Up @@ -265,9 +265,13 @@ print.sj_resample <- function(x, ...) {
else
id10 <- x$id

cat("<", paste0("id's of resample [", prettyNum(nrow(x$data), big.mark = ","), " x ",
prettyNum(ncol(x$data), big.mark = ","), "]"), "> ",
paste(id10, collapse = ", "), "\n", sep = "")
cat("<", paste0(
"id's of resample [", prettyNum(nrow(x$data), big.mark = ","), " x ",
prettyNum(ncol(x$data), big.mark = ","), "]"
), "> ",
toString(id10), "\n",
sep = ""
)
}


Expand Down
8 changes: 3 additions & 5 deletions R/anova_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' \cr \cr
#' Tippey K, Longnecker MT (2016): An Ad Hoc Method for Computing Pseudo-Effect Size for Mixed Model.
#'
#' @examples
#' @examplesIf requireNamespace("car")
#' # load sample data
#' data(efc)
#'
Expand All @@ -24,9 +24,7 @@
#' c12hour ~ as.factor(e42dep) + as.factor(c172code) + c160age,
#' data = efc
#' )
#' \dontrun{
#' anova_stats(car::Anova(fit, type = 2))
#' }
#' @export
anova_stats <- function(model, digits = 3) {
insight::check_if_installed("pwr")
Expand Down Expand Up @@ -97,7 +95,7 @@ aov_stat <- function(model, type) {


aov_stat_summary <- function(model) {
insight::check_if_installed("broom")
insight::check_if_installed("parameters")
# check if we have a mixed model
mm <- is_merMod(model)
ori.model <- model
Expand All @@ -108,7 +106,7 @@ aov_stat_summary <- function(model) {
model <- stats::anova(model)

# get summary table
aov.sum <- as.data.frame(broom::tidy(model))
aov.sum <- insight::standardize_names(as.data.frame(parameters::model_parameters(model)), style = "broom")

# for mixed models, add information on residuals
if (mm) {
Expand Down
22 changes: 7 additions & 15 deletions R/auto_prior.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,16 @@
#' formula used in \code{brms::brm()} must be rewritten to something like
#' \code{y ~ 0 + intercept ...}, see \code{\link[brms]{set_prior}}.
#'
#' @examples
#' library(sjmisc)
#' @examplesIf requireNamespace("brms")
#' data(efc)
#' efc$c172code <- as.factor(efc$c172code)
#' efc$c161sex <- to_label(efc$c161sex)
#' efc$c161sex <- as.factor(efc$c161sex)
#'
#' mf <- formula(neg_c_7 ~ c161sex + c160age + c172code)
#'
#' if (requireNamespace("brms", quietly = TRUE))
#' auto_prior(mf, efc, TRUE)
#' auto_prior(mf, efc, TRUE)
#'
#' ## compare to
#' # library(rstanarm)
#' # m <- stan_glm(mf, data = efc, chains = 2, iter = 200)
#' # m <- rstanarm::stan_glm(mf, data = efc, chains = 2, iter = 200)
#' # ps <- prior_summary(m)
#' # ps$prior_intercept$adjusted_scale
#' # ps$prior$adjusted_scale
Expand All @@ -59,17 +55,13 @@
#' # add informative priors
#' mf <- formula(neg_c_7 ~ c161sex + c172code)
#'
#' if (requireNamespace("brms", quietly = TRUE)) {
#' auto_prior(mf, efc, TRUE) +
#' brms::prior(normal(.1554, 40), class = "b", coef = "c160age")
#' }
#' auto_prior(mf, efc, TRUE) +
#' brms::prior(normal(.1554, 40), class = "b", coef = "c160age")
#'
#' # example with binary response
#' efc$neg_c_7d <- ifelse(efc$neg_c_7 < median(efc$neg_c_7, na.rm = TRUE), 0, 1)
#' mf <- formula(neg_c_7d ~ c161sex + c160age + c172code + e17age)
#'
#' if (requireNamespace("brms", quietly = TRUE))
#' auto_prior(mf, efc, FALSE)
#' auto_prior(mf, efc, FALSE)
#' @export
auto_prior <- function(formula, data, gaussian, locations = NULL) {
insight::check_if_installed("brms")
Expand Down
2 changes: 1 addition & 1 deletion R/boot_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#'
#' @seealso []`bootstrap()`] to generate nonparametric bootstrap samples.
#'
#' @examplesIf getRversion() >= "4.2.0"
#' @examples
#' data(efc)
#' bs <- bootstrap(efc, 100)
#'
Expand Down
8 changes: 4 additions & 4 deletions R/cramer.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ cramers_v.ftable <- function(tab, ...) {
#' @rdname crosstable_statistics
#' @export
cramers_v.formula <- function(formula, data, ci.lvl = NULL, n = 1000, method = c("dist", "quantile"), ...) {
terms <- all.vars(formula)
tab <- table(data[[terms[1]]], data[[terms[2]]])
fterms <- all.vars(formula)
tab <- table(data[[fterms[1]]], data[[fterms[2]]])
method <- match.arg(method)

if (is.null(ci.lvl) || is.na(ci.lvl)) {
.cramers_v(tab)
} else {
straps <- sjstats::bootstrap(data[terms], n)
straps <- sjstats::bootstrap(data[fterms], n)
tables <- lapply(straps$strap, function(x) {
dat <- as.data.frame(x)
table(dat[[1]], dat[[2]])
})
cramers <- sapply(tables, function(x) .cramers_v(x))
cramers <- sapply(tables, .cramers_v)
ci <- boot_ci(cramers, ci.lvl = ci.lvl, method = method)

data_frame(
Expand Down
3 changes: 1 addition & 2 deletions R/cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ cv <- function(x, ...) {
}


#' @importFrom performance rmse
#' @importFrom insight get_response
cv_helper <- function(x) {
insight::check_if_installed("performance")
# check if we have a fitted linear model
if (inherits(x, c("lm", "lmerMod", "lme", "merModLmerTest")) && !inherits(x, "glm")) {
# get response
Expand Down
9 changes: 4 additions & 5 deletions R/find_beta.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,24 @@ find_beta2 <- function(x, se, ci, n) {

# need to compute proportion
x <- x / n
p2 <- .95
p2 <- 0.95
x2 <- x + bvar
}

# for standard errors, we assume a 68% quantile
if (!missing(se)) {
p2 <- .68
p2 <- 0.68
x2 <- x + se
}

# for CI, we assume a 68% quantile
if (!missing(ci)) {
p2 <- .95
p2 <- 0.95
x2 <- ci
}

# the probability is assumed to be the median
p1 <- .5
p1 <- 0.5
x1 <- x

find_beta(x1, p1, x2, p2)
Expand Down Expand Up @@ -182,4 +182,3 @@ find_normal <- function(x1, p1, x2, p2) {

list(mean = mw, sd = stddev)
}

4 changes: 2 additions & 2 deletions man/anova_stats.Rd

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

22 changes: 8 additions & 14 deletions man/auto_prior.Rd

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

2 changes: 0 additions & 2 deletions man/boot_ci.Rd

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

0 comments on commit 70ce5f2

Please sign in to comment.