Skip to content

Commit

Permalink
added handling for factor variables where not all levels are resampled
Browse files Browse the repository at this point in the history
  • Loading branch information
MeganTJ21 committed Jan 8, 2024
1 parent f5a857e commit 4bfd4ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion R/internal_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ chisq2Ssq = function(chisq, df, n){
#' @return Returns a vector of RESI estimates for a single bootstrap replicate
#' @noRd
resi_stat = function(dat, inds, mod.full, mod.reduced, boot.method = "nonparam",
cluster = FALSE, clvar = NULL, mod.dat = NULL, overall = TRUE, ...){
cluster = FALSE, clvar = NULL, mod.dat = NULL, overall = TRUE,
nest = NULL, ...){
# nonparametric bootstrap
if (boot.method == "nonparam"){
if(!cluster){
Expand Down Expand Up @@ -62,6 +63,11 @@ resi_stat = function(dat, inds, mod.full, mod.reduced, boot.method = "nonparam",
out = try(resi_pe(mod.full, model.reduced = mod.reduced, data = boot.data, overall = overall, ...)$estimates, silent = T)
if(inherits(out, "try-error")){
out = NA
} else{
# for factored variables, it's possible the model will not contain all factor levels and not represent the original model
if(length(out) != nest){
out = NA
}
}
} else{
out = NA
Expand Down
2 changes: 1 addition & 1 deletion R/resi.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ resi.default = function(model.full, model.reduced = NULL, data, anova = TRUE,
ncpus = ncpus, mod.full = model.full, mod.reduced = model.reduced,
anova = anova, coefficients = coefficients, overall = overall, vcovfunc = vcovfunc,
Anova.args = Anova.args, vcov.args = vcov.args, unbiased = unbiased,
boot.method = boot.method, clvar = clvar, ...), file = nullfile()))
boot.method = boot.method, clvar = clvar, nest = length(output$estimates), ...), file = nullfile()))

# bootstrapped estimates
boot.results = boot_out$t
Expand Down

0 comments on commit 4bfd4ed

Please sign in to comment.