Skip to content

Commit

Permalink
still hacking on binned_residuals
Browse files Browse the repository at this point in the history
  • Loading branch information
bbolker committed Oct 24, 2023
1 parent e9c9b46 commit 2fb679a
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions R/binned_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
#' }
#'
#' @export
binned_residuals <- function(model, term = NULL, n_bins = NULL, show_dots = NULL, ...) {
binned_residuals <- function(model, term = NULL, n_bins = NULL, show_dots = NULL, resids = c("gaussian", "exact", "boot"), level = 0.95, ...) {

Check warning on line 65 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/binned_residuals.R,line=65,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 143 characters.

Check warning on line 65 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/binned_residuals.R,line=65,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 143 characters.

resids <- match.arg(resids)
fv <- stats::fitted(model)
mf <- insight::get_data(model, verbose = FALSE)

Expand All @@ -78,8 +80,9 @@ binned_residuals <- function(model, term = NULL, n_bins = NULL, show_dots = NULL
show_dots <- is.null(n) || n <= 1e5
}

y <- .recode_to_zero(insight::get_response(model, verbose = FALSE)) - fv
>>>>>>> upstream/main

y0 <- .recode_to_zero(insight::get_response(model, verbose = FALSE))
y <- y0 - fv

if (is.null(n_bins)) n_bins <- round(sqrt(length(pred)))

Expand All @@ -96,18 +99,28 @@ binned_residuals <- function(model, term = NULL, n_bins = NULL, show_dots = NULL
n <- length(items)
sdev <- stats::sd(y[items], na.rm = TRUE)

bt <- binom.test(sum(y0[items]), n)
data.frame(
ci_fun <- function() {
r <- switch(resids,

Check warning on line 103 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/binned_residuals.R,line=103,col=8,[indentation_linter] Indentation should be 6 spaces but is 8 spaces.
gaussian = qnorm(c((1-level)/2, (1+level)/2),

Check warning on line 104 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/binned_residuals.R,line=104,col=37,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 104 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/binned_residuals.R,line=104,col=44,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 104 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/binned_residuals.R,line=104,col=50,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 104 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/binned_residuals.R,line=104,col=57,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 104 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/binned_residuals.R,line=104,col=15,[indentation_linter] Indentation should be 8 spaces but is 15 spaces.

Check warning on line 104 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/binned_residuals.R,line=104,col=37,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 104 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/binned_residuals.R,line=104,col=44,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 104 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/binned_residuals.R,line=104,col=50,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 104 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/binned_residuals.R,line=104,col=57,[infix_spaces_linter] Put spaces around all infix operators.
mean = ybar, sd = sdev/sqrt(n)),

Check warning on line 105 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/binned_residuals.R,line=105,col=55,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 105 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/binned_residuals.R,line=105,col=55,[infix_spaces_linter] Put spaces around all infix operators.
exact = stats:::binom.test(sum(y0[items]), n)$conf.int - fv,

Check warning on line 106 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/binned_residuals.R,line=106,col=15,[indentation_linter] Indentation should be 8 spaces but is 15 spaces.
boot = Hmisc::smean.cl.boot(y[items], conf.int = level)[c("Lower", "Upper")]
)

Check warning on line 108 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/binned_residuals.R,line=108,col=15,[indentation_linter] Indentation should be 6 spaces but is 15 spaces.
names(r) <- c("CI_low", "CI_high")
r
}

d0 <- data.frame(
xbar = xbar,
ybar = ybar,
n = n,
x.lo = model.range[1],
x.hi = model.range[2],
se = stats::qnorm(0.975) * sdev / sqrt(n),
ci_range = sdev / sqrt(n),
CI_low = bt$conf.int[1] - fv,
CI_high = bt$conf.int[2] - fv
se = stats::qnorm((1+level)/2) * sdev / sqrt(n),

Check warning on line 119 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/binned_residuals.R,line=119,col=27,[infix_spaces_linter] Put spaces around all infix operators.

Check warning on line 119 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/binned_residuals.R,line=119,col=34,[infix_spaces_linter] Put spaces around all infix operators.
ci_range = sdev / sqrt(n)
)
cbind(d0, rbind(ci_fun()))

Check warning on line 123 in R/binned_residuals.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/binned_residuals.R,line=123,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
}))

d <- do.call(rbind, d)
Expand Down

0 comments on commit 2fb679a

Please sign in to comment.