├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── CRAN-SUBMISSION ├── DESCRIPTION ├── NAMESPACE ├── NEWS ├── R ├── bootstrap_lme4.R ├── bootstrap_nlme.R ├── combine_lmersamp.R ├── complete.R ├── confint.R ├── data.R ├── error_messages.R ├── generics.R ├── lme4_invlink.R ├── lme4_utility_functions.R ├── lme_utilities.R ├── lmeresampler.R ├── plot.R ├── print.R ├── pvals.R ├── resamplers.R ├── setup.R ├── summary.R └── utils-pipe.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── cran-comments.md ├── data └── jsp728.RData ├── docs ├── 404.html ├── apple-touch-icon-120x120.png ├── apple-touch-icon-152x152.png ├── apple-touch-icon-180x180.png ├── apple-touch-icon-60x60.png ├── apple-touch-icon-76x76.png ├── apple-touch-icon.png ├── articles │ ├── Vignette.html │ ├── Vignette_files │ │ └── accessible-code-block-0.0.1 │ │ │ └── empty-anchor.js │ ├── index.html │ ├── lmeresampler-vignette.html │ └── lmeresampler-vignette_files │ │ ├── accessible-code-block-0.0.1 │ │ └── empty-anchor.js │ │ ├── figure-html │ │ ├── unnamed-chunk-2-1.png │ │ ├── unnamed-chunk-2-2.png │ │ └── unnamed-chunk-2-3.png │ │ ├── header-attrs-2.11 │ │ └── header-attrs.js │ │ ├── header-attrs-2.13 │ │ └── header-attrs.js │ │ └── header-attrs-2.7 │ │ └── header-attrs.js ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── image │ └── FINAL_HEX_nobackground.png ├── index.html ├── link.svg ├── logo.png ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml └── reference │ ├── Rplot001.png │ ├── bootstrap.html │ ├── bootstrap_pvals.html │ ├── case_bootstrap.html │ ├── cgr_bootstrap.html │ ├── combine.html │ ├── combine_pvals.html │ ├── confint.html │ ├── extract_parameters.html │ ├── figures │ └── logo.png │ ├── index.html │ ├── jsp728.html │ ├── lmeresampler.html │ ├── parametric_bootstrap.html │ ├── pipe.html │ ├── plot.html │ ├── print.coef_tbl.html │ ├── print.html │ ├── reb_bootstrap.html │ ├── resid_bootstrap.html │ ├── summary.html │ └── wild_bootstrap.html ├── inst └── image │ └── FINAL_HEX_nobackground.png ├── man ├── bootstrap.Rd ├── bootstrap_pvals.Rd ├── case_bootstrap.Rd ├── combine.Rd ├── combine_pvals.Rd ├── confint.Rd ├── extract_parameters.Rd ├── figures │ └── logo.png ├── jsp728.Rd ├── lmeresampler.Rd ├── parametric_bootstrap.Rd ├── pipe.Rd ├── plot.Rd ├── print.Rd ├── print.coef_tbl.Rd ├── reb_bootstrap.Rd ├── resid_bootstrap.Rd ├── summary.Rd └── wild_bootstrap.Rd ├── pkgdown └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── revdep ├── .gitignore ├── README.md ├── checks.noindex │ └── libraries.csv ├── cran.md ├── data.sqlite ├── email.yml ├── failures.md ├── library.noindex │ └── lmeresampler │ │ ├── new │ │ └── lmeresampler │ │ │ ├── DESCRIPTION │ │ │ ├── INDEX │ │ │ ├── NAMESPACE │ │ │ ├── NEWS │ │ │ ├── R │ │ │ ├── lmeresampler │ │ │ ├── lmeresampler.rdb │ │ │ └── lmeresampler.rdx │ │ │ ├── data │ │ │ ├── Rdata.rdb │ │ │ ├── Rdata.rds │ │ │ └── Rdata.rdx │ │ │ ├── help │ │ │ ├── AnIndex │ │ │ ├── aliases.rds │ │ │ ├── figures │ │ │ │ └── logo.png │ │ │ ├── lmeresampler.rdb │ │ │ ├── lmeresampler.rdx │ │ │ └── paths.rds │ │ │ ├── html │ │ │ ├── 00Index.html │ │ │ └── R.css │ │ │ └── image │ │ │ └── FINAL_HEX_nobackground.png │ │ └── old │ │ └── lmeresampler │ │ ├── DESCRIPTION │ │ ├── INDEX │ │ ├── NAMESPACE │ │ ├── NEWS │ │ ├── R │ │ ├── lmeresampler │ │ ├── lmeresampler.rdb │ │ └── lmeresampler.rdx │ │ ├── data │ │ ├── Rdata.rdb │ │ ├── Rdata.rds │ │ └── Rdata.rdx │ │ ├── help │ │ ├── AnIndex │ │ ├── aliases.rds │ │ ├── lmeresampler.rdb │ │ ├── lmeresampler.rdx │ │ └── paths.rds │ │ └── html │ │ ├── 00Index.html │ │ └── R.css └── problems.md ├── tests ├── testthat.R └── testthat │ ├── reference_data_for_rbootnoise_test_A071022.RData │ ├── reference_data_for_rbootnoise_test_B071022.RData │ ├── test-case-lme4.R │ ├── test-case-nlme.R │ ├── test-parametric-lme4.R │ ├── test-parametric-nlme.R │ ├── test-rbootnoise.R │ ├── test-reb-lme4.R │ ├── test-reb-nlme.R │ ├── test-resid-lme4.R │ ├── test-resid-nlme.R │ ├── test-wild-lme4.R │ └── test-wild-nlme.R └── vignettes ├── .gitignore └── lmeresampler-vignette.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^CRAN-RELEASE$ 2 | ^.*\.Rproj$ 3 | ^\.Rproj\.user$ 4 | ^cran-comments\.md$ 5 | ^NEWS\.md$ 6 | ^\.travis\.yml$ 7 | ^README\.Rmd$ 8 | ^README-.*\.png$ 9 | ^doc$ 10 | ^Meta$ 11 | ^_pkgdown\.yml$ 12 | ^docs$ 13 | ^pkgdown$ 14 | ^\.github$ 15 | ^revdep$ 16 | ^CRAN-SUBMISSION$ 17 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macos-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v3 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | 5 | *.Rproj 6 | 7 | *.history 8 | 9 | R/.Rapp.history 10 | .DS_Store 11 | R/.DS_Store 12 | Meta 13 | doc 14 | /doc/ 15 | /Meta/ 16 | -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 0.2.4 2 | Date: 2023-02-10 19:39:40 UTC 3 | SHA: 4ba8a363de05608b070d8ed435a74c0d1c438f10 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: lmeresampler 2 | Title: Bootstrap Methods for Nested Linear Mixed-Effects Models 3 | Version: 0.2.4 4 | Authors@R: c(person("Adam", "Loy", email = "loyad01@gmail.com", 5 | role = c("aut", "cre"), comment = c(ORCID = "0000-0002-5780-4611")), 6 | person("Spenser", "Steele", role = "aut"), 7 | person("Jenna", "Korobova", role = "aut"), 8 | person("Ilmari", "Tamminen", role = "ctb")) 9 | Description: Bootstrap routines for nested linear mixed effects models fit using 10 | either 'lme4' or 'nlme'. The provided 'bootstrap()' function implements the 11 | parametric, residual, cases, random effect block (REB), and wild bootstrap 12 | procedures. An overview of these procedures can be found 13 | in Van der Leeden et al. (2008) , 14 | Carpenter, Goldstein & Rasbash (2003) , 15 | and Chambers & Chandra (2013) . 16 | Depends: 17 | R (>= 3.5.0) 18 | Imports: 19 | dplyr (>= 0.8.0), 20 | Matrix, 21 | nlmeU, 22 | ggplot2, 23 | ggdist, 24 | HLMdiag, 25 | purrr, 26 | forcats, 27 | stats, 28 | statmod, 29 | tidyr, 30 | magrittr, 31 | tibble 32 | Suggests: 33 | lme4 (>= 1.1-7), 34 | nlme, 35 | testthat, 36 | mlmRev, 37 | knitr, 38 | rmarkdown, 39 | doParallel, 40 | foreach 41 | License: GPL-3 42 | LazyData: true 43 | URL: https://github.com/aloy/lmeresampler 44 | BugReports: https://github.com/aloy/lmeresampler/issues 45 | RoxygenNote: 7.2.3 46 | VignetteBuilder: knitr 47 | Encoding: UTF-8 48 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(bootstrap,lme) 4 | S3method(bootstrap,merMod) 5 | S3method(bootstrap_pvals,lme) 6 | S3method(bootstrap_pvals,merMod) 7 | S3method(case_bootstrap,lme) 8 | S3method(case_bootstrap,merMod) 9 | S3method(confint,lmeresamp) 10 | S3method(extract_parameters,lme) 11 | S3method(extract_parameters,merMod) 12 | S3method(parametric_bootstrap,lme) 13 | S3method(parametric_bootstrap,merMod) 14 | S3method(plot,lmeresamp) 15 | S3method(print,coef_tbl) 16 | S3method(print,lmeresamp) 17 | S3method(reb_bootstrap,lme) 18 | S3method(reb_bootstrap,lmerMod) 19 | S3method(resid_bootstrap,lme) 20 | S3method(resid_bootstrap,merMod) 21 | S3method(summary,lmeresamp) 22 | S3method(wild_bootstrap,lme) 23 | S3method(wild_bootstrap,lmerMod) 24 | export("%>%") 25 | export(bootstrap) 26 | export(bootstrap_pvals) 27 | export(case_bootstrap) 28 | export(combine_lmeresamp) 29 | export(combine_pvals) 30 | export(extract_parameters) 31 | export(parametric_bootstrap) 32 | export(reb_bootstrap) 33 | export(resid_bootstrap) 34 | export(wild_bootstrap) 35 | import(Matrix) 36 | importFrom(HLMdiag,extract_design) 37 | importFrom(forcats,fct_inorder) 38 | importFrom(ggdist,stat_halfeye) 39 | importFrom(ggplot2,aes) 40 | importFrom(ggplot2,ggplot) 41 | importFrom(ggplot2,labs) 42 | importFrom(magrittr,"%>%") 43 | importFrom(nlmeU,simulateY) 44 | importFrom(purrr,map) 45 | importFrom(purrr,map_dbl) 46 | importFrom(purrr,map_dfr) 47 | importFrom(statmod,rinvgauss) 48 | importFrom(stats,as.formula) 49 | importFrom(stats,confint) 50 | importFrom(stats,cov) 51 | importFrom(stats,family) 52 | importFrom(stats,fitted) 53 | importFrom(stats,formula) 54 | importFrom(stats,getCall) 55 | importFrom(stats,model.frame) 56 | importFrom(stats,model.matrix) 57 | importFrom(stats,model.response) 58 | importFrom(stats,na.exclude) 59 | importFrom(stats,na.omit) 60 | importFrom(stats,napredict) 61 | importFrom(stats,predict) 62 | importFrom(stats,qnorm) 63 | importFrom(stats,quantile) 64 | importFrom(stats,rbinom) 65 | importFrom(stats,resid) 66 | importFrom(stats,rgamma) 67 | importFrom(stats,rnbinom) 68 | importFrom(stats,rnorm) 69 | importFrom(stats,rpois) 70 | importFrom(stats,sd) 71 | importFrom(stats,sigma) 72 | importFrom(stats,simulate) 73 | importFrom(stats,terms) 74 | importFrom(stats,weights) 75 | importFrom(tibble,as_tibble) 76 | importFrom(tidyr,pivot_longer) 77 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | 0.2.4 2 | =========== 3 | 4 | * Adding tests for rboot noise feature. 5 | 6 | 7 | 0.2.3 8 | =========== 9 | 10 | * There are no user-visible changes. This fixes an error with testing on CRAN based on RNG differences. 11 | 12 | 0.2.3 13 | =========== 14 | 15 | BUG FIXES 16 | * `rbootnoise` argument added to residual bootstrap to bypass "system is exactly singular" issues with lme4 models (Credit to Ilmari Tamminen) 17 | * Eliminated unnecessary warnings for unnamed vectors with type = "reb2". 18 | * `bootstrap_pvals()` added mean centering for correction to the calculation 19 | 20 | 0.2.2 21 | =========== 22 | 23 | NEW FEATURES 24 | * Additional auxilliary distributions were added for the Wild bootstrap. There are now 6 options, including the standard normal. 25 | * `.refit` argument can be set to FALSE in order to return the only bootstrap responses. 26 | * `bootstrap_pvals()` appends bootstrap p-values to the summary table for the fixed effects 27 | * `combine_pvals()` provides a way to combine the results of `bootstrap_pvals()` for parallel runs. 28 | 29 | 30 | BUG FIXES 31 | * `plot.lmeresamp()` now works if the replicates are a numeric vector rather than a data frame or tibble. 32 | * bug fixed when `na.action = na.omit` 33 | * fixed issue with transformed variables in `glmer` 34 | 35 | 0.2.1 36 | =========== 37 | 38 | * Unarchiving from CRAN 39 | 40 | DEPENDENCY CHANGE 41 | * Remove `catchr` dependency to avoid issues on CRAN 42 | 43 | BUG FIXES 44 | * message/error/warning summarization in `summary.lmeresamp` has been fixed 45 | * If `var` is omitted from `plot.lmeresamp()` a halfeye plot with all terms is created. 46 | 47 | 0.2.0 48 | ===== 49 | 50 | * The case, parametric, and residual bootstraps now suppport `glmerMod` objects. 51 | * The Wild bootstrap is available for `lme` and `lmerMod` objects. 52 | * The CGR bootstrap is now the default "residual" bootstrap algorithm. 53 | * Objects returned by the `bootstrap()` call are now of class `lmeresamp`. 54 | * `lmeresamp` objects have a new structure, including a new `stats` dataframe (contains the observed value, bootstrap mean, standard error, and bias of each LME model parameter). 55 | * New generic `print()` function that is compatible with `lmeresamp` objects 56 | * New generic `confint()` function that is compatible with `lmeresamp` objects (the possible confidence intervals include: basic, normal, percentile, or all) 57 | * A package vignette is now available 58 | * Vignette outlines how to perform parallelization in `bootstrap()` using the `doParallel` and `foreach` packages 59 | * New `combine()` function that combines processes split for parallelization for unified output 60 | 61 | 0.1.1 62 | ===== 63 | 64 | * Unarchiving from CRAN - back to active development 65 | * Updating for use with the new version of dplyr (>= 0.8.0) 66 | * Bug fixed for `case_bootstrap.lme ` so that `.cases.resamp` can be found 67 | 68 | Version 0.1.0 69 | ============= 70 | 71 | * Initial release, enjoy! 72 | -------------------------------------------------------------------------------- /R/bootstrap_nlme.R: -------------------------------------------------------------------------------- 1 | #' @rdname bootstrap 2 | #' @export 3 | 4 | bootstrap.lme <- function(model, .f = extract_parameters, type, B, resample, reb_type, hccme, aux.dist, orig_data = NULL, .refit = TRUE, rbootnoise = 0){ 5 | 6 | if (rbootnoise != 0) { 7 | stop("'rbootnoise' implemented currently only for LME4 models. Do not define or use default 0.") 8 | } 9 | 10 | switch(type, 11 | parametric = parametric_bootstrap.lme(model, .f, B, .refit), 12 | residual = resid_bootstrap.lme(model, .f, B, .refit, rbootnoise), 13 | case = case_bootstrap.lme(model, .f, B, resample, orig_data, .refit), 14 | reb = reb_bootstrap.lme(model, .f, B, reb_type, .refit), 15 | wild = wild_bootstrap.lme(model, .f, B, hccme, aux.dist, .refit)) 16 | } 17 | 18 | #' @rdname parametric_bootstrap 19 | #' @export 20 | #' @importFrom nlmeU simulateY 21 | parametric_bootstrap.lme <- function(model, .f, B, .refit = TRUE){ 22 | # Match function 23 | if (.refit) { 24 | .f <- match.fun(.f) 25 | t0 <- .f(model) 26 | } 27 | 28 | # Extract fixed effects 29 | # model.fixef <- nlme::fixef(model) 30 | 31 | ystar <- nlmeU::simulateY(model, nsim = B) 32 | row.names(ystar) <- 1:model$dims$N 33 | ystar <- data.frame(ystar) 34 | 35 | if(!.refit) return(ystar) 36 | 37 | refits <- refit_lme(ystar = ystar, model = model, .f = .f) 38 | 39 | .bootstrap.completion(model, tstar = refits$tstar, B, .f, type = "parametric", warnings = refits$warnings) 40 | } 41 | 42 | 43 | 44 | #' @rdname case_bootstrap 45 | #' @export 46 | case_bootstrap.lme <- function(model, .f, B, resample, orig_data = NULL, .refit = TRUE){ 47 | 48 | data <- model$data 49 | # data$.id <- seq_len(nrow(data)) 50 | clusters <- c(names(model$groups), ".id") 51 | 52 | if(length(clusters) != length(resample)) 53 | stop("'resample' is not the same length as the number of grouping variables. 54 | Please specify whether to resample the data at each level of grouping.") 55 | 56 | refits <- purrr::map(integer(B), function(x) 57 | .resample_refit.cases(model = model, .f = .f, dat = data, cluster = clusters, resample = resample, .refit = .refit)) 58 | 59 | tstar <- purrr::map(refits, ~.x) 60 | 61 | if(!.refit) return(tstar) 62 | 63 | .bootstrap.completion(model, tstar = tstar, B, .f, type = "case", 64 | warnings = collect_warnings(.resample_refit.cases)) 65 | } 66 | 67 | 68 | 69 | #' @rdname reb_bootstrap 70 | #' @inheritParams bootstrap 71 | #' @export 72 | reb_bootstrap.lme <- function(model, .f, B, reb_type, .refit = TRUE){ 73 | 74 | if(missing(reb_type)){ 75 | reb_type <- 0 76 | warning("'reb_type' unspecified, performing REB 0 bootstrap") 77 | } 78 | 79 | if(ncol(model$groups) > 1) { 80 | stop("The REB bootstrap has not been adapted for 3+ level models.") 81 | } 82 | 83 | if(!.refit & reb_type == 2) { 84 | stop(".refit == FALSE is not available with reb_type = 2.") 85 | } 86 | 87 | .f <- match.fun(.f) 88 | 89 | # Set up for bootstrapping 90 | setup <- .setup.lme(model, type = "reb", reb_type = reb_type) 91 | 92 | # Generate bootstrap responses 93 | y.star <- replicate( 94 | n = B, 95 | .resample.reb.lme( 96 | Xbeta = setup$Xbeta, 97 | Zlist = setup$Zlist, 98 | Uhat = setup$b, 99 | estar.vec = as.numeric(setup$e), 100 | flist = setup$flist, 101 | levs = setup$levs 102 | ) 103 | ) 104 | 105 | ystar <- as.data.frame(y.star) 106 | 107 | if(!.refit) return(ystar) 108 | 109 | # Extract bootstrap statistics 110 | if(reb_type == 2) .f <- extract_parameters.lme 111 | 112 | refits <- refit_lme(ystar = ystar, model = model, .f = .f) 113 | tstar <- refits$tstar 114 | 115 | # Extract original statistics 116 | t0 <- .f(model) 117 | 118 | # Postprocessing for REB/2 119 | if(reb_type == 2) 120 | tstar <- .postprocess.reb2(t0, tstar, nbeta = length(nlme::fixef(model)), B = B) 121 | 122 | # Format for return 123 | .bootstrap.completion(model, tstar = tstar, B, .f, 124 | type = paste("reb", reb_type, sep = ""), 125 | warnings = refits$warnings) 126 | } 127 | 128 | 129 | 130 | 131 | 132 | #' @rdname resid_bootstrap 133 | #' @inheritParams bootstrap 134 | #' @export 135 | resid_bootstrap.lme <- function(model, .f, B, .refit = TRUE, rbootnoise){ 136 | 137 | .f <- match.fun(.f) 138 | 139 | setup <- .setup.lme(model, type = "residual") 140 | 141 | ystar <- as.data.frame( 142 | replicate( 143 | n = B, 144 | .resample.cgr.lme( 145 | b = setup$b, 146 | e = setup$e, 147 | Xbeta = setup$Xbeta, 148 | Zlist = setup$Zlist, 149 | vclist = setup$vclist, 150 | sig0 = setup$sig0 151 | ) 152 | ) 153 | ) 154 | 155 | if(!.refit) return(ystar) 156 | 157 | refits <- refit_lme(ystar = ystar, model = model, .f = .f) 158 | 159 | .bootstrap.completion(model, tstar = refits$tstar, B, .f, type = "residual", warnings = refits$warnings) 160 | } 161 | 162 | 163 | #' @rdname wild_bootstrap 164 | #' @inheritParams bootstrap 165 | #' @export 166 | wild_bootstrap.lme <- function(model, .f, B, hccme = c("hc2", "hc3"), 167 | aux.dist = c("mammen", "rademacher", 168 | "norm", "webb", "gamma"), 169 | .refit = TRUE){ 170 | 171 | .f <- match.fun(.f) 172 | hccme <- match.arg(hccme) 173 | aux.dist <- match.arg(aux.dist) 174 | 175 | setup <- .setup.lme(model, type = "wild") 176 | 177 | ystar <- as.data.frame( 178 | replicate( 179 | n = B, 180 | .resample.wild( 181 | Xbeta = setup$Xbeta, 182 | mresid = setup$mresid, 183 | .hatvalues = setup$.hatvalues, 184 | hccme = hccme, 185 | aux.dist = aux.dist, 186 | n.lev = setup$n.lev, 187 | flist = setup$flist 188 | ) 189 | ) 190 | ) 191 | 192 | if(!.refit) return(ystar) 193 | 194 | refits <- refit_lme(ystar = ystar, model = model, .f = .f) 195 | 196 | .bootstrap.completion(model, tstar = refits$tstar, B, .f, type = "wild", warnings = refits$warnings) 197 | } 198 | 199 | -------------------------------------------------------------------------------- /R/combine_lmersamp.R: -------------------------------------------------------------------------------- 1 | #' @title Combine bootstrap results 2 | #' 3 | #' @description 4 | #' Combines bootstrap results from processes split for parallelization. 5 | #' 6 | #' @details 7 | #' This helper function combines the different processes split for 8 | #' parallelization to yield unified output and bootstrap statistics. 9 | #' 10 | #' @param ... two or more objects of class \code{lmeresamp}, to be combined into one. 11 | #' 12 | #' @rdname combine 13 | #' @export 14 | #' @importFrom purrr map_dfr map map_dbl 15 | combine_lmeresamp <- function(...) { 16 | boot_list <- list(...) 17 | combo_replicates <- purrr::map_dfr(boot_list, ~as.data.frame(.x$replicates)) 18 | combo_r <- sum(map_dbl(boot_list, ~.x$B)) 19 | RES <- boot_list[[1]] 20 | RES$B <- combo_r 21 | RES$replicates <- combo_replicates 22 | RES$stats$rep.mean <- colMeans(RES$replicates) # recalculated mean 23 | RES$stats$se <- unlist(purrr::map(RES$replicates, sd)) # recalculated se 24 | RES$stats$bias <- RES$stats$rep.mean - RES$stats$observed # recalculated bias 25 | return(RES) 26 | } 27 | 28 | 29 | #' @title Combine p-values 30 | #' 31 | #' @description 32 | #' Combines bootstrap p-values from processes split for parallelization. 33 | #' 34 | #' @details 35 | #' This helper function combines the different summary tables produced by 36 | #' \code{bootstrap_pvals()} when run in parallel to yield unified output 37 | #' and a single summary table. 38 | #' 39 | #' @param ... two or more summary data frames produced by \code{bootstrap_pvals}. 40 | #' 41 | #' @rdname combine_pvals 42 | #' @export 43 | #' @importFrom tibble as_tibble 44 | combine_pvals <- function(...) { 45 | n_extreme <- B <- NULL 46 | pval_list <- list(...) 47 | pval_tbl <- purrr::map_dfr( 48 | pval_list, 49 | ~dplyr::mutate(.x$coefficients, n_extreme = (p.value * (.x$B + 1)) - 1, B = .x$B) 50 | ) 51 | 52 | combo_coef <- pval_tbl %>% 53 | dplyr::group_by(dplyr::across(1:4)) %>% 54 | # dplyr::group_by(term, Estimate, `Std. Error`, `t value`) %>% 55 | dplyr::summarize(p.value = (sum(n_extreme) + 1) / (sum(B) + 1), .groups = "drop_last") %>% 56 | dplyr::ungroup() 57 | 58 | combo_seeds <- purrr::map(pval_list, ~.x$seed) 59 | 60 | combo_r <- sum(map_dbl(pval_list, ~.x$B)) 61 | type <- unique(sapply(pval_list, function(x) x$type)) 62 | 63 | structure( 64 | list(coefficients = combo_coef, B = combo_r, seed = combo_seeds, type = type), 65 | class = "coef_tbl" 66 | ) 67 | } 68 | -------------------------------------------------------------------------------- /R/complete.R: -------------------------------------------------------------------------------- 1 | #' @title Bootstrap Completion 2 | #' 3 | #' @description 4 | #' Finishes the bootstrap process and makes the output readable. 5 | #' 6 | #' @details 7 | #' This function is given \code{model, tstar, B, .f} and uses them to complete 8 | #' the bootstrap process. They are then structured into a list for output and returned. 9 | #' 10 | #' @param tstar The tstar being passed in 11 | #' @inheritParams bootstrap 12 | #' 13 | #' @return list 14 | #' @keywords internal 15 | #' @noRd 16 | .bootstrap.completion <- function(model, tstar, B, .f, type = type, warnings){ 17 | t0 <- .f(model) 18 | 19 | nsim <- length(tstar) 20 | 21 | # tstar <- do.call("cbind", tstar) # Can these be nested? 22 | # row.names(tstar) <- names(t0) 23 | 24 | # if((nfail <- sum(bad.runs <- apply(is.na(tstar), 2, all))) > 0) { 25 | # warning("some bootstrap runs failed (", nfail, "/", nsim, ")") 26 | # fail.msgs <- purrr::map_chr(tstar[bad.runs], .f = attr, FUN.VALUE = character(1), 27 | # "fail.msgs") 28 | # } else fail.msgs <- NULL 29 | 30 | # prep for stats df 31 | 32 | observed <- t0 33 | 34 | if(is.numeric(t0)) { 35 | if(length(t0) == 1) { 36 | replicates <- unlist(tstar) 37 | rep.mean <- mean(replicates) 38 | se <- sd(replicates) 39 | bias <- rep.mean - observed 40 | stats <- dplyr::tibble(observed, rep.mean, se, bias) 41 | } else{ 42 | # Check for names 43 | if(type == "reb2") nms <- names(tstar) 44 | else nms <- unlist(lapply(tstar, names)) 45 | 46 | if(is.null(nms)) 47 | warning("Lists of unnamed vectors are converted to data frames.\nPlease create named vectors in .f() if this is not the desired behavior.", 48 | call. = FALSE) 49 | 50 | tstar <- tstar[vapply(tstar, is.numeric, FUN.VALUE = logical(1))] 51 | replicates <- dplyr::bind_rows(tstar) 52 | rep.mean <- colMeans(replicates) 53 | se <- unlist(purrr::map(replicates, sd)) 54 | bias <- rep.mean - observed 55 | stats <- dplyr::tibble(term = names(t0), observed, rep.mean, se, bias) 56 | } 57 | 58 | } else{ 59 | if(is.data.frame(t0)) { 60 | .ids <- rep(seq_along(tstar), times = vapply(tstar, nrow, FUN.VALUE = 0L)) 61 | replicates <- dplyr::bind_rows(tstar) %>% dplyr::mutate(.n = .ids) 62 | } 63 | stats <- NULL 64 | } 65 | 66 | 67 | if (inherits(model, "lme")) data <- model$data 68 | else data <- model@frame 69 | 70 | RES <- structure(list(observed = observed, model = model, .f = .f, replicates = replicates, 71 | stats = stats, B = B, data = data, 72 | seed = .Random.seed, type = type, call = match.call(), 73 | message = warnings$message, warning = warnings$warning, error = warnings$error), 74 | class = "lmeresamp") 75 | 76 | # attr(RES,"bootFail") <- nfail 77 | # attr(RES,"boot.fail.msgs") <- fail.msgs 78 | return(RES) 79 | } 80 | -------------------------------------------------------------------------------- /R/confint.R: -------------------------------------------------------------------------------- 1 | #' @title Calculate confidence intervals for a lmeresamp object 2 | #' 3 | #' @description 4 | #' Calculates normal, basic, and percentile bootstrap confidence intervals 5 | #' from a \code{lmeresamp} object. 6 | #' 7 | #' 8 | #' @param object The lmeresamp object for which confidence intervals should be computed. 9 | #' @param type A character string giving the type of confidence intervals that should be calculated. 10 | #' This should be a subset of \code{c("norm", "basic", "perc")} (for normal, basic, and percentile 11 | #' bootstrap confidence intervals, respectively), or \code{"all"}. 12 | #' @param level The level at which the confidence interval should be calculated. 13 | #' @param parm not used 14 | #' @param ... not used 15 | #' 16 | #' @return 17 | #' A tibble with columns term, estimate, lower, upper, type, and level. 18 | #' 19 | #' 20 | #' @rdname confint 21 | #' @export 22 | #' @importFrom stats qnorm 23 | confint.lmeresamp <- function(object, parm, level = 0.95, 24 | type = c("all", "norm", "basic", "perc"), 25 | ...) { 26 | term <- estimate <- lower <- upper <- NULL 27 | 28 | if(!level > 0 && !level < 1){ 29 | stop("please specify a confidence level between 0 and 1") 30 | } 31 | 32 | type <- match.arg(type) 33 | 34 | terms <- names(object$observed) 35 | if(is.null(terms)) terms <- "" 36 | orig <- dplyr::tibble(term = terms, estimate = object$observed) 37 | 38 | ci.out <- NULL 39 | if(any(type == "all" | type == "norm")) { 40 | ci.out <- c(ci.out, list(.norm_ci(object, level))) 41 | } 42 | 43 | if(any(type == "all" | type == "basic")) { 44 | ci.out <- c(ci.out, list(.basic_ci(object, level))) 45 | } 46 | 47 | if(any(type == "all" | type == "perc")) { 48 | ci.out <- c(ci.out, list(.perc_ci(object, level))) 49 | } 50 | 51 | ci.out <- lapply( 52 | ci.out, 53 | function(x) dplyr::bind_cols(orig, lower = x[,1], upper = x[,2]) 54 | ) 55 | 56 | if(type == "all") type <- c("norm", "basic", "perc") 57 | names(ci.out) <- type 58 | 59 | dplyr::bind_rows(ci.out, .id = "type") %>% 60 | dplyr::mutate(level = level) %>% 61 | dplyr::select(term, estimate, lower, upper, dplyr::everything()) 62 | } 63 | 64 | 65 | 66 | #' Calculate Percentile Bootstrap CI 67 | #' 68 | #' @description 69 | #' Calculate a percentile bootstrap interval 70 | #' 71 | #' @details 72 | #' This function uses \code{object} and \code{level} to calculate a percentile 73 | #' interval for the components specified by .f 74 | #' 75 | #' @param object An lmeresamp object 76 | #' @param level A confidence level 77 | #' 78 | #' @keywords internal 79 | #' @noRd 80 | .perc_ci <- function(object, level){ 81 | if(typeof(object$replicates) == "list") { 82 | t( 83 | apply(object$replicates, 2, quantile, probs = (1 + c(-level, level)) / 2, na.rm = TRUE) 84 | ) 85 | } else { 86 | t(quantile(object$replicates, probs = (1 + c(-level, level)) / 2, na.rm = TRUE)) 87 | } 88 | } 89 | 90 | 91 | #' Calculate Basic Bootstrap CI 92 | #' 93 | #' @description 94 | #' Calculate a basic bootstrap interval 95 | #' 96 | #' @details 97 | #' This function uses \code{object} and \code{level} to calculate a basic 98 | #' interval for the components specified by .f 99 | #' 100 | #' @param object An lmeresamp object 101 | #' @param level A confidence level 102 | #' 103 | #' @keywords internal 104 | #' @noRd 105 | .basic_ci <- function(object, level){ 106 | if(typeof(object$replicates) == "list") { 107 | quants <- apply(object$replicates, 2, quantile, probs = (1 + c(level, -level))/2) 108 | ci <- 2 * object$observed - t(quants) 109 | colnames(ci) <- rev(colnames(ci)) 110 | } else{ 111 | quants <- quantile(object$replicates, probs = (1 + c(level, -level))/2) 112 | ci <- 2 * object$observed - t(quants) 113 | } 114 | ci 115 | } 116 | 117 | 118 | #' Calculate Normal Bootstrap CI 119 | #' 120 | #' @description 121 | #' Calculate a normal bootstrap interval 122 | #' 123 | #' @details 124 | #' This function uses \code{object} and \code{level} to calculate a normal 125 | #' interval for the components specified by .f 126 | #' 127 | #' @param object An lmeresamp object 128 | #' @param level A confidence level 129 | #' 130 | #' @keywords internal 131 | #' @noRd 132 | .norm_ci <- function(object, level){ 133 | if(typeof(object$replicates) == "list") { 134 | se <- apply(object$replicates, 2, sd, na.rm = TRUE) 135 | } else { 136 | se <- sd(object$replicates, na.rm = TRUE) 137 | } 138 | merr <- se * qnorm((1 + level) / 2) 139 | bias <- object$stats$bias 140 | orig <- object$observed 141 | ci <- cbind(orig - bias - merr, orig - bias + merr) 142 | colnames(ci) <- paste0(100 * (1 + c(-level, level))/2, "%") 143 | ci 144 | } 145 | -------------------------------------------------------------------------------- /R/data.R: -------------------------------------------------------------------------------- 1 | #' Junior school project math score data. 2 | #' 3 | #' A dataset containing 728 students from 50 primary (elementary) schools in inner 4 | #' London that were part of the Junior School Project (JSP). The variables are 5 | #' as follows: 6 | #' 7 | #' @format A data frame with 728 rows and 8 variables. 8 | #' \describe{ 9 | #' \item{mathAge11}{score on math at age 11} 10 | #' \item{mathAge8}{score on math at age 8} 11 | #' \item{gender}{gender, a factor with 2 levels (F, M)} 12 | #' \item{class}{father's social class, a factor with 2 levels (manual, nonmanual)} 13 | #' \item{school}{school code (1-50)} 14 | #' \item{normAge11}{normalized score on math at age 11} 15 | #' \item{normAge8}{normalized score on math at age 8} 16 | #' \item{schoolMathAge8}{average school math score} 17 | #' \item{mathAge8c}{centered math score at age 8} 18 | #' } 19 | #' 20 | #' @docType data 21 | #' @keywords datasets 22 | #' @name jsp728 23 | #' @usage data(jsp728) 24 | #' @source \url{http://www.bristol.ac.uk/cmm/team/hg/msm-3rd-ed/datasets.html} 25 | #' @references 26 | #' Goldstein, H. (2011). Multilevel Statistical Models (4th ed.). Hoboken: Wiley 27 | NULL -------------------------------------------------------------------------------- /R/error_messages.R: -------------------------------------------------------------------------------- 1 | #' Catch errors and warnings 2 | #' 3 | #' This function is modified from a version in lme4, which was based on 4 | #' a factory written by Martin Morgan on Stack Overflow (see below). 5 | #' Factory generates a function which is appropriately wrapped by error handlers. 6 | #' If there are no errors and no warnings, the result is provided. 7 | #' If there are warnings but no errors, the result is provided with a warn attribute set. 8 | #' If there are errors, the result returns is a list with the elements of warn and err. 9 | #' @param fun The function to be turned into a factory 10 | #' @param debug print debugging statements? 11 | #' @param errval the value to be returned from the function if an error is thrown 12 | #' @param types which types to catch? 13 | #' @return The result of the function given to turn into a factory. If this function was in error "An error as occurred" as a character element. factory-error and factory-warning attributes may also be set as appropriate. 14 | #' @references 15 | #' \url{http://stackoverflow.com/questions/4948361/how-do-i-save-warnings-and-errors-as-output-from-a-function} 16 | #' @author Martin Morgan; Modified by Russell S. Pierce and Ben Bolker 17 | #' @noRd 18 | factory <- function (fun, debug=FALSE, 19 | errval="An error occurred in the factory function", 20 | types=c("message","warning","error")) { 21 | function(...) { 22 | errorOccurred <- FALSE 23 | warn <- err <- msg <- NULL 24 | res <- withCallingHandlers(tryCatch(fun(...), 25 | error = function(e) { 26 | if (debug) cat("error: ",conditionMessage(e),"\n") 27 | err <<- conditionMessage(e) 28 | errorOccurred <<- TRUE 29 | NULL 30 | }), warning = function(w) { 31 | if (!"warning" %in% types) { 32 | warning(conditionMessage(w)) 33 | } else { 34 | warn <<- append(warn, conditionMessage(w)) 35 | invokeRestart("muffleWarning") 36 | } 37 | }, 38 | message = function(m) { 39 | if (debug) cat("message: ",conditionMessage(m),"\n") 40 | if (!"message" %in% types) { 41 | message(conditionMessage(m)) 42 | } else { 43 | msg <<- append(msg, conditionMessage(m)) 44 | invokeRestart("muffleMessage") 45 | } 46 | }) 47 | if (errorOccurred) { 48 | if (!"error" %in% types) stop(err) 49 | res <- errval 50 | } 51 | 52 | setattr <- function(x, attrib, value) { 53 | attr(x,attrib) <- value 54 | x 55 | } 56 | 57 | attr_fun <- function(x,str,msg) { 58 | setattr(x,paste0("factory-",str), if(is.character(msg)) msg else NULL) 59 | } 60 | 61 | res <- attr_fun(res, "message", msg) 62 | res <- attr_fun(res, "warning", warn) 63 | res <- attr_fun(res, "error", err) 64 | 65 | return(res) 66 | } 67 | } 68 | 69 | 70 | #' Collect all the warnings, errors, and messages from model refits 71 | #' @noRd 72 | collect_warnings <- function(.x) { 73 | list( 74 | warning = lapply(.x, function(.x) attr(.x, "factory-warning")), 75 | message = lapply(.x, function(.x) attr(.x, "factory-message")), 76 | error = lapply(.x, function(.x) attr(.x, "factory-error")) 77 | ) 78 | } -------------------------------------------------------------------------------- /R/lme4_invlink.R: -------------------------------------------------------------------------------- 1 | ### Provided in lme4/predict.R 2 | #' @importFrom stats family fitted model.frame model.response rbinom 3 | #' rgamma rnbinom rnorm rpois weights 4 | gaussian_simfun <- function(object, nsim, ftd=fitted(object), 5 | wts=weights(object)) { 6 | 7 | if (any(wts != 1)) warning("ignoring prior weights") 8 | rnorm(nsim*length(ftd), ftd, sd=sigma(object)) 9 | } 10 | 11 | binomial_simfun <- function(object, nsim, ftd=fitted(object), 12 | wts=weights(object)) { 13 | n <- length(ftd) 14 | ntot <- n*nsim 15 | if (any(wts %% 1 != 0)) 16 | stop("cannot simulate from non-integer prior.weights") 17 | ## Try to figure out if the original data were 18 | ## proportions, a factor or a two-column matrix 19 | if (!is.null(m <- model.frame(object))) { 20 | y <- model.response(m) 21 | if(is.factor(y)) { 22 | ## ignore weights 23 | yy <- factor(1+rbinom(ntot, size = 1, prob = ftd), 24 | labels = levels(y)) 25 | split(yy, rep(seq_len(nsim), each = n)) 26 | } else if(is.matrix(y) && ncol(y) == 2) { 27 | yy <- vector("list", nsim) 28 | for (i in seq_len(nsim)) { 29 | Y <- rbinom(n, size = wts, prob = ftd) 30 | YY <- cbind(Y, wts - Y) 31 | colnames(YY) <- colnames(y) 32 | yy[[i]] <- YY 33 | } 34 | yy 35 | } else 36 | rbinom(ntot, size = wts, prob = ftd)/wts 37 | } else rbinom(ntot, size = wts, prob = ftd)/wts 38 | } 39 | 40 | poisson_simfun <- function(object, nsim, ftd=fitted(object), 41 | wts=weights(object)) { 42 | ## A Poisson GLM has dispersion fixed at 1, so prior weights 43 | ## do not have a simple unambiguous interpretation: 44 | ## they might be frequency weights or indicate averages. 45 | wts <- weights(object) 46 | if (any(wts != 1)) warning("ignoring prior weights") 47 | rpois(nsim*length(ftd), ftd) 48 | } 49 | 50 | 51 | ## FIXME: need a gamma.shape.merMod method in order for this to work. 52 | ## (see initial shot at gamma.shape.merMod below) 53 | Gamma_simfun <- function(object, nsim, ftd=fitted(object), 54 | wts=weights(object)) { 55 | if (any(wts != 1)) message("using weights to scale shape parameter") 56 | ## used to use gamma.shape(), but sigma() is more general 57 | ## (wouldn't work *outside* of the merMod context though) 58 | shape <- sigma(object)*wts 59 | rgamma(nsim*length(ftd), shape = shape, rate = shape/ftd) 60 | } 61 | 62 | gamma.shape.merMod <- function(object, ...) { 63 | if(family(object)$family != "Gamma") 64 | stop("Can not fit gamma shape parameter because Gamma family not used") 65 | 66 | y <- lme4::getME(object, "y") 67 | mu <- lme4::getME(object, "mu") 68 | w <- weights(object) 69 | # Sec 8.3.2 (MN) 70 | L <- w*(log(y/mu)-((y-mu)/mu)) 71 | dev <- -2*sum(L) 72 | # Eqs. between 8.2 & 8.3 (MN) 73 | Dbar <- dev/length(y) 74 | structure(list(alpha = (6+2*Dbar)/(Dbar*(6+Dbar)), 75 | SE = NA), # FIXME: obtain standard error 76 | class = "gamma.shape") 77 | } 78 | 79 | #' @importFrom statmod rinvgauss 80 | inverse.gaussian_simfun <- function(object, nsim, ftd=fitted(object), 81 | wts = weights(object)) { 82 | if (any(wts != 1)) message("using weights as inverse variances") 83 | statmod::rinvgauss(nsim * length(ftd), mean = ftd, 84 | shape= wts/sigma(object)) 85 | } 86 | 87 | ## in the original MASS version, .Theta is assigned into the environment 88 | ## (triggers a NOTE in R CMD check) 89 | ## modified from @aosmith16 GH contribution 90 | 91 | negative.binomial_simfun <- function (object, nsim, 92 | ftd = fitted(object), 93 | wts=weights(object)) 94 | { 95 | 96 | if (any(wts != 1)) 97 | warning("ignoring prior weights") 98 | theta <- lme4::getME(object, "glmer.nb.theta") 99 | rnbinom(nsim * length(ftd), mu = ftd, size = theta) 100 | } 101 | 102 | simfunList <- list(gaussian = gaussian_simfun, 103 | binomial = binomial_simfun, 104 | poisson = poisson_simfun, 105 | Gamma = Gamma_simfun, 106 | negative.binomial = negative.binomial_simfun, 107 | inverse.gaussian = inverse.gaussian_simfun) -------------------------------------------------------------------------------- /R/lme_utilities.R: -------------------------------------------------------------------------------- 1 | # Extract the residual covariance matrix from an lme object 2 | # .extractR.lme <- function(lme.fit) { 3 | # n <- length( nlme::getResponse(lme.fit) ) 4 | # if (length(lme.fit$group) > 1) { 5 | # stop("not implemented for multiple levels of nesting") 6 | # } 7 | # else{ 8 | # ugroups <- unique(lme.fit$groups[[1]]) 9 | # if (!is.null(lme.fit$modelStruct$corStruct)) { 10 | # V <- Matrix( nlme::corMatrix(lme.fit$modelStruct$corStruct) ) 11 | # } 12 | # else V <- Diagonal(n) 13 | # } 14 | # if (!is.null(lme.fit$modelStruct$varStruct)) 15 | # sds <- 1/nlme::varWeights(lme.fit$modelStruct$varStruct) 16 | # else sds <- rep(1, n) 17 | # sds <- lme.fit$sigma * sds 18 | # cond.var <- t(V * sds) * sds 19 | # 20 | # return(cond.var / lme.fit$sigma^2) 21 | # } 22 | 23 | # Extract the ranef covariance matrix from an lme object 24 | # .extractD.lme <- function(lme.fit) { 25 | # mod.mats <- RLRsim::extract.lmeDesign(lme.fit) 26 | # D <- Matrix( mod.mats$Vr ) 27 | # return(D) 28 | # } 29 | 30 | # Extract the Z matrix from a model 31 | # .extractZ.lme <- function(model){ 32 | # Z.lme <- RLRsim::extract.lmeDesign(model)$Z 33 | # one.Z <- matrix(1, ncol = ncol(Z.lme)/2, nrow = nrow(Z.lme)) 34 | # two.Z <- matrix(2, ncol = ncol(Z.lme)/2, nrow = nrow(Z.lme)) 35 | # my.counter <- 1 36 | # for(i in 1:ncol(Z.lme)){ 37 | # if(i%%2==0){ 38 | # two.Z[,my.counter] <- Z.lme[,i] 39 | # my.counter <- my.counter+1 40 | # }else{ 41 | # one.Z[,my.counter] <- Z.lme[,i]} 42 | # 43 | # } 44 | # one.Z <- t(one.Z) 45 | # two.Z <- t(two.Z) 46 | # Z <- structure(list(one = one.Z, two = two.Z)) 47 | # return(Z) 48 | # } 49 | 50 | # Refit the model 51 | updated.model <- function(model, new.y = NULL, new.data = NULL){ 52 | # Extract formulas and data 53 | mod.fixd <- as.formula(model$call$fixed) 54 | mod.rand <- model$call$random 55 | mod.data <- model$data 56 | if(!is.null(model$na.action) && model$na.action == 8) mod.data <- na.omit(mod.data) 57 | 58 | if(is.null(new.data)){ 59 | # Place ystars in data 60 | mod.data[,as.character(mod.fixd[[2]])] <- unname(new.y) 61 | } 62 | 63 | # create new lme 64 | ctrl <- nlme::lmeControl(opt = 'optim', returnObject = TRUE) 65 | 66 | if(is.null(mod.rand)){ 67 | f1 <- factory( 68 | function(mod.fixd, mod.data, ctrl) 69 | do.call("lme", args = list(fixed = mod.fixd, data = mod.data, control = ctrl)) 70 | ) 71 | out.lme <- f1(mod.fixd, mod.data, ctrl) 72 | } else{ 73 | mod.rand <- as.formula(mod.rand) 74 | f1 <- factory( 75 | function(mod.fixd, mod.data, mod.rand, ctrl) 76 | do.call("lme", args = list(fixed = mod.fixd, data = mod.data, random = mod.rand, control = ctrl)) 77 | ) 78 | out.lme <- f1(mod.fixd, mod.data, mod.rand, ctrl) 79 | } 80 | 81 | out.lme 82 | } 83 | 84 | 85 | #' Refitting lme with error catching 86 | #' @param ystar bootstrapped responses 87 | #' @param model fitted merMod object 88 | #' @param .f function to calc bootstrap stats 89 | #' @keywords internal 90 | #' @noRd 91 | refit_lme <- function(ystar = NULL, model, .f) { 92 | if(!is.null(ystar)) 93 | refits <- purrr::map(ystar, function(y) updated.model(model = model, new.y = y)) 94 | 95 | stats <- purrr::map(refits, ~.f(.x)) 96 | 97 | list(tstar = stats, warnings = collect_warnings(stats)) 98 | } 99 | 100 | 101 | 102 | 103 | 104 | #' Create list of Z matrices, similar to Ztlist in lme4 105 | #' @importFrom forcats fct_inorder 106 | #' @keywords internal 107 | #' @noRd 108 | extract_zlist.lme <- function(model){ 109 | level.num <- ncol(model$groups) 110 | re.form <- formula(model$modelStruct$reStr) 111 | Z <- purrr::map(seq_along(re.form), function(i) model.matrix(formula(model$modelStruct$reStr)[[i]], data=model$data)) 112 | names(Z) <- names(re.form) 113 | 114 | grp <- purrr::map(model$groups, forcats::fct_inorder) 115 | 116 | # if(level.num == 1) { 117 | # Z <- as.data.frame(Z[[1]]) 118 | # Zlist <- purrr::map(Z, function(col) split(col, grp[[1]])) 119 | # 120 | # } else{ 121 | 122 | Z <- purrr::map(Z, as.data.frame) 123 | Z <- Z[rev(names(Z))] # agree w/ order of model$group and bstar 124 | 125 | Zlist <- purrr::map(seq_along(Z), function(i) purrr::map(Z[[i]], function(col) split(col, model$group[,i]))) 126 | names(Zlist) <- names(Z) 127 | # } 128 | Zlist 129 | } 130 | 131 | 132 | .Zbstar.combine.lme <- function(bstar, Zlist){ 133 | zbstar_list <- purrr::map(seq_along(Zlist), function(e) { 134 | z.e <- Zlist[[e]] 135 | b.e <- bstar[[e]] 136 | purrr::map(seq_along(z.e), function(j) unlist(mapply("*", z.e[[j]], b.e[,j], SIMPLIFY = FALSE))) 137 | }) 138 | Reduce("+", unlist(zbstar_list, recursive = FALSE)) 139 | } 140 | 141 | #' @importFrom stats sigma 142 | #' @export 143 | extract_parameters.lme <- function(model) { 144 | sig.e <- stats::sigma(model) 145 | vc <- nlme::getVarCov(model) 146 | 147 | c( 148 | beta = nlme::fixef(model), 149 | vc = c(diag(vc), sig.e^2) 150 | ) 151 | } 152 | -------------------------------------------------------------------------------- /R/lmeresampler.R: -------------------------------------------------------------------------------- 1 | #' lmeresampler: A package for bootstrapping nested linear mixed-effects models 2 | #' 3 | #' The \pkg{lme4} and \pkg{nlme} packages have made fitting nested 4 | #' linear mixed-effects (LME) models quite easy. Using the the 5 | #' functionality of these packages we can easily use maximum 6 | #' likelihood or restricted maximum likelihood to fit a 7 | #' model and conduct inference using our parametric toolkit. 8 | #' In practice, the assumptions of our model are often violated 9 | #' to such a degree that leads to biased estimators and 10 | #' incorrect standard errors. In these situations, resampling 11 | #' methods such as the bootstrap can be used to obtain consistent 12 | #' estimators and standard errors for inference. 13 | #' \code{lmeresampler} provides an easy way to bootstrap nested 14 | #' linear-mixed effects models using either fit using either \pkg{lme4} or 15 | #' \pkg{nlme}. 16 | #' 17 | #' 18 | #' A variety of bootstrap procedures are available: 19 | #' \itemize{ 20 | #' \item the parametric bootstrap: \code{\link{parametric_bootstrap}} 21 | #' \item the residual bootstrap: \code{\link{resid_bootstrap}} 22 | #' \item the cases (i.e. non-parametric) bootstrap: \code{\link{case_bootstrap}} 23 | #' \item the random effects block (REB) bootstrap: \code{\link{reb_bootstrap}} 24 | #' \item the Wild bootstrap: \code{\link{wild_bootstrap}} 25 | #' } 26 | #' 27 | #' In addition to the individual bootstrap functions, \code{lmeresampler} provides 28 | #' a unified interface to bootstrapping LME models in its \code{bootstrap} function. 29 | #' @docType package 30 | #' @name lmeresampler 31 | #' @aliases lmeresampler package-lmeresampler 32 | #' @keywords package 33 | NULL -------------------------------------------------------------------------------- /R/plot.R: -------------------------------------------------------------------------------- 1 | #' @title Plot bootstrap results 2 | #' 3 | #' @description 4 | #' Generate a density plot with a half-eye plot representing the 68% and 95% 5 | #' percentile intervals from an \code{lmeresamp} object. 6 | #' 7 | #' @param x The lmeresamp object to plot. 8 | #' @param var The estimated parameter to plot, as a string or column number. 9 | #' @param ... not used 10 | #' 11 | #' @rdname plot 12 | #' @export 13 | #' @method plot lmeresamp 14 | #' @importFrom ggplot2 ggplot labs aes 15 | #' @importFrom ggdist stat_halfeye 16 | #' @importFrom tidyr pivot_longer 17 | plot.lmeresamp <- function(x, var, ...){ 18 | value <- term <- NULL 19 | if(is.numeric(x$replicates)) { 20 | ggplot2::ggplot(data = NULL, ggplot2::aes(x = x$replicates)) + 21 | ggdist::stat_halfeye(fill = "cadetblue", alpha = 0.5) 22 | } else{ 23 | 24 | # set default 25 | if(missing(var)){ 26 | tidy_reps <- tidyr::pivot_longer( 27 | x$replicates, 28 | cols = dplyr::everything(), 29 | names_to = "term", 30 | values_to = "value" 31 | ) 32 | 33 | ggplot2::ggplot(tidy_reps, ggplot2::aes(x = value, y = term)) + 34 | ggdist::stat_halfeye(fill = "cadetblue", alpha = 0.5) 35 | 36 | } else{ 37 | x$replicates <- as.data.frame(x$replicates) 38 | if(is.numeric(var)) var <- colnames(x$replicates)[var] 39 | if(grepl("[()]", var)) var <- paste0("`", var, "`") 40 | 41 | # to_plot <- unlist(x$replicates[var]) 42 | 43 | ggplot2::ggplot(x$replicates, ggplot2::aes_string(x = var)) + 44 | ggdist::stat_halfeye(fill = "cadetblue", alpha = 0.5) + 45 | ggplot2::labs( 46 | title = paste("Distribution of", var), 47 | x = var, 48 | y = "density" 49 | ) 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /R/print.R: -------------------------------------------------------------------------------- 1 | #' @title Print a summary of an \code{lmeresamp} object 2 | #' 3 | #' @description 4 | #' Print summary statistics and confidence intervals, if desired, for an \code{lmeresamp} object. 5 | #' 6 | #' @details 7 | #' If the bootstrap statistics are stored in a vector (as opposed to a data frame or tibble), 8 | #' then summary statistics will be calculated and printed. The printed data frame will include 9 | #' the name of the term (if applicable), the observed value (\code{observed}), the mean of the bootstrap replicated 10 | #' (\code{rep.mean}), the standard error (\code{se}), and the bootstrap bias estimate (\code{bias}). 11 | #' In addition, the number of resamples will be printed. If any messages, warnings, or errors were 12 | #' generated during the bootstrap procedure, they will be summarized below, and you should check the 13 | #' \code{message}, \code{warning}, and \code{error} elements of the \code{lmeresamp} object to 14 | #' investigate further. 15 | #' 16 | #' @param x The lmeresamp object to print. 17 | #' @param ci A logical value specifying whether confidence intervals should be printed. 18 | #' @param ... not used 19 | #' 20 | #' @rdname print 21 | #' @export 22 | #' @method print lmeresamp 23 | print.lmeresamp <- function(x, ci = FALSE, ...){ 24 | 25 | summary.lmeresamp(x) 26 | 27 | if(ci == TRUE){ 28 | cat(paste("\n")) 29 | cat(paste("\n")) 30 | confint(x) 31 | } 32 | } 33 | 34 | 35 | 36 | #' @title Print coefficients from a \code{coef_tbl} object 37 | #' 38 | #' @description 39 | #' Print table of coefficients produced by \code{bootstrap_pvals}. 40 | #' 41 | #' @param x the coef_tbl object to print 42 | #' @method print coef_tbl 43 | #' @param ... not used 44 | #' @export 45 | print.coef_tbl <- function(x, ...) { 46 | cat(paste("Bootstrap type:", x$type, "\n")) 47 | cat(paste("\n")) 48 | cat(paste("Number of resamples:", x$B, "\n")) 49 | cat(paste("\n")) 50 | print(x$coefficients) 51 | 52 | } -------------------------------------------------------------------------------- /R/pvals.R: -------------------------------------------------------------------------------- 1 | #' @title Calculate Bootstrap p-values for fixed effects 2 | #' 3 | #' @description 4 | #' Perform bootstrap tests based on the t-statistic for each 5 | #' fixed effect in order to calculate approximate p-values. 6 | #' 7 | #' @details 8 | #' The bootstrap test compares the fitted model specified by the user 9 | #' to reduced models that eliminate a single fixed effect, the same 10 | #' comparison summarized by the table of coefficients in the summary. 11 | #' The bootstrap p-value is then calculated as 12 | #' $(n_{extreme} + 1) / (B + 1)$. 13 | #' 14 | #' @return 15 | #' A tibble giving the table of coefficients from the model summary with a column 16 | #' appended containing bootstrap p-values. 17 | #' 18 | #' @references 19 | #' Davison, A., & Hinkley, D. (1997). Tests. In Bootstrap Methods and their 20 | #' Application (Cambridge Series in Statistical and Probabilistic Mathematics, pp. 136-190). 21 | #' Cambridge: Cambridge University Press. doi:10.1017/CBO9780511802843.005 22 | #' 23 | #' @examples 24 | #' \dontrun{ 25 | #' # This takes a while to run 26 | #' bootstrap_pvals.merMod(jsp_mod, type = "wild", B = 1000, hccme = "hc2", aux.dist = "mammen") 27 | #' } 28 | #' 29 | #' @inheritParams bootstrap 30 | #' @export 31 | bootstrap_pvals <- function(model, type, B, resample = NULL, 32 | reb_type = NULL, 33 | hccme = NULL, 34 | aux.dist = NULL) { 35 | if(!type %in% c("parametric", "residual", "case", "wild", "reb")) 36 | stop("'type' must be one of 'parametric', 'residual', 'case', 'wild', or 'reb'") 37 | if(!is.null(reb_type)) 38 | if(!reb_type %in% 0:2) 39 | stop("'reb_type' must be either 0, 1, or 2") 40 | UseMethod("bootstrap_pvals", model) 41 | 42 | } 43 | 44 | #' @rdname bootstrap_pvals 45 | #' @export 46 | #' @method bootstrap_pvals merMod 47 | bootstrap_pvals.merMod <- function(model, type, B, resample = NULL, 48 | reb_type = NULL, 49 | hccme = NULL, 50 | aux.dist = NULL) { 51 | 52 | mod_summary <- summary(model) 53 | tstats <- stats::coef(mod_summary)[, "t value"] 54 | trms <- names(tstats) 55 | # xmat <- lme4::getME(model, "X") 56 | 57 | 58 | pvals <- rep(NA, length(tstats)) 59 | for(i in seq_along(pvals)) { 60 | trm <- trms[i] 61 | if(trm == "(Intercept)") null_mod <- update(model, . ~ . - 1) 62 | else null_mod <- update(model, as.formula(paste(". ~ . -", trm))) 63 | 64 | if(type == "case") { 65 | gen_data <- bootstrap(null_mod, type = type, B = B, .refit = FALSE, 66 | resample = resample, orig_data = model@frame) 67 | } else { 68 | gen_data <- bootstrap(null_mod, type = type, B = B, .refit = FALSE, resample = resample, 69 | reb_type = reb_type, hccme = hccme, aux.dist = aux.dist) 70 | } 71 | 72 | extract_t <- function(x) stats::coef(summary(x))[i, "t value"] 73 | 74 | if(type == "case") { 75 | boot_ts <- purrr::map_dbl(gen_data, ~refit_to_newdf(model, newdata = .x, .f = extract_t)) 76 | } else{ 77 | boot_ts <- unlist(refit_merMod(gen_data, model, .f = extract_t)$tstar) 78 | } 79 | boot_ts <- boot_ts - mean(boot_ts, na.rm = TRUE) 80 | pvals[i] <- (sum(abs(boot_ts) >= abs(tstats[i])) + 1) / (B + 1) 81 | } 82 | 83 | coef_tbl <- cbind(stats::coef(mod_summary), p.value = pvals) %>% 84 | tibble::as_tibble(rownames = "term") 85 | 86 | structure( 87 | list(coefficients = coef_tbl, B = B, seed = .Random.seed, type = type), 88 | class = "coef_tbl" 89 | ) 90 | 91 | 92 | } 93 | 94 | #' @rdname bootstrap_pvals 95 | #' @export 96 | #' @method bootstrap_pvals lme 97 | bootstrap_pvals.lme <- function(model, type, B, resample = NULL, 98 | reb_type = NULL, 99 | hccme = NULL, 100 | aux.dist = NULL) { 101 | 102 | mod_summary <- summary(model) 103 | tstats <- stats::coef(mod_summary)[, "t-value"] 104 | trms <- names(tstats) 105 | 106 | 107 | pvals <- rep(NA, length(tstats)) 108 | for(i in seq_along(pvals)) { 109 | trm <- trms[i] 110 | if(trm == "(Intercept)") null_mod <- update(model, . ~ . - 1) 111 | else null_mod <- update(model, as.formula(paste(". ~ . -", trm))) 112 | 113 | if(type == "case") { 114 | gen_data <- bootstrap(null_mod, type = type, B = B, .refit = FALSE, 115 | resample = resample) 116 | } else { 117 | gen_data <- bootstrap(null_mod, type = type, B = B, .refit = FALSE, resample = resample, 118 | reb_type = reb_type, hccme = hccme, aux.dist = aux.dist) 119 | } 120 | 121 | extract_t <- function(x) stats::coef(summary(x))[i, "t-value"] 122 | 123 | if(type == "case") { 124 | boot_ts <- purrr::map(gen_data, ~updated.model(model, new.data = .x)) %>% 125 | purrr::map_dbl(~extract_t(.x)) 126 | } else{ 127 | boot_ts <- purrr::map(gen_data, ~updated.model(model, new.y = .x)) %>% 128 | purrr::map_dbl(~extract_t(.x)) 129 | } 130 | 131 | boot_ts <- boot_ts - mean(boot_ts, na.rm = TRUE) 132 | pvals[i] <- (sum(abs(boot_ts) >= abs(tstats[i])) + 1) / (B + 1) 133 | } 134 | 135 | coef_tbl <- cbind(stats::coef(mod_summary), p.value = pvals) %>% 136 | tibble::as_tibble(rownames = "term") 137 | 138 | structure( 139 | list(coefficients = coef_tbl, B = B, seed = .Random.seed, type = type), 140 | class = "coef_tbl" 141 | ) 142 | 143 | } 144 | -------------------------------------------------------------------------------- /R/setup.R: -------------------------------------------------------------------------------- 1 | #' Setup for resampling from lmerMod object 2 | #' 3 | #' @inheritParams bootstrap 4 | #' @keywords internal 5 | #' @noRd 6 | .setup <- function(model, type, reb_type = NULL, rbootnoise = 0){ 7 | # Extract marginal means 8 | Xbeta <- predict(model, re.form = NA) # This is X %*% fixef(model) 9 | 10 | # Extract ranef design matrix list 11 | Ztlist <- lme4::getME(object = model, name = "Ztlist") 12 | 13 | level.num <- lme4::getME(object = model, name = "n_rfacs") 14 | 15 | if(type == "reb") { 16 | Z <- lme4::getME(object = model, name = "Z") 17 | mresid <- lme4::getME(model, "y") - Xbeta 18 | 19 | # level-2 resid 20 | b <- solve(t(Z) %*% Z) %*% t(Z) %*% mresid # a single vector 21 | 22 | # level 1 resid 23 | e <- mresid - Z %*% b 24 | 25 | levs <- purrr::map(fl <- model@flist, levels) 26 | cnms <- lme4::getME(model, "cnms") 27 | b <- arrange_ranefs.lmerMod(b, fl, levs, cnms) 28 | } 29 | 30 | if(type == "residual"){ 31 | # Extract and center random effects 32 | b <- purrr::map(lme4::ranef(model), .f = scale, scale = FALSE) 33 | b <- purrr::map(b, as.data.frame) 34 | 35 | # Extract and center error terms 36 | e <- scale(resid(model), scale = FALSE) 37 | } 38 | 39 | if(type == "wild") { 40 | mresid <- lme4::getME(model, "y") - Xbeta 41 | X <- lme4::getME(model, "X") 42 | .hatvalues <- diag(tcrossprod(X %*% solve(crossprod(X)), X)) 43 | flist <- lme4::getME(model, "flist") 44 | if(length(flist) == 1) { 45 | n.lev <- nlevels(flist[[1]]) 46 | flist <- as.numeric(flist[[1]]) 47 | } else { 48 | flist <- lapply(flist, as.character) 49 | flist <- forcats::fct_inorder(do.call("paste", c(flist, sep = ":"))) 50 | n.lev <- nlevels(flist) 51 | flist <- as.numeric(forcats::fct_inorder(flist)) 52 | } 53 | 54 | } 55 | 56 | if (type == "residual" || type == "reb" && reb_type == 1) { 57 | 58 | sig0 <- stats::sigma(model) 59 | 60 | varcor <- lme4::VarCorr(model) 61 | 62 | #Add rbootnoise to 2-level variance when requested 63 | if (rbootnoise != 0) { 64 | varcor[[1]][[1]] <- varcor[[1]][[1]] + (attr(lme4::VarCorr(model), "sc")*rbootnoise)^2 65 | } 66 | vclist <- purrr::map(seq_along(b), .f = ~bdiag(varcor[[names(b)[.x]]])) 67 | names(vclist) <- names(b) 68 | } 69 | 70 | 71 | if(type == "reb" && reb_type == 1){ 72 | if(level.num > 1) stop("reb_type = 1 is not yet implemented for higher order models") 73 | 74 | # Rescale u the residuals *prior* to resampling 75 | # so empirical variance is equal to estimated variance 76 | b <- purrr::map2(b, vclist, scale_center_ranef) 77 | e <- scale_center_e(e, sig0) 78 | } 79 | 80 | if(type %in% c("reb", "residual")) { 81 | RES <- list(Xbeta = Xbeta, b = b, e = e, Ztlist = Ztlist) 82 | 83 | if(type == "reb") { 84 | RES <- append(RES, list(flist = fl, levs = levs)) 85 | } else{ 86 | RES <- append(RES, list(level.num = level.num, sig0 = sig0, vclist = vclist)) 87 | } 88 | } 89 | 90 | if(type == "wild") { 91 | RES <- list(Xbeta = Xbeta, mresid = mresid, .hatvalues = .hatvalues, 92 | flist = flist, n.lev = n.lev) 93 | } 94 | 95 | RES 96 | } 97 | 98 | 99 | 100 | #' Setup for resampling from lme object 101 | #' 102 | #' @inheritParams bootstrap 103 | #' @keywords internal 104 | #' @noRd 105 | #' @importFrom HLMdiag extract_design 106 | .setup.lme <- function(model, type, reb_type = NULL){ 107 | design <- HLMdiag::extract_design(model) 108 | 109 | # Extract marginal means 110 | Xbeta <- predict(model, level = 0) 111 | 112 | # Extract ranef design matrix list 113 | re.struct <- model$modelStruct$reStruct 114 | re.form <- formula(re.struct) 115 | 116 | Zlist <- extract_zlist.lme(model) 117 | 118 | level.num <- ncol(model$groups) 119 | 120 | if(type == "reb") { 121 | Z <- Matrix::Matrix(design$Z) 122 | mresid <- design$Y - Xbeta 123 | 124 | # level-2 resid 125 | b <- solve(t(Z) %*% Z) %*% t(Z) %*% mresid # a single vector 126 | 127 | # level 1 resid 128 | e <- mresid - Z %*% b 129 | 130 | levs <- purrr::map(fl <- model$groups, levels) 131 | cnms <- purrr::map(model$coefficients$random, colnames) 132 | b <- arrange_ranefs.lme(b, fl, levs, cnms) 133 | } 134 | if(type == "residual"){ 135 | # Extract and center random effects 136 | reff <- nlme::ranef(model) 137 | if(level.num == 1) { 138 | reff <- list(reff) 139 | names(reff) <- colnames(model$groups) 140 | } 141 | 142 | b <- purrr::map(reff, .f = scale, scale = FALSE) 143 | b <- purrr::map(b, as.data.frame) 144 | 145 | # Extract and center error terms 146 | e <- scale(resid(model), scale = FALSE) 147 | } 148 | 149 | if(type == "wild") { 150 | mresid <- design$Y - Xbeta 151 | X <- design$X 152 | .hatvalues <- diag(tcrossprod(X %*% solve(crossprod(X)), X)) 153 | flist <- model$groups 154 | flist <- flist[[ncol(flist)]] 155 | n.lev <- nlevels(flist) 156 | flist <- as.numeric(flist) 157 | } 158 | 159 | if(type == "residual" || type == "reb" && reb_type == 1){ 160 | sig0 <- stats::sigma(model) 161 | vclist <- purrr::map( 162 | as.matrix(model$modelStruct$reStruct), 163 | .f = ~.x * sig0^2 164 | ) 165 | } 166 | 167 | if(type == "reb" && reb_type == 1){ 168 | if(level.num > 1) stop("reb_type = 1 is not yet implemented for higher order models") 169 | 170 | # Rescale u the residuals *prior* to resampling 171 | # so empirical variance is equal to estimated variance 172 | b <- purrr::map2(b, vclist, scale_center_ranef) 173 | e <- scale_center_e(e, sig0) 174 | } 175 | 176 | if(type %in% c("reb", "residual")) { 177 | RES <- list(Xbeta = Xbeta, b = b, e = e, Zlist = Zlist) 178 | 179 | if(type == "reb") { 180 | RES <- append(RES, list(flist = fl, levs = levs)) 181 | } else{ 182 | RES <- append(RES, list(level.num = level.num, sig0 = sig0, vclist = vclist)) 183 | } 184 | } 185 | 186 | 187 | if(type == "wild") { 188 | RES <- list(Xbeta = Xbeta, mresid = mresid, .hatvalues = .hatvalues, 189 | flist = flist, n.lev = n.lev) 190 | } 191 | 192 | RES 193 | } 194 | -------------------------------------------------------------------------------- /R/summary.R: -------------------------------------------------------------------------------- 1 | #' @title Calculate summary statistics for \code{lmeresamp} objects 2 | #' 3 | #' @description 4 | #' Calculate basic summary statistics such as the mean, standard error, and bias of the 5 | #' bootstrap replicates. 6 | #' 7 | #' @details 8 | #' If the bootstrap statistics are stored in a vector (as opposed to a data frame or tibble), 9 | #' then summary statistics will be calculated. The printed data frame will include 10 | #' the name of the term (if applicable), the observed value (\code{observed}), the mean of the bootstrap replicated 11 | #' (\code{rep.mean}), the standard error (\code{se}), and the bootstrap bias estimate (\code{bias}). 12 | #' In addition, the number of resamples will be printed. If any messages, warnings, or errors were 13 | #' generated during the bootstrap procedure, they will be summarized below, and you should check the 14 | #' \code{message}, \code{warning}, and \code{error} elements of the \code{lmeresamp} object to 15 | #' investigate further. 16 | #' 17 | #' @param object The lmeresamp object to be summarized. 18 | #' @param ... not used 19 | #' 20 | #' @rdname summary 21 | #' @export 22 | #' @method summary lmeresamp 23 | summary.lmeresamp <- function(object, ...){ 24 | 25 | cat(paste("Bootstrap type:", object$type, "\n")) 26 | cat(paste("\n")) 27 | cat(paste("Number of resamples:", object$B, "\n")) 28 | cat(paste("\n")) 29 | print(as.data.frame(object$stats)) 30 | 31 | messages <- unlist(object$message) 32 | warnings <- unlist(object$warnings) 33 | errors <- unlist(object$error) 34 | 35 | cat(paste("\n")) 36 | cat(paste("There were", length(messages), "messages,", 37 | length(warnings), "warnings, and", 38 | length(errors), "errors.")) 39 | cat(paste("\n")) 40 | 41 | # finding most commonly occuring message/warning/error 42 | object$message <- as.factor(messages) 43 | object$warning <- as.factor(warnings) 44 | object$error <- as.factor(errors) 45 | 46 | top_message <- names(sort(summary(object$message), decreasing=T)[1]) 47 | if(!is.null(top_message)){ 48 | cat(paste("\n")) 49 | cat(paste("The most commonly occurring message was:", top_message)) 50 | cat(paste("\n")) 51 | } 52 | 53 | top_warning <- names(sort(summary(object$warning), decreasing=T)[1]) 54 | if(!is.null(top_warning)){ 55 | cat(paste("\n")) 56 | cat(paste("The most commonly occurring warning was:", top_warning)) 57 | cat(paste("\n")) 58 | } 59 | 60 | top_error <- names(sort(summary(object$error), decreasing=T)[1]) 61 | if(!is.null(top_error)){ 62 | cat(paste("\n")) 63 | cat(paste("The most commonly occurring error was:", top_error)) 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | #' @param lhs A value or the magrittr placeholder. 12 | #' @param rhs A function call using the magrittr semantics. 13 | #' @return The result of calling `rhs(lhs)`. 14 | NULL 15 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | # lmeresampler 6 | 7 | [![R-CMD-check](https://github.com/aloy/lmeresampler/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/aloy/lmeresampler/actions/workflows/R-CMD-check.yaml) 8 | [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/lmeresampler)](https://cran.r-project.org/package=lmeresampler) 9 | ![CRAN_Downloads_Badge](http://cranlogs.r-pkg.org/badges/lmersesampler) 10 | 11 | 12 | 13 | ```{r, echo = FALSE} 14 | knitr::opts_chunk$set( 15 | collapse = TRUE, 16 | comment = "#>", 17 | fig.path = "README-" 18 | ) 19 | ``` 20 | 21 | 22 | The `lme4` and `nlme` packages have made fitting nested linear mixed-effects models quite easy. Using the functionality of these packages we can easily use maximum likelihood or restricted maximum likelihood to fit our model and conduct inference using our parametric toolkit. In practice, the assumptions of our model are often violated to such a degree that leads to biased estimators and incorrect standard errors. In these situations, resampling methods such as the bootstrap can be used to obtain consistent estimators of the bias and standard errors for inference. `lmeresampler` provides an easy way to bootstrap nested linear-mixed effects models using the parametric, residual, cases, wild, or random effects block (REB) bootstraps fit using either `lme4` or `nlme`. The output from `lmeresampler` is an `lmeresamp` object. Moreover, the `lmeresampler` package has its own `print()`, `summary()`, `confint()`, and `plot()` functions. All of these functions follow the syntax of generic `print()`, `summary()`, `confint()`, and `plot()` functions; thus, the commands may be used with `lmeresamp` objects. 23 | 24 | ## Installation 25 | 26 | You can install the latest released version from CRAN with: 27 | 28 | ```{r eval=FALSE} 29 | install.packages("lmeresampler") 30 | ``` 31 | 32 | or the latest development version from GitHub: 33 | 34 | ```{r eval=FALSE} 35 | if(!require(devtools)) install.packages("devtools") 36 | devtools::install_github("aloy/lmeresampler") 37 | ``` 38 | 39 | ## Usage 40 | 41 | Below is a short example of how to execute a parametric bootstrap for models fit either by `lme4` or by `nlme`. For a complete guide outlining the purpose of `lmeresampler`, the structure of `lmeresamp` objects, each of the bootstrap types, how to implement parallelization with `bootstrap()` calls, directions for future developers, and examples, please see the package vignette, available on the `lmeresampler` website. 42 | 43 | First, fit the necessary model(s) with the LME package of your choice. Here we show the same model fit first with `lme4`, then with `nlme`: 44 | 45 | ```{r, results = FALSE, message = FALSE} 46 | library(lmeresampler) 47 | 48 | library(lme4) 49 | vcmodA <- lmer(mathAge11 ~ mathAge8 + gender + class + (1 | school), data = jsp728) 50 | 51 | library(nlme) 52 | vcmodB <- lme(mathAge11 ~ mathAge8 + gender + class, random = ~1|school, data = jsp728) 53 | ``` 54 | 55 | Now, to perform a parametric bootstrap, first specify the model to be used, then the function to return the parameters of interest, then `type = "parametric`, and finally, the number of bootstrap resamples to be computed: 56 | 57 | ```{r} 58 | # let's set .f = fixef to specify that we want only the fixed effects bootstrapped 59 | 60 | # lme4 61 | lmer_par_boot <- bootstrap(vcmodA, .f = fixef, type = "parametric", B = 100) 62 | 63 | # nlme 64 | lme_par_boot <- bootstrap(vcmodB, .f = fixef, type = "parametric", B = 100) 65 | ``` 66 | 67 | The four other bootstrap types (residual, cases, wild, and REB) may be executed in a similar way, with some minor changes. 68 | 69 | ## References 70 | 71 | A full list of references may be found in the package vignette. 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # lmeresampler 3 | 4 | [![R-CMD-check](https://github.com/aloy/lmeresampler/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/aloy/lmeresampler/actions/workflows/R-CMD-check.yaml) 5 | [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/lmeresampler)](https://cran.r-project.org/package=lmeresampler) 6 | ![CRAN_Downloads_Badge](http://cranlogs.r-pkg.org/badges/lmersesampler) 7 | 8 | 9 | 10 | The `lme4` and `nlme` packages have made fitting nested linear 11 | mixed-effects models quite easy. Using the functionality of these 12 | packages we can easily use maximum likelihood or restricted maximum 13 | likelihood to fit our model and conduct inference using our parametric 14 | toolkit. In practice, the assumptions of our model are often violated to 15 | such a degree that leads to biased estimators and incorrect standard 16 | errors. In these situations, resampling methods such as the bootstrap 17 | can be used to obtain consistent estimators of the bias and standard 18 | errors for inference. `lmeresampler` provides an easy way to bootstrap 19 | nested linear-mixed effects models using the parametric, residual, 20 | cases, wild, or random effects block (REB) bootstraps fit using either 21 | `lme4` or `nlme`. The output from `lmeresampler` is an `lmeresamp` 22 | object. Moreover, the `lmeresampler` package has its own `print()`, 23 | `summary()`, `confint()`, and `plot()` functions. All of these functions 24 | follow the syntax of generic `print()`, `summary()`, `confint()`, and 25 | `plot()` functions; thus, the commands may be used with `lmeresamp` 26 | objects. 27 | 28 | ## Installation 29 | 30 | You can install the latest released version from CRAN with: 31 | 32 | ``` r 33 | install.packages("lmeresampler") 34 | ``` 35 | 36 | or the latest development version from GitHub: 37 | 38 | ``` r 39 | if(!require(devtools)) install.packages("devtools") 40 | devtools::install_github("aloy/lmeresampler") 41 | ``` 42 | 43 | ## Usage 44 | 45 | Below is a short example of how to execute a parametric bootstrap for 46 | models fit either by `lme4` or by `nlme`. For a complete guide outlining 47 | the purpose of `lmeresampler`, the structure of `lmeresamp` objects, 48 | each of the bootstrap types, how to implement parallelization with 49 | `bootstrap()` calls, directions for future developers, and examples, 50 | please see the package vignette, available on the `lmeresampler` 51 | website. 52 | 53 | First, fit the necessary model(s) with the LME package of your choice. 54 | Here we show the same model fit first with `lme4`, then with `nlme`: 55 | 56 | ``` r 57 | library(lmeresampler) 58 | 59 | library(lme4) 60 | vcmodA <- lmer(mathAge11 ~ mathAge8 + gender + class + (1 | school), data = jsp728) 61 | 62 | library(nlme) 63 | vcmodB <- lme(mathAge11 ~ mathAge8 + gender + class, random = ~1|school, data = jsp728) 64 | ``` 65 | 66 | Now, to perform a parametric bootstrap, first specify the model to be 67 | used, then the function to return the parameters of interest, then 68 | `type = "parametric`, and finally, the number of bootstrap resamples to 69 | be computed: 70 | 71 | ``` r 72 | # let's set .f = fixef to specify that we want only the fixed effects bootstrapped 73 | 74 | # lme4 75 | lmer_par_boot <- bootstrap(vcmodA, .f = fixef, type = "parametric", B = 100) 76 | 77 | # nlme 78 | lme_par_boot <- bootstrap(vcmodB, .f = fixef, type = "parametric", B = 100) 79 | ``` 80 | 81 | The four other bootstrap types (residual, cases, wild, and REB) may be 82 | executed in a similar way, with some minor changes. 83 | 84 | ## References 85 | 86 | A full list of references may be found in the package vignette. 87 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | template: 2 | params: 3 | bootswatch: yeti 4 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | 2 | This is essentially a resubmission to address errors caused by my recent submission that were unexpected based on my testing. I apologize for a new submission so quickly. 3 | 4 | In this version I have: 5 | 6 | * Failing tests are skipped on CRAN as they are not robust to different operating systems. They will be edited and changed on the development version and tested via continuous integration. 7 | 8 | ## Test environments 9 | Windows (github actions - release, win-builder - devel and release) 10 | macOS (local, github actions) 11 | Ubuntu (github actions, r-hub) 12 | Fedora (r-hub) 13 | 14 | 15 | ## R CMD check results 16 | There were no ERRORs or WARNINGs. 17 | 18 | There was 1 NOTE generated only on win-builder windows release: 19 | 20 | * checking CRAN incoming feasibility ... NOTE 21 | Maintainer: ‘Adam Loy ’ 22 | 23 | Found the following (possibly) invalid DOIs: 24 | DOI: 10.1111/1467-9876.00415 25 | From: DESCRIPTION 26 | Status: Service Unavailable 27 | Message: 503 28 | 29 | This DOI is valid, and I did not receive an error navigating there in a web browser 30 | -------------------------------------------------------------------------------- /data/jsp728.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/data/jsp728.RData -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • lmeresampler 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 122 | 123 | 124 | 125 |
126 | 127 |
128 |
129 | 132 | 133 | Content not found. Please use links in the navbar. 134 | 135 |
136 | 137 | 142 | 143 |
144 | 145 | 146 | 147 |
148 | 151 | 152 |
153 |

Site built with pkgdown 1.6.1.

154 |
155 | 156 |
157 |
158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /docs/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/articles/Vignette_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • lmeresampler 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 122 | 123 | 124 | 125 |
126 | 127 |
128 |
129 | 132 | 133 |
134 |

All vignettes

135 |

136 | 137 |
138 |
Vignette
139 |
140 |
141 |
142 |
143 |
144 | 145 | 146 |
147 | 150 | 151 |
152 |

Site built with pkgdown 1.6.1.

153 |
154 | 155 |
156 |
157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /docs/articles/lmeresampler-vignette_files/accessible-code-block-0.0.1/empty-anchor.js: -------------------------------------------------------------------------------- 1 | // Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) --> 2 | // v0.0.1 3 | // Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020. 4 | 5 | document.addEventListener('DOMContentLoaded', function() { 6 | const codeList = document.getElementsByClassName("sourceCode"); 7 | for (var i = 0; i < codeList.length; i++) { 8 | var linkList = codeList[i].getElementsByTagName('a'); 9 | for (var j = 0; j < linkList.length; j++) { 10 | if (linkList[j].innerHTML === "") { 11 | linkList[j].setAttribute('aria-hidden', 'true'); 12 | } 13 | } 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /docs/articles/lmeresampler-vignette_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/articles/lmeresampler-vignette_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/lmeresampler-vignette_files/figure-html/unnamed-chunk-2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/articles/lmeresampler-vignette_files/figure-html/unnamed-chunk-2-2.png -------------------------------------------------------------------------------- /docs/articles/lmeresampler-vignette_files/figure-html/unnamed-chunk-2-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/articles/lmeresampler-vignette_files/figure-html/unnamed-chunk-2-3.png -------------------------------------------------------------------------------- /docs/articles/lmeresampler-vignette_files/header-attrs-2.11/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/lmeresampler-vignette_files/header-attrs-2.13/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/lmeresampler-vignette_files/header-attrs-2.7/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Authors • lmeresampler 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 122 | 123 | 124 | 125 |
126 | 127 |
128 |
129 | 132 | 133 |
    134 |
  • 135 |

    Adam Loy. Author, maintainer. 136 |

    137 |
  • 138 |
  • 139 |

    Spenser Steele. Author. 140 |

    141 |
  • 142 |
  • 143 |

    Jenna Korobova. Author. 144 |

    145 |
  • 146 |
147 | 148 |
149 | 150 |
151 | 152 | 153 | 154 |
155 | 158 | 159 |
160 |

Site built with pkgdown 1.6.1.

161 |
162 | 163 |
164 |
165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/favicon-16x16.png -------------------------------------------------------------------------------- /docs/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/favicon-32x32.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/favicon.ico -------------------------------------------------------------------------------- /docs/image/FINAL_HEX_nobackground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/image/FINAL_HEX_nobackground.png -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/logo.png -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $(".examples, div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent; 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.11.4 2 | pkgdown: 1.6.1 3 | pkgdown_sha: ~ 4 | articles: 5 | lmeresampler-vignette: lmeresampler-vignette.html 6 | last_built: 2022-04-29T13:57Z 7 | 8 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/docs/reference/figures/logo.png -------------------------------------------------------------------------------- /docs/reference/print.coef_tbl.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Print coefficients from a coef_tbl object — print.coef_tbl • lmeresampler 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
    71 |
    72 | 123 | 124 | 125 | 126 |
    127 | 128 |
    129 |
    130 | 135 | 136 |
    137 |

    Print table of coefficients produced by bootstrap_pvals.

    138 |
    139 | 140 |
    print.coef_tbl(x)
    141 | 142 |

    Arguments

    143 | 144 | 145 | 146 | 147 | 148 | 149 |
    x

    the coef_tbl object to print

    150 | 151 | 152 |
    153 | 158 |
    159 | 160 | 161 |
    162 | 165 | 166 |
    167 |

    Site built with pkgdown 1.6.1.

    168 |
    169 | 170 |
    171 |
    172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /inst/image/FINAL_HEX_nobackground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/inst/image/FINAL_HEX_nobackground.png -------------------------------------------------------------------------------- /man/bootstrap_pvals.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pvals.R 3 | \name{bootstrap_pvals} 4 | \alias{bootstrap_pvals} 5 | \alias{bootstrap_pvals.merMod} 6 | \alias{bootstrap_pvals.lme} 7 | \title{Calculate Bootstrap p-values for fixed effects} 8 | \usage{ 9 | bootstrap_pvals( 10 | model, 11 | type, 12 | B, 13 | resample = NULL, 14 | reb_type = NULL, 15 | hccme = NULL, 16 | aux.dist = NULL 17 | ) 18 | 19 | \method{bootstrap_pvals}{merMod}( 20 | model, 21 | type, 22 | B, 23 | resample = NULL, 24 | reb_type = NULL, 25 | hccme = NULL, 26 | aux.dist = NULL 27 | ) 28 | 29 | \method{bootstrap_pvals}{lme}( 30 | model, 31 | type, 32 | B, 33 | resample = NULL, 34 | reb_type = NULL, 35 | hccme = NULL, 36 | aux.dist = NULL 37 | ) 38 | } 39 | \arguments{ 40 | \item{model}{The model object you wish to bootstrap.} 41 | 42 | \item{type}{A character string indicating the type of bootstrap that is being 43 | requested. Possible values are \code{"parametric"}, \code{"residual"}, 44 | \code{"case"}, \code{"wild"}, or \code{"reb"} 45 | (random effect block bootstrap).} 46 | 47 | \item{B}{The number of bootstrap resamples.} 48 | 49 | \item{resample}{A logical vector specifying whether each level of the model 50 | should be resampled in the cases bootstrap. The levels should be specified 51 | from the highest level (largest cluster) of the hierarchy to the lowest 52 | (observation-level); for example for students within a school, specify the 53 | school level first, then the student level.} 54 | 55 | \item{reb_type}{Specification of what random effect block bootstrap version to 56 | implement. Possible values are \code{0}, \code{1} or \code{2}.} 57 | 58 | \item{hccme}{either \code{"hc2"} or \code{"hc3"}, indicating which 59 | heteroscedasticity consistent covariance matrix estimator to use.} 60 | 61 | \item{aux.dist}{one of \code{"mammen"}, \code{"rademacher"}, \code{"norm"}, 62 | \code{"webb"}, or \code{"gamma"} indicating which auxiliary 63 | distribution to draw the errors from} 64 | } 65 | \value{ 66 | A tibble giving the table of coefficients from the model summary with a column 67 | appended containing bootstrap p-values. 68 | } 69 | \description{ 70 | Perform bootstrap tests based on the t-statistic for each 71 | fixed effect in order to calculate approximate p-values. 72 | } 73 | \details{ 74 | The bootstrap test compares the fitted model specified by the user 75 | to reduced models that eliminate a single fixed effect, the same 76 | comparison summarized by the table of coefficients in the summary. 77 | The bootstrap p-value is then calculated as 78 | $(n_{extreme} + 1) / (B + 1)$. 79 | } 80 | \examples{ 81 | \dontrun{ 82 | # This takes a while to run 83 | bootstrap_pvals.merMod(jsp_mod, type = "wild", B = 1000, hccme = "hc2", aux.dist = "mammen") 84 | } 85 | 86 | } 87 | \references{ 88 | Davison, A., & Hinkley, D. (1997). Tests. In Bootstrap Methods and their 89 | Application (Cambridge Series in Statistical and Probabilistic Mathematics, pp. 136-190). 90 | Cambridge: Cambridge University Press. doi:10.1017/CBO9780511802843.005 91 | } 92 | -------------------------------------------------------------------------------- /man/case_bootstrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bootstrap_lme4.R, R/bootstrap_nlme.R, 3 | % R/generics.R 4 | \name{case_bootstrap.merMod} 5 | \alias{case_bootstrap.merMod} 6 | \alias{case_bootstrap.lme} 7 | \alias{case_bootstrap} 8 | \title{Cases Bootstrap for Nested LMEs} 9 | \usage{ 10 | \method{case_bootstrap}{merMod}(model, .f, B, resample, orig_data = NULL, .refit = TRUE) 11 | 12 | \method{case_bootstrap}{lme}(model, .f, B, resample, orig_data = NULL, .refit = TRUE) 13 | 14 | case_bootstrap(model, .f, B, resample, orig_data = NULL, .refit = TRUE) 15 | } 16 | \arguments{ 17 | \item{model}{The model object you wish to bootstrap.} 18 | 19 | \item{.f}{A function returning the statistic(s) of interest.} 20 | 21 | \item{B}{The number of bootstrap resamples.} 22 | 23 | \item{resample}{A logical vector specifying whether each level of the model 24 | should be resampled in the cases bootstrap. The levels should be specified 25 | from the highest level (largest cluster) of the hierarchy to the lowest 26 | (observation-level); for example for students within a school, specify the 27 | school level first, then the student level.} 28 | 29 | \item{orig_data}{the original data frame. This should be specified if variables 30 | are transformed within the formula for \code{glmer()} or \code{lmer()} 31 | and the case bootstrap is used.} 32 | 33 | \item{.refit}{a logical value indicating whether the model should be refit to 34 | the bootstrap resample, or if the simulated bootstrap resample should be 35 | returned. Defaults to \code{TRUE}.} 36 | } 37 | \value{ 38 | The returned value is an object of class "lmeresamp". 39 | } 40 | \description{ 41 | Generate cases bootstrap replicates of a statistic for a nested linear 42 | mixed-effects model. 43 | } 44 | \details{ 45 | The cases bootstrap is a fully nonparametric bootstrap that resamples the data 46 | with respect to the clusters in order to generate bootstrap samples. Depending 47 | on the nature of the data, the resampling can be done only for the higher-level 48 | cluster(s), only at the observation-level within a cluster, or at all levels. 49 | See Van der Leeden et al. (2008) for a nice discussion of this decision. 50 | 51 | To resample a given level of the model, the corresponding entry in the logical 52 | vector specified in the \code{resample} parameter must be set to true. A few 53 | examples are given below in terms of a two-level model where students are 54 | clustered within schools: 55 | 56 | \itemize{ 57 | \item To resample only the schools, set \code{resample = c(TRUE, FALSE)}. 58 | \item To resample only the students, set \code{resample = c(FALSE, TRUE)}. 59 | \item To resample both the students and the schools, set \code{resample = c(TRUE, TRUE)}. 60 | } 61 | } 62 | \references{ 63 | Van der Leeden, R., Meijer, E. and Busing F. M. (2008) Resampling multilevel 64 | models. In J. de Leeuw and E. Meijer, editors, \emph{Handbook of 65 | Multilevel Analysis}, pages 401--433. New York: Springer. 66 | } 67 | \seealso{ 68 | \itemize{ 69 | \item Examples are given in \code{\link{bootstrap}} 70 | \item \code{\link{parametric_bootstrap}}, \code{\link{resid_bootstrap}}, 71 | \code{\link{case_bootstrap}}, \code{\link{reb_bootstrap}}, 72 | \code{\link{wild_bootstrap}} for more details on a specific bootstrap. 73 | \item \code{\link[lme4]{bootMer}} in the \pkg{lme4} package for an 74 | implementation of (semi-)parametric bootstrap for mixed models. 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /man/combine.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/combine_lmersamp.R 3 | \name{combine_lmeresamp} 4 | \alias{combine_lmeresamp} 5 | \title{Combine bootstrap results} 6 | \usage{ 7 | combine_lmeresamp(...) 8 | } 9 | \arguments{ 10 | \item{...}{two or more objects of class \code{lmeresamp}, to be combined into one.} 11 | } 12 | \description{ 13 | Combines bootstrap results from processes split for parallelization. 14 | } 15 | \details{ 16 | This helper function combines the different processes split for 17 | parallelization to yield unified output and bootstrap statistics. 18 | } 19 | -------------------------------------------------------------------------------- /man/combine_pvals.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/combine_lmersamp.R 3 | \name{combine_pvals} 4 | \alias{combine_pvals} 5 | \title{Combine p-values} 6 | \usage{ 7 | combine_pvals(...) 8 | } 9 | \arguments{ 10 | \item{...}{two or more summary data frames produced by \code{bootstrap_pvals}.} 11 | } 12 | \description{ 13 | Combines bootstrap p-values from processes split for parallelization. 14 | } 15 | \details{ 16 | This helper function combines the different summary tables produced by 17 | \code{bootstrap_pvals()} when run in parallel to yield unified output 18 | and a single summary table. 19 | } 20 | -------------------------------------------------------------------------------- /man/confint.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/confint.R 3 | \name{confint.lmeresamp} 4 | \alias{confint.lmeresamp} 5 | \title{Calculate confidence intervals for a lmeresamp object} 6 | \usage{ 7 | \method{confint}{lmeresamp}( 8 | object, 9 | parm, 10 | level = 0.95, 11 | type = c("all", "norm", "basic", "perc"), 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{object}{The lmeresamp object for which confidence intervals should be computed.} 17 | 18 | \item{parm}{not used} 19 | 20 | \item{level}{The level at which the confidence interval should be calculated.} 21 | 22 | \item{type}{A character string giving the type of confidence intervals that should be calculated. 23 | This should be a subset of \code{c("norm", "basic", "perc")} (for normal, basic, and percentile 24 | bootstrap confidence intervals, respectively), or \code{"all"}.} 25 | 26 | \item{...}{not used} 27 | } 28 | \value{ 29 | A tibble with columns term, estimate, lower, upper, type, and level. 30 | } 31 | \description{ 32 | Calculates normal, basic, and percentile bootstrap confidence intervals 33 | from a \code{lmeresamp} object. 34 | } 35 | -------------------------------------------------------------------------------- /man/extract_parameters.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/generics.R 3 | \name{extract_parameters} 4 | \alias{extract_parameters} 5 | \title{Extract parameters from LME models} 6 | \usage{ 7 | extract_parameters(model) 8 | } 9 | \arguments{ 10 | \item{model}{the fitted model object, either an \code{merMod} or \code{lme} object.} 11 | } 12 | \value{ 13 | A named vector of parameters. 14 | } 15 | \description{ 16 | A utility function that extracts the fixed effects and variance component 17 | estimates from a fitted \code{merMod} or \code{lme} object. 18 | } 19 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/man/figures/logo.png -------------------------------------------------------------------------------- /man/jsp728.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{jsp728} 5 | \alias{jsp728} 6 | \title{Junior school project math score data.} 7 | \format{ 8 | A data frame with 728 rows and 8 variables. 9 | \describe{ 10 | \item{mathAge11}{score on math at age 11} 11 | \item{mathAge8}{score on math at age 8} 12 | \item{gender}{gender, a factor with 2 levels (F, M)} 13 | \item{class}{father's social class, a factor with 2 levels (manual, nonmanual)} 14 | \item{school}{school code (1-50)} 15 | \item{normAge11}{normalized score on math at age 11} 16 | \item{normAge8}{normalized score on math at age 8} 17 | \item{schoolMathAge8}{average school math score} 18 | \item{mathAge8c}{centered math score at age 8} 19 | } 20 | } 21 | \source{ 22 | \url{http://www.bristol.ac.uk/cmm/team/hg/msm-3rd-ed/datasets.html} 23 | } 24 | \usage{ 25 | data(jsp728) 26 | } 27 | \description{ 28 | A dataset containing 728 students from 50 primary (elementary) schools in inner 29 | London that were part of the Junior School Project (JSP). The variables are 30 | as follows: 31 | } 32 | \references{ 33 | Goldstein, H. (2011). Multilevel Statistical Models (4th ed.). Hoboken: Wiley 34 | } 35 | \keyword{datasets} 36 | -------------------------------------------------------------------------------- /man/lmeresampler.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lmeresampler.R 3 | \docType{package} 4 | \name{lmeresampler} 5 | \alias{lmeresampler} 6 | \alias{package-lmeresampler} 7 | \title{lmeresampler: A package for bootstrapping nested linear mixed-effects models} 8 | \description{ 9 | The \pkg{lme4} and \pkg{nlme} packages have made fitting nested 10 | linear mixed-effects (LME) models quite easy. Using the the 11 | functionality of these packages we can easily use maximum 12 | likelihood or restricted maximum likelihood to fit a 13 | model and conduct inference using our parametric toolkit. 14 | In practice, the assumptions of our model are often violated 15 | to such a degree that leads to biased estimators and 16 | incorrect standard errors. In these situations, resampling 17 | methods such as the bootstrap can be used to obtain consistent 18 | estimators and standard errors for inference. 19 | \code{lmeresampler} provides an easy way to bootstrap nested 20 | linear-mixed effects models using either fit using either \pkg{lme4} or 21 | \pkg{nlme}. 22 | } 23 | \details{ 24 | A variety of bootstrap procedures are available: 25 | \itemize{ 26 | \item the parametric bootstrap: \code{\link{parametric_bootstrap}} 27 | \item the residual bootstrap: \code{\link{resid_bootstrap}} 28 | \item the cases (i.e. non-parametric) bootstrap: \code{\link{case_bootstrap}} 29 | \item the random effects block (REB) bootstrap: \code{\link{reb_bootstrap}} 30 | \item the Wild bootstrap: \code{\link{wild_bootstrap}} 31 | } 32 | 33 | In addition to the individual bootstrap functions, \code{lmeresampler} provides 34 | a unified interface to bootstrapping LME models in its \code{bootstrap} function. 35 | } 36 | \keyword{package} 37 | -------------------------------------------------------------------------------- /man/parametric_bootstrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bootstrap_lme4.R, R/bootstrap_nlme.R, 3 | % R/generics.R 4 | \name{parametric_bootstrap.merMod} 5 | \alias{parametric_bootstrap.merMod} 6 | \alias{parametric_bootstrap.lme} 7 | \alias{parametric_bootstrap} 8 | \title{Parametric Bootstrap for Nested LMEs} 9 | \usage{ 10 | \method{parametric_bootstrap}{merMod}(model, .f, B, .refit = TRUE) 11 | 12 | \method{parametric_bootstrap}{lme}(model, .f, B, .refit = TRUE) 13 | 14 | parametric_bootstrap(model, .f, B, .refit = TRUE) 15 | } 16 | \arguments{ 17 | \item{model}{The model object you wish to bootstrap.} 18 | 19 | \item{.f}{A function returning the statistic(s) of interest.} 20 | 21 | \item{B}{The number of bootstrap resamples.} 22 | 23 | \item{.refit}{a logical value indicating whether the model should be refit to 24 | the bootstrap resample, or if the simulated bootstrap resample should be 25 | returned. Defaults to \code{TRUE}.} 26 | } 27 | \value{ 28 | The returned value is an object of class "lmeresamp". 29 | } 30 | \description{ 31 | Generate parametric bootstrap replicates of a statistic for a nested linear 32 | mixed-effects model. 33 | } 34 | \details{ 35 | The parametric bootstrap simulates bootstrap samples from the estimated 36 | distribution functions. That is, error terms and random effects are simulated 37 | from their estimated normal distributions and are combined into bootstrap 38 | samples via the fitted model equation. 39 | } 40 | \references{ 41 | Chambers, R. and Chandra, H. (2013) A random effect block bootstrap for 42 | clustered data. \emph{Journal of Computational and Graphical Statistics}, 43 | \bold{22}, 452--470. 44 | 45 | Van der Leeden, R., Meijer, E. and Busing F. M. (2008) Resampling multilevel 46 | models. In J. de Leeuw and E. Meijer, editors, \emph{Handbook of 47 | Multilevel Analysis}, pages 401--433. New York: Springer. 48 | } 49 | \seealso{ 50 | \itemize{ 51 | \item Examples are given in \code{\link{bootstrap}} 52 | \item \code{\link{parametric_bootstrap}}, \code{\link{resid_bootstrap}}, 53 | \code{\link{case_bootstrap}}, \code{\link{reb_bootstrap}}, 54 | \code{\link{wild_bootstrap}} for more details on a specific bootstrap. 55 | \item \code{\link[lme4]{bootMer}} in the \pkg{lme4} package for an 56 | implementation of (semi-)parametric bootstrap for mixed models. 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \arguments{ 10 | \item{lhs}{A value or the magrittr placeholder.} 11 | 12 | \item{rhs}{A function call using the magrittr semantics.} 13 | } 14 | \value{ 15 | The result of calling `rhs(lhs)`. 16 | } 17 | \description{ 18 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot.R 3 | \name{plot.lmeresamp} 4 | \alias{plot.lmeresamp} 5 | \title{Plot bootstrap results} 6 | \usage{ 7 | \method{plot}{lmeresamp}(x, var, ...) 8 | } 9 | \arguments{ 10 | \item{x}{The lmeresamp object to plot.} 11 | 12 | \item{var}{The estimated parameter to plot, as a string or column number.} 13 | 14 | \item{...}{not used} 15 | } 16 | \description{ 17 | Generate a density plot with a half-eye plot representing the 68% and 95% 18 | percentile intervals from an \code{lmeresamp} object. 19 | } 20 | -------------------------------------------------------------------------------- /man/print.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/print.R 3 | \name{print.lmeresamp} 4 | \alias{print.lmeresamp} 5 | \title{Print a summary of an \code{lmeresamp} object} 6 | \usage{ 7 | \method{print}{lmeresamp}(x, ci = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{The lmeresamp object to print.} 11 | 12 | \item{ci}{A logical value specifying whether confidence intervals should be printed.} 13 | 14 | \item{...}{not used} 15 | } 16 | \description{ 17 | Print summary statistics and confidence intervals, if desired, for an \code{lmeresamp} object. 18 | } 19 | \details{ 20 | If the bootstrap statistics are stored in a vector (as opposed to a data frame or tibble), 21 | then summary statistics will be calculated and printed. The printed data frame will include 22 | the name of the term (if applicable), the observed value (\code{observed}), the mean of the bootstrap replicated 23 | (\code{rep.mean}), the standard error (\code{se}), and the bootstrap bias estimate (\code{bias}). 24 | In addition, the number of resamples will be printed. If any messages, warnings, or errors were 25 | generated during the bootstrap procedure, they will be summarized below, and you should check the 26 | \code{message}, \code{warning}, and \code{error} elements of the \code{lmeresamp} object to 27 | investigate further. 28 | } 29 | -------------------------------------------------------------------------------- /man/print.coef_tbl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/print.R 3 | \name{print.coef_tbl} 4 | \alias{print.coef_tbl} 5 | \title{Print coefficients from a \code{coef_tbl} object} 6 | \usage{ 7 | \method{print}{coef_tbl}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{the coef_tbl object to print} 11 | 12 | \item{...}{not used} 13 | } 14 | \description{ 15 | Print table of coefficients produced by \code{bootstrap_pvals}. 16 | } 17 | -------------------------------------------------------------------------------- /man/reb_bootstrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bootstrap_lme4.R, R/bootstrap_nlme.R, 3 | % R/generics.R 4 | \name{reb_bootstrap.lmerMod} 5 | \alias{reb_bootstrap.lmerMod} 6 | \alias{reb_bootstrap.lme} 7 | \alias{reb_bootstrap} 8 | \title{REB Bootstrap for Two-Level Nested LMEs} 9 | \usage{ 10 | \method{reb_bootstrap}{lmerMod}(model, .f, B, reb_type, .refit = TRUE) 11 | 12 | \method{reb_bootstrap}{lme}(model, .f, B, reb_type, .refit = TRUE) 13 | 14 | reb_bootstrap(model, .f, B, reb_type, .refit = TRUE) 15 | } 16 | \arguments{ 17 | \item{model}{The model object you wish to bootstrap.} 18 | 19 | \item{.f}{A function returning the statistic(s) of interest.} 20 | 21 | \item{B}{The number of bootstrap resamples.} 22 | 23 | \item{reb_type}{Specification of what random effect block bootstrap version to 24 | implement. Possible values are \code{0}, \code{1} or \code{2}.} 25 | 26 | \item{.refit}{a logical value indicating whether the model should be refit to 27 | the bootstrap resample, or if the simulated bootstrap resample should be 28 | returned. Defaults to \code{TRUE}.} 29 | } 30 | \value{ 31 | The returned value is an object of class "lmeresamp". 32 | } 33 | \description{ 34 | Generate random effect block (REB) bootstrap replicates of a statistic for a 35 | two-level nested linear mixed-effects model. 36 | } 37 | \details{ 38 | The random effects block (REB) bootstrap was outlined by Chambers and Chandra (2013) 39 | and has been developed for two-level nested linear mixed-effects (LME) models. 40 | Consider a two-level LME of the form 41 | \deqn{y = X \beta + Z b + \epsilon} 42 | 43 | The REB bootstrap algorithm (\code{type = 0}) is as follows: 44 | \enumerate{ 45 | \item Calculate the nonparametric residual quantities for the fitted model 46 | \itemize{ 47 | \item marginal residuals \eqn{r = y - X\beta} 48 | \item predicted random effects \eqn{\tilde{b} = (Z^\prime Z)^{-1} Z^\prime r} 49 | \item error terms \eqn{\tilde{e} = r - Z \tilde{b}} 50 | } 51 | \item Take a simple random sample, with replacement, of the predicted random effects, \eqn{\tilde{b}}. 52 | \item Draw a simple random sample, with replacement, of the group (cluster) IDs. 53 | For each sampled cluster, draw a random sample, with replacement, of size 54 | \eqn{n_i} from that cluster's vector of error terms, \eqn{\tilde{e}}. 55 | \item Generate bootstrap samples via the fitted model equation 56 | \eqn{y = X \widehat{\beta} + Z \tilde{b} + \tilde{e}} 57 | \item Refit the model and extract the statistic(s) of interest. 58 | \item Repeat steps 2-5 B times. 59 | } 60 | 61 | Variation 1 (\code{type = 1}): 62 | The first variation of the REB bootstrap zero centers and rescales the 63 | residual quantities prior to resampling. 64 | 65 | Variation 2 (\code{type = 2}): 66 | The second variation of the REB bootstrap scales the estimates and centers 67 | the bootstrap distributions (i.e., adjusts for bias) after REB bootstrapping. 68 | } 69 | \references{ 70 | Chambers, R. and Chandra, H. (2013) A random effect block bootstrap for 71 | clustered data. \emph{Journal of Computational and Graphical Statistics}, 72 | \bold{22}, 452--470. 73 | } 74 | \seealso{ 75 | \itemize{ 76 | \item Examples are given in \code{\link{bootstrap}} 77 | \item \code{\link{parametric_bootstrap}}, \code{\link{resid_bootstrap}}, 78 | \code{\link{case_bootstrap}}, \code{\link{reb_bootstrap}}, 79 | \code{\link{wild_bootstrap}} for more details on a specific bootstrap. 80 | \item \code{\link[lme4]{bootMer}} in the \pkg{lme4} package for an 81 | implementation of (semi-)parametric bootstrap for mixed models. 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /man/resid_bootstrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bootstrap_lme4.R, R/bootstrap_nlme.R, 3 | % R/generics.R 4 | \name{resid_bootstrap.merMod} 5 | \alias{resid_bootstrap.merMod} 6 | \alias{resid_bootstrap.lme} 7 | \alias{resid_bootstrap} 8 | \title{Residual Bootstrap for Nested LMEs} 9 | \usage{ 10 | \method{resid_bootstrap}{merMod}(model, .f, B, .refit = TRUE, rbootnoise = 0) 11 | 12 | \method{resid_bootstrap}{lme}(model, .f, B, .refit = TRUE, rbootnoise) 13 | 14 | resid_bootstrap(model, .f, B, .refit = TRUE, rbootnoise = 0) 15 | } 16 | \arguments{ 17 | \item{model}{The model object you wish to bootstrap.} 18 | 19 | \item{.f}{A function returning the statistic(s) of interest.} 20 | 21 | \item{B}{The number of bootstrap resamples.} 22 | 23 | \item{.refit}{a logical value indicating whether the model should be refit to 24 | the bootstrap resample, or if the simulated bootstrap resample should be 25 | returned. Defaults to \code{TRUE}.} 26 | 27 | \item{rbootnoise}{a numeric value between 0-1 indicating the strength of 28 | technical 2-level noise added in relation to the 1-level variation (in 29 | standard deviations) during residual bootstrapping. Minuscule noise, such 30 | as \code{rbootnoise = 0.0001}, can be used to avoid errors with singular 31 | matrices when exactly the same values are replicated during the 32 | bootstrapping, or when the model being processed fails to return any 33 | 2-level variation. Currently applicable only with \code{lme4::lmer} 34 | models. The feature has been tested with 2-level random-intercept models 35 | with predictors. Defaults to \code{0} (i.e. the feature is not used by 36 | default).} 37 | } 38 | \value{ 39 | The returned value is an object of class "lmeresamp". 40 | } 41 | \description{ 42 | Generate semi-parametric residual bootstrap replicates of a statistic for a nested 43 | linear mixed-effects model. 44 | } 45 | \details{ 46 | The semi-parametric bootstrap algorithm implemented was outlined by Carpenter, 47 | Goldstein and Rasbash (2003), and is referred to as the CGR bootstrap by some. 48 | The algorithm is outlined below: 49 | \enumerate{ 50 | \item Obtain the parameter estimates from the fitted model and calculate 51 | the estimated error terms and EBLUPs. 52 | \item Center and rescale the error terms and EBLUPs so that the empirical variance of 53 | these quantities is equal to estimated variance components from the model. 54 | \item Sample independently with replacement from the rescaled estimated error 55 | terms and rescaled EBLUPs. 56 | \item Obtain bootstrap samples by combining the samples via the fitted model equation. 57 | \item Refit the model and extract the statistic(s) of interest. 58 | \item Repeat steps 3-5 B times. 59 | } 60 | } 61 | \references{ 62 | Carpenter, J. R., Goldstein, H. and Rasbash, J. (2003) A novel bootstrap 63 | procedure for assessing the relationship between class size and achievement. 64 | \emph{Journal of the Royal Statistical Society. Series C (Applied Statistics)}, 65 | \bold{52}, 431--443. 66 | } 67 | \seealso{ 68 | \itemize{ 69 | \item Examples are given in \code{\link{bootstrap}} 70 | \item \code{\link{parametric_bootstrap}}, \code{\link{resid_bootstrap}}, 71 | \code{\link{case_bootstrap}}, \code{\link{reb_bootstrap}}, 72 | \code{\link{wild_bootstrap}} for more details on a specific bootstrap. 73 | \item \code{\link[lme4]{bootMer}} in the \pkg{lme4} package for an 74 | implementation of (semi-)parametric bootstrap for mixed models. 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /man/summary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/summary.R 3 | \name{summary.lmeresamp} 4 | \alias{summary.lmeresamp} 5 | \title{Calculate summary statistics for \code{lmeresamp} objects} 6 | \usage{ 7 | \method{summary}{lmeresamp}(object, ...) 8 | } 9 | \arguments{ 10 | \item{object}{The lmeresamp object to be summarized.} 11 | 12 | \item{...}{not used} 13 | } 14 | \description{ 15 | Calculate basic summary statistics such as the mean, standard error, and bias of the 16 | bootstrap replicates. 17 | } 18 | \details{ 19 | If the bootstrap statistics are stored in a vector (as opposed to a data frame or tibble), 20 | then summary statistics will be calculated. The printed data frame will include 21 | the name of the term (if applicable), the observed value (\code{observed}), the mean of the bootstrap replicated 22 | (\code{rep.mean}), the standard error (\code{se}), and the bootstrap bias estimate (\code{bias}). 23 | In addition, the number of resamples will be printed. If any messages, warnings, or errors were 24 | generated during the bootstrap procedure, they will be summarized below, and you should check the 25 | \code{message}, \code{warning}, and \code{error} elements of the \code{lmeresamp} object to 26 | investigate further. 27 | } 28 | -------------------------------------------------------------------------------- /man/wild_bootstrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bootstrap_lme4.R, R/bootstrap_nlme.R, 3 | % R/generics.R 4 | \name{wild_bootstrap.lmerMod} 5 | \alias{wild_bootstrap.lmerMod} 6 | \alias{wild_bootstrap.lme} 7 | \alias{wild_bootstrap} 8 | \title{Wild Bootstrap for LME models} 9 | \usage{ 10 | \method{wild_bootstrap}{lmerMod}( 11 | model, 12 | .f, 13 | B, 14 | hccme = c("hc2", "hc3"), 15 | aux.dist = c("mammen", "rademacher", "norm", "webb", "gamma"), 16 | .refit = TRUE 17 | ) 18 | 19 | \method{wild_bootstrap}{lme}( 20 | model, 21 | .f, 22 | B, 23 | hccme = c("hc2", "hc3"), 24 | aux.dist = c("mammen", "rademacher", "norm", "webb", "gamma"), 25 | .refit = TRUE 26 | ) 27 | 28 | wild_bootstrap(model, .f, B, hccme, aux.dist, .refit = TRUE) 29 | } 30 | \arguments{ 31 | \item{model}{The model object you wish to bootstrap.} 32 | 33 | \item{.f}{A function returning the statistic(s) of interest.} 34 | 35 | \item{B}{The number of bootstrap resamples.} 36 | 37 | \item{hccme}{either \code{"hc2"} or \code{"hc3"}, indicating which 38 | heteroscedasticity consistent covariance matrix estimator to use.} 39 | 40 | \item{aux.dist}{one of \code{"mammen"}, \code{"rademacher"}, \code{"norm"}, 41 | \code{"webb"}, or \code{"gamma"} indicating which auxiliary 42 | distribution to draw the errors from} 43 | 44 | \item{.refit}{a logical value indicating whether the model should be refit to 45 | the bootstrap resample, or if the simulated bootstrap resample should be 46 | returned. Defaults to \code{TRUE}.} 47 | } 48 | \value{ 49 | The returned value is an object of class "lmeresamp". 50 | } 51 | \description{ 52 | Generate wild bootstrap replicates of a statistic for a 53 | linear mixed-effects model. 54 | } 55 | \details{ 56 | The wild bootstrap algorithm for LMEs implemented here was outlined by 57 | Modugno & Giannerini (2015). The algorithm is outlined below: 58 | \enumerate{ 59 | \item Draw a random sample equal to the number of groups (clusters) from 60 | an auxillary distribution with mean zero and unit variance. 61 | Denote these as \eqn{w_1, \ldots, w_g}. 62 | \item Calculate the selected heteroscedasticity consistent matrix estimator for 63 | the marginal residuals, \eqn{\tilde{v}_i} 64 | \item Generate bootstrap responses using the fitted equation: 65 | \eqn{y_i^* = X_i \beta + \tilde{v}_i w_j} 66 | \item Refit the model and extract the statistic(s) of interest. 67 | \item Repeat steps 2-4 B times. 68 | } 69 | } 70 | \references{ 71 | Modugno, L., & Giannerini, S. (2015). The Wild Bootstrap for 72 | Multilevel Models. \emph{Communications in Statistics -- Theory and Methods}, 73 | \bold{44}(22), 4812--4825. 74 | } 75 | \seealso{ 76 | \itemize{ 77 | \item Examples are given in \code{\link{bootstrap}} 78 | \item \code{\link{parametric_bootstrap}}, \code{\link{resid_bootstrap}}, 79 | \code{\link{case_bootstrap}}, \code{\link{reb_bootstrap}}, 80 | \code{\link{wild_bootstrap}} for more details on a specific bootstrap. 81 | \item \code{\link[lme4]{bootMer}} in the \pkg{lme4} package for an 82 | implementation of (semi-)parametric bootstrap for mixed models. 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /revdep/.gitignore: -------------------------------------------------------------------------------- 1 | checks 2 | library 3 | checks.noindex 4 | library.noindex 5 | cloud.noindex 6 | data.sqlite 7 | *.html 8 | -------------------------------------------------------------------------------- /revdep/README.md: -------------------------------------------------------------------------------- 1 | # Platform 2 | 3 | |field |value | 4 | |:--------|:----------------------------------------| 5 | |version |R version 4.2.2 (2022-10-31) | 6 | |os |macOS Monterey 12.5.1 | 7 | |system |x86_64, darwin17.0 | 8 | |ui |RStudio | 9 | |language |(EN) | 10 | |collate |en_US.UTF-8 | 11 | |ctype |en_US.UTF-8 | 12 | |tz |America/Chicago | 13 | |date |2023-01-28 | 14 | |rstudio |2022.12.0+353 Elsbeth Geranium (desktop) | 15 | |pandoc |2.19 @ /usr/local/bin/pandoc | 16 | 17 | # Dependencies 18 | 19 | |package |old |new |Δ | 20 | |:-------------|:-----|:----------|:--| 21 | |lmeresampler |0.2.2 |0.2.3 |* | 22 | |colorspace |NA |2.1-0 |* | 23 | |fansi |NA |1.0.4 |* | 24 | |ggdist |NA |3.2.1 |* | 25 | |lubridate |NA |1.9.1 |* | 26 | |Rcpp |NA |1.0.10 |* | 27 | |RcppArmadillo |NA |0.11.4.3.1 |* | 28 | |statmod |NA |1.5.0 |* | 29 | |tidyr |NA |1.3.0 |* | 30 | |timechange |NA |0.2.0 |* | 31 | |vctrs |NA |0.5.2 |* | 32 | 33 | # Revdeps 34 | 35 | -------------------------------------------------------------------------------- /revdep/checks.noindex/libraries.csv: -------------------------------------------------------------------------------- 1 | package,old,new,delta 2 | lmeresampler,0.2.2,0.2.3,* 3 | colorspace,NA,2.1-0,* 4 | fansi,NA,1.0.4,* 5 | ggdist,NA,3.2.1,* 6 | lubridate,NA,1.9.1,* 7 | Rcpp,NA,1.0.10,* 8 | RcppArmadillo,NA,0.11.4.3.1,* 9 | statmod,NA,1.5.0,* 10 | tidyr,NA,1.3.0,* 11 | timechange,NA,0.2.0,* 12 | vctrs,NA,0.5.2,* 13 | -------------------------------------------------------------------------------- /revdep/cran.md: -------------------------------------------------------------------------------- 1 | ## revdepcheck results 2 | 3 | We checked 0 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 4 | 5 | * We saw 0 new problems 6 | * We failed to check 0 packages 7 | 8 | -------------------------------------------------------------------------------- /revdep/data.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/data.sqlite -------------------------------------------------------------------------------- /revdep/email.yml: -------------------------------------------------------------------------------- 1 | release_date: ??? 2 | rel_release_date: ??? 3 | my_news_url: ??? 4 | release_version: ??? 5 | release_details: ??? 6 | -------------------------------------------------------------------------------- /revdep/failures.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: lmeresampler 2 | Title: Bootstrap Methods for Nested Linear Mixed-Effects Models 3 | Version: 0.2.3 4 | Authors@R: c(person("Adam", "Loy", email = "loyad01@gmail.com", 5 | role = c("aut", "cre"), comment = c(ORCID = "0000-0002-5780-4611")), 6 | person("Spenser", "Steele", role = "aut"), 7 | person("Jenna", "Korobova", role = "aut")) 8 | Description: Bootstrap routines for nested linear mixed effects models fit using 9 | either 'lme4' or 'nlme'. The provided 'bootstrap()' function implements the 10 | parametric, residual, cases, random effect block (REB), and wild bootstrap 11 | procedures. An overview of these procedures can be found 12 | in Van der Leeden et al. (2008) , 13 | Carpenter, Goldstein & Rasbash (2003) , 14 | and Chambers & Chandra (2013) . 15 | Depends: R (>= 3.5.0) 16 | Imports: dplyr (>= 0.8.0), Matrix, nlmeU, ggplot2, ggdist, HLMdiag, 17 | purrr, forcats, stats, statmod, tidyr, magrittr, tibble 18 | Suggests: lme4 (>= 1.1-7), nlme, testthat, mlmRev, knitr, rmarkdown, 19 | doParallel, foreach 20 | License: GPL-3 21 | LazyData: true 22 | URL: https://github.com/aloy/lmeresampler 23 | BugReports: https://github.com/aloy/lmeresampler/issues 24 | RoxygenNote: 7.2.1 25 | VignetteBuilder: knitr 26 | Encoding: UTF-8 27 | RemoteType: local 28 | RemoteUrl: /Users/aloy/Documents/r_packages/lmeresampler 29 | NeedsCompilation: no 30 | Packaged: 2023-01-28 17:02:05 UTC; aloy 31 | Author: Adam Loy [aut, cre] (), 32 | Spenser Steele [aut], 33 | Jenna Korobova [aut] 34 | Maintainer: Adam Loy 35 | Built: R 4.2.2; ; 2023-01-28 17:02:05 UTC; unix 36 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/INDEX: -------------------------------------------------------------------------------- 1 | bootstrap.merMod Bootstrap Nested Linear Mixed-Effects Models 2 | bootstrap_pvals Calculate Bootstrap p-values for fixed effects 3 | case_bootstrap.merMod Cases Bootstrap for Nested LMEs 4 | combine_lmeresamp Combine bootstrap results 5 | combine_pvals Combine p-values 6 | confint.lmeresamp Calculate confidence intervals for a lmeresamp 7 | object 8 | extract_parameters Extract parameters from LME models 9 | jsp728 Junior school project math score data. 10 | lmeresampler lmeresampler: A package for bootstrapping 11 | nested linear mixed-effects models 12 | parametric_bootstrap.merMod 13 | Parametric Bootstrap for Nested LMEs 14 | plot.lmeresamp Plot bootstrap results 15 | print.coef_tbl Print coefficients from a 'coef_tbl' object 16 | print.lmeresamp Print a summary of an 'lmeresamp' object 17 | reb_bootstrap.lmerMod REB Bootstrap for Two-Level Nested LMEs 18 | resid_bootstrap.merMod 19 | Residual Bootstrap for Nested LMEs 20 | summary.lmeresamp Calculate summary statistics for 'lmeresamp' 21 | objects 22 | wild_bootstrap.lmerMod 23 | Wild Bootstrap for LME models 24 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(bootstrap,lme) 4 | S3method(bootstrap,merMod) 5 | S3method(bootstrap_pvals,lme) 6 | S3method(bootstrap_pvals,merMod) 7 | S3method(case_bootstrap,lme) 8 | S3method(case_bootstrap,merMod) 9 | S3method(confint,lmeresamp) 10 | S3method(extract_parameters,lme) 11 | S3method(extract_parameters,merMod) 12 | S3method(parametric_bootstrap,lme) 13 | S3method(parametric_bootstrap,merMod) 14 | S3method(plot,lmeresamp) 15 | S3method(print,coef_tbl) 16 | S3method(print,lmeresamp) 17 | S3method(reb_bootstrap,lme) 18 | S3method(reb_bootstrap,lmerMod) 19 | S3method(resid_bootstrap,lme) 20 | S3method(resid_bootstrap,merMod) 21 | S3method(summary,lmeresamp) 22 | S3method(wild_bootstrap,lme) 23 | S3method(wild_bootstrap,lmerMod) 24 | export("%>%") 25 | export(bootstrap) 26 | export(bootstrap_pvals) 27 | export(case_bootstrap) 28 | export(combine_lmeresamp) 29 | export(combine_pvals) 30 | export(extract_parameters) 31 | export(parametric_bootstrap) 32 | export(reb_bootstrap) 33 | export(resid_bootstrap) 34 | export(wild_bootstrap) 35 | import(Matrix) 36 | importFrom(HLMdiag,extract_design) 37 | importFrom(forcats,fct_inorder) 38 | importFrom(ggdist,stat_halfeye) 39 | importFrom(ggplot2,aes) 40 | importFrom(ggplot2,ggplot) 41 | importFrom(ggplot2,labs) 42 | importFrom(magrittr,"%>%") 43 | importFrom(nlmeU,simulateY) 44 | importFrom(purrr,map) 45 | importFrom(purrr,map_dbl) 46 | importFrom(purrr,map_dfr) 47 | importFrom(statmod,rinvgauss) 48 | importFrom(stats,as.formula) 49 | importFrom(stats,confint) 50 | importFrom(stats,cov) 51 | importFrom(stats,family) 52 | importFrom(stats,fitted) 53 | importFrom(stats,formula) 54 | importFrom(stats,getCall) 55 | importFrom(stats,model.frame) 56 | importFrom(stats,model.matrix) 57 | importFrom(stats,model.response) 58 | importFrom(stats,na.exclude) 59 | importFrom(stats,na.omit) 60 | importFrom(stats,napredict) 61 | importFrom(stats,predict) 62 | importFrom(stats,qnorm) 63 | importFrom(stats,quantile) 64 | importFrom(stats,rbinom) 65 | importFrom(stats,resid) 66 | importFrom(stats,rgamma) 67 | importFrom(stats,rnbinom) 68 | importFrom(stats,rnorm) 69 | importFrom(stats,rpois) 70 | importFrom(stats,sd) 71 | importFrom(stats,sigma) 72 | importFrom(stats,simulate) 73 | importFrom(stats,terms) 74 | importFrom(stats,weights) 75 | importFrom(tibble,as_tibble) 76 | importFrom(tidyr,pivot_longer) 77 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/NEWS: -------------------------------------------------------------------------------- 1 | 0.2.3 2 | =========== 3 | 4 | BUG FIXES 5 | * `rbootnoise` argument added to residual bootstrap to bypass "system is exactly singular" issues with lme4 models (Credit to Ilmari Tamminen) 6 | * Eliminated unnecessary warnings for unnamed vectors with type = "reb2". 7 | 8 | 0.2.2 9 | =========== 10 | 11 | NEW FEATURES 12 | * Additional auxilliary distributions were added for the Wild bootstrap. There are now 6 options, including the standard normal. 13 | * `.refit` argument can be set to FALSE in order to return the only bootstrap responses. 14 | * `bootstrap_pvals()` appends bootstrap p-values to the summary table for the fixed effects 15 | * `combine_pvals()` provides a way to combine the results of `bootstrap_pvals()` for parallel runs. 16 | 17 | 18 | BUG FIXES 19 | * `plot.lmeresamp()` now works if the replicates are a numeric vector rather than a data frame or tibble. 20 | * bug fixed when `na.action = na.omit` 21 | * fixed issue with transformed variables in `glmer` 22 | 23 | 0.2.1 24 | =========== 25 | 26 | * Unarchiving from CRAN 27 | 28 | DEPENDENCY CHANGE 29 | * Remove `catchr` dependency to avoid issues on CRAN 30 | 31 | BUG FIXES 32 | * message/error/warning summarization in `summary.lmeresamp` has been fixed 33 | * If `var` is omitted from `plot.lmeresamp()` a halfeye plot with all terms is created. 34 | 35 | 0.2.0 36 | ===== 37 | 38 | * The case, parametric, and residual bootstraps now suppport `glmerMod` objects. 39 | * The Wild bootstrap is available for `lme` and `lmerMod` objects. 40 | * The CGR bootstrap is now the default "residual" bootstrap algorithm. 41 | * Objects returned by the `bootstrap()` call are now of class `lmeresamp`. 42 | * `lmeresamp` objects have a new structure, including a new `stats` dataframe (contains the observed value, bootstrap mean, standard error, and bias of each LME model parameter). 43 | * New generic `print()` function that is compatible with `lmeresamp` objects 44 | * New generic `confint()` function that is compatible with `lmeresamp` objects (the possible confidence intervals include: basic, normal, percentile, or all) 45 | * A package vignette is now available 46 | * Vignette outlines how to perform parallelization in `bootstrap()` using the `doParallel` and `foreach` packages 47 | * New `combine()` function that combines processes split for parallelization for unified output 48 | 49 | 0.1.1 50 | ===== 51 | 52 | * Unarchiving from CRAN - back to active development 53 | * Updating for use with the new version of dplyr (>= 0.8.0) 54 | * Bug fixed for `case_bootstrap.lme ` so that `.cases.resamp` can be found 55 | 56 | Version 0.1.0 57 | ============= 58 | 59 | Initial release, enjoy! 60 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/R/lmeresampler: -------------------------------------------------------------------------------- 1 | # File share/R/nspackloader.R 2 | # Part of the R package, https://www.R-project.org 3 | # 4 | # Copyright (C) 1995-2012 The R Core Team 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # A copy of the GNU General Public License is available at 17 | # https://www.r-project.org/Licenses/ 18 | 19 | local({ 20 | info <- loadingNamespaceInfo() 21 | pkg <- info$pkgname 22 | ns <- .getNamespace(as.name(pkg)) 23 | if (is.null(ns)) 24 | stop("cannot find namespace environment for ", pkg, domain = NA); 25 | dbbase <- file.path(info$libname, pkg, "R", pkg) 26 | lazyLoad(dbbase, ns, filter = function(n) n != ".__NAMESPACE__.") 27 | }) 28 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/R/lmeresampler.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/R/lmeresampler.rdb -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/R/lmeresampler.rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/R/lmeresampler.rdx -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/data/Rdata.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/data/Rdata.rdb -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/data/Rdata.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/data/Rdata.rds -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/data/Rdata.rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/data/Rdata.rdx -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/help/AnIndex: -------------------------------------------------------------------------------- 1 | %>% pipe 2 | bootstrap bootstrap 3 | bootstrap.lme bootstrap 4 | bootstrap.merMod bootstrap 5 | bootstrap_pvals bootstrap_pvals 6 | bootstrap_pvals.lme bootstrap_pvals 7 | bootstrap_pvals.merMod bootstrap_pvals 8 | case_bootstrap case_bootstrap 9 | case_bootstrap.lme case_bootstrap 10 | case_bootstrap.merMod case_bootstrap 11 | combine_lmeresamp combine 12 | combine_pvals combine_pvals 13 | confint.lmeresamp confint 14 | extract_parameters extract_parameters 15 | jsp728 jsp728 16 | lmeresampler lmeresampler 17 | package-lmeresampler lmeresampler 18 | parametric_bootstrap parametric_bootstrap 19 | parametric_bootstrap.lme parametric_bootstrap 20 | parametric_bootstrap.merMod parametric_bootstrap 21 | plot.lmeresamp plot 22 | print.coef_tbl print.coef_tbl 23 | print.lmeresamp print 24 | reb_bootstrap reb_bootstrap 25 | reb_bootstrap.lme reb_bootstrap 26 | reb_bootstrap.lmerMod reb_bootstrap 27 | resid_bootstrap resid_bootstrap 28 | resid_bootstrap.lme resid_bootstrap 29 | resid_bootstrap.merMod resid_bootstrap 30 | summary.lmeresamp summary 31 | wild_bootstrap wild_bootstrap 32 | wild_bootstrap.lme wild_bootstrap 33 | wild_bootstrap.lmerMod wild_bootstrap 34 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/help/aliases.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/help/aliases.rds -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/help/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/help/figures/logo.png -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/help/lmeresampler.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/help/lmeresampler.rdb -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/help/lmeresampler.rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/help/lmeresampler.rdx -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/help/paths.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/help/paths.rds -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/html/00Index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | R: Bootstrap Methods for Nested Linear Mixed-Effects Models 4 | 5 | 6 | 7 |
    8 |

    Bootstrap Methods for Nested Linear Mixed-Effects Models 9 | 10 |

    11 |
    12 |
    13 | [Up] 14 | [Top] 15 |

    Documentation for package ‘lmeresampler’ version 0.2.3

    16 | 17 | 20 | 21 |

    Help Pages

    22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 |
    bootstrapBootstrap Nested Linear Mixed-Effects Models
    bootstrap.lmeBootstrap Nested Linear Mixed-Effects Models
    bootstrap.merModBootstrap Nested Linear Mixed-Effects Models
    bootstrap_pvalsCalculate Bootstrap p-values for fixed effects
    bootstrap_pvals.lmeCalculate Bootstrap p-values for fixed effects
    bootstrap_pvals.merModCalculate Bootstrap p-values for fixed effects
    case_bootstrapCases Bootstrap for Nested LMEs
    case_bootstrap.lmeCases Bootstrap for Nested LMEs
    case_bootstrap.merModCases Bootstrap for Nested LMEs
    combine_lmeresampCombine bootstrap results
    combine_pvalsCombine p-values
    confint.lmeresampCalculate confidence intervals for a lmeresamp object
    extract_parametersExtract parameters from LME models
    jsp728Junior school project math score data.
    lmeresamplerlmeresampler: A package for bootstrapping nested linear mixed-effects models
    package-lmeresamplerlmeresampler: A package for bootstrapping nested linear mixed-effects models
    parametric_bootstrapParametric Bootstrap for Nested LMEs
    parametric_bootstrap.lmeParametric Bootstrap for Nested LMEs
    parametric_bootstrap.merModParametric Bootstrap for Nested LMEs
    plot.lmeresampPlot bootstrap results
    print.coef_tblPrint coefficients from a 'coef_tbl' object
    print.lmeresampPrint a summary of an 'lmeresamp' object
    reb_bootstrapREB Bootstrap for Two-Level Nested LMEs
    reb_bootstrap.lmeREB Bootstrap for Two-Level Nested LMEs
    reb_bootstrap.lmerModREB Bootstrap for Two-Level Nested LMEs
    resid_bootstrapResidual Bootstrap for Nested LMEs
    resid_bootstrap.lmeResidual Bootstrap for Nested LMEs
    resid_bootstrap.merModResidual Bootstrap for Nested LMEs
    summary.lmeresampCalculate summary statistics for 'lmeresamp' objects
    wild_bootstrapWild Bootstrap for LME models
    wild_bootstrap.lmeWild Bootstrap for LME models
    wild_bootstrap.lmerModWild Bootstrap for LME models
    90 |
    91 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/html/R.css: -------------------------------------------------------------------------------- 1 | @media screen { 2 | .container { 3 | padding-right: 10px; 4 | padding-left: 10px; 5 | margin-right: auto; 6 | margin-left: auto; 7 | max-width: 900px; 8 | } 9 | } 10 | 11 | .rimage img { /* from knitr - for examples and demos */ 12 | width: 96%; 13 | margin-left: 2%; 14 | } 15 | 16 | .katex { font-size: 1.1em; } 17 | 18 | code { 19 | color: inherit; 20 | background: inherit; 21 | } 22 | 23 | body { 24 | line-height: 1.4; 25 | background: white; 26 | color: black; 27 | } 28 | 29 | a:link { 30 | background: white; 31 | color: blue; 32 | } 33 | 34 | a:visited { 35 | background: white; 36 | color: rgb(50%, 0%, 50%); 37 | } 38 | 39 | h1 { 40 | background: white; 41 | color: rgb(55%, 55%, 55%); 42 | font-family: monospace; 43 | font-size: 1.4em; /* x-large; */ 44 | text-align: center; 45 | } 46 | 47 | h2 { 48 | background: white; 49 | color: rgb(40%, 40%, 40%); 50 | font-family: monospace; 51 | font-size: 1.2em; /* large; */ 52 | text-align: center; 53 | } 54 | 55 | h3 { 56 | background: white; 57 | color: rgb(40%, 40%, 40%); 58 | font-family: monospace; 59 | font-size: 1.2em; /* large; */ 60 | } 61 | 62 | h4 { 63 | background: white; 64 | color: rgb(40%, 40%, 40%); 65 | font-family: monospace; 66 | font-style: italic; 67 | font-size: 1.2em; /* large; */ 68 | } 69 | 70 | h5 { 71 | background: white; 72 | color: rgb(40%, 40%, 40%); 73 | font-family: monospace; 74 | } 75 | 76 | h6 { 77 | background: white; 78 | color: rgb(40%, 40%, 40%); 79 | font-family: monospace; 80 | font-style: italic; 81 | } 82 | 83 | img.toplogo { 84 | width: 4em; 85 | vertical-align: middle; 86 | } 87 | 88 | img.arrow { 89 | width: 30px; 90 | height: 30px; 91 | border: 0; 92 | } 93 | 94 | span.acronym { 95 | font-size: small; 96 | } 97 | 98 | span.env { 99 | font-family: monospace; 100 | } 101 | 102 | span.file { 103 | font-family: monospace; 104 | } 105 | 106 | span.option{ 107 | font-family: monospace; 108 | } 109 | 110 | span.pkg { 111 | font-weight: bold; 112 | } 113 | 114 | span.samp{ 115 | font-family: monospace; 116 | } 117 | 118 | div.vignettes a:hover { 119 | background: rgb(85%, 85%, 85%); 120 | } 121 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/new/lmeresampler/image/FINAL_HEX_nobackground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/new/lmeresampler/image/FINAL_HEX_nobackground.png -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: lmeresampler 2 | Title: Bootstrap Methods for Nested Linear Mixed-Effects Models 3 | Version: 0.2.2 4 | Authors@R: c(person("Adam", "Loy", email = "loyad01@gmail.com", 5 | role = c("aut", "cre"), comment = c(ORCID = "0000-0002-5780-4611")), 6 | person("Spenser", "Steele", role = "aut"), 7 | person("Jenna", "Korobova", role = "aut")) 8 | Description: Bootstrap routines for nested linear mixed effects models fit using 9 | either 'lme4' or 'nlme'. The provided 'bootstrap()' function implements the 10 | parametric, residual, cases, random effect block (REB), and wild bootstrap 11 | procedures. An overview of these procedures can be found 12 | in Van der Leeden et al. (2008) , 13 | Carpenter, Goldstein & Rasbash (2003) , 14 | and Chambers & Chandra (2013) . 15 | Depends: R (>= 3.5.0) 16 | Imports: dplyr (>= 0.8.0), Matrix, nlmeU, ggplot2, ggdist, HLMdiag, 17 | purrr, forcats, stats, statmod, tidyr, magrittr, tibble 18 | Suggests: lme4 (>= 1.1-7), nlme, testthat, mlmRev, knitr, rmarkdown, 19 | doParallel, foreach 20 | License: GPL-3 21 | LazyData: true 22 | URL: https://github.com/aloy/lmeresampler 23 | BugReports: https://github.com/aloy/lmeresampler/issues 24 | RoxygenNote: 7.1.1 25 | VignetteBuilder: knitr 26 | Encoding: UTF-8 27 | NeedsCompilation: no 28 | Packaged: 2022-04-29 14:05:32 UTC; aloy 29 | Author: Adam Loy [aut, cre] (), 30 | Spenser Steele [aut], 31 | Jenna Korobova [aut] 32 | Maintainer: Adam Loy 33 | Repository: CRAN 34 | Date/Publication: 2022-04-29 22:50:11 UTC 35 | Built: R 4.2.0; ; 2022-05-11 04:53:33 UTC; unix 36 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/INDEX: -------------------------------------------------------------------------------- 1 | bootstrap.merMod Bootstrap Nested Linear Mixed-Effects Models 2 | bootstrap_pvals Calculate Bootstrap p-values for fixed effects 3 | Perform bootstrap tests based on the 4 | t-statistic for each fixed effect in order to 5 | calculate approximate p-values. 6 | case_bootstrap.merMod Cases Bootstrap for Nested LMEs 7 | combine_lmeresamp Combine bootstrap results 8 | combine_pvals Combine p-values 9 | confint.lmeresamp Calculate confidence intervals for a lmeresamp 10 | object 11 | extract_parameters Extract parameters from LME models 12 | jsp728 Junior school project math score data. 13 | lmeresampler lmeresampler: A package for bootstrapping 14 | nested linear mixed-effects models 15 | parametric_bootstrap.merMod 16 | Parametric Bootstrap for Nested LMEs 17 | plot.lmeresamp Plot bootstrap results 18 | print.coef_tbl Print coefficients from a 'coef_tbl' object 19 | print.lmeresamp Print a summary of an 'lmeresamp' object 20 | reb_bootstrap.lmerMod REB Bootstrap for Two-Level Nested LMEs 21 | resid_bootstrap.merMod 22 | Residual Bootstrap for Nested LMEs 23 | summary.lmeresamp Calculate summary statistics for 'lmeresamp' 24 | objects 25 | wild_bootstrap.lmerMod 26 | Wild Bootstrap for LME models 27 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(bootstrap,lme) 4 | S3method(bootstrap,merMod) 5 | S3method(bootstrap_pvals,lme) 6 | S3method(bootstrap_pvals,merMod) 7 | S3method(case_bootstrap,lme) 8 | S3method(case_bootstrap,merMod) 9 | S3method(confint,lmeresamp) 10 | S3method(extract_parameters,lme) 11 | S3method(extract_parameters,merMod) 12 | S3method(parametric_bootstrap,lme) 13 | S3method(parametric_bootstrap,merMod) 14 | S3method(plot,lmeresamp) 15 | S3method(print,lmeresamp) 16 | S3method(reb_bootstrap,lme) 17 | S3method(reb_bootstrap,lmerMod) 18 | S3method(resid_bootstrap,lme) 19 | S3method(resid_bootstrap,merMod) 20 | S3method(summary,lmeresamp) 21 | S3method(wild_bootstrap,lme) 22 | S3method(wild_bootstrap,lmerMod) 23 | export("%>%") 24 | export(bootstrap) 25 | export(bootstrap_pvals) 26 | export(case_bootstrap) 27 | export(combine_lmeresamp) 28 | export(combine_pvals) 29 | export(extract_parameters) 30 | export(parametric_bootstrap) 31 | export(reb_bootstrap) 32 | export(resid_bootstrap) 33 | export(wild_bootstrap) 34 | import(Matrix) 35 | importFrom(HLMdiag,extract_design) 36 | importFrom(forcats,fct_inorder) 37 | importFrom(ggdist,stat_halfeye) 38 | importFrom(ggplot2,aes) 39 | importFrom(ggplot2,ggplot) 40 | importFrom(ggplot2,labs) 41 | importFrom(magrittr,"%>%") 42 | importFrom(nlmeU,simulateY) 43 | importFrom(purrr,map) 44 | importFrom(purrr,map_dbl) 45 | importFrom(purrr,map_dfr) 46 | importFrom(statmod,rinvgauss) 47 | importFrom(stats,as.formula) 48 | importFrom(stats,confint) 49 | importFrom(stats,cov) 50 | importFrom(stats,family) 51 | importFrom(stats,fitted) 52 | importFrom(stats,formula) 53 | importFrom(stats,getCall) 54 | importFrom(stats,model.frame) 55 | importFrom(stats,model.matrix) 56 | importFrom(stats,model.response) 57 | importFrom(stats,na.exclude) 58 | importFrom(stats,na.omit) 59 | importFrom(stats,napredict) 60 | importFrom(stats,predict) 61 | importFrom(stats,qnorm) 62 | importFrom(stats,quantile) 63 | importFrom(stats,rbinom) 64 | importFrom(stats,resid) 65 | importFrom(stats,rgamma) 66 | importFrom(stats,rnbinom) 67 | importFrom(stats,rnorm) 68 | importFrom(stats,rpois) 69 | importFrom(stats,sd) 70 | importFrom(stats,sigma) 71 | importFrom(stats,simulate) 72 | importFrom(stats,terms) 73 | importFrom(stats,weights) 74 | importFrom(tibble,as_tibble) 75 | importFrom(tidyr,pivot_longer) 76 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/NEWS: -------------------------------------------------------------------------------- 1 | 0.2.1.99999 2 | =========== 3 | 4 | NEW FEATURES 5 | * Additional auxilliary distributions were added for the Wild bootstrap. 6 | There are now 6 options, including the standard normal. 7 | * `.refit` argument can be set to FALSE in order to return the only bootstrap 8 | responses. 9 | * `bootstrap_pvals()` appends bootstrap p-values to the summary table for 10 | the fixed effects 11 | * `combine_pvals()` provides a way to combine the results of `bootstrap_pvals()` 12 | for parallel runds. 13 | 14 | 15 | BUG FIXES 16 | * `plot.lmeresamp()` now works if the replicates are a numeric vector rather 17 | than a data frame or tibble. 18 | * bug fixed when `na.action = na.omit` 19 | * fixed issue with transformed variables in `glmer` 20 | 21 | 0.2.1 22 | =========== 23 | 24 | * Unarchiving from CRAN 25 | 26 | DEPENDENCY CHANGE 27 | * Remove `catchr` dependency to avoid issues on CRAN 28 | 29 | BUG FIXES 30 | * message/error/warning summarization in `summary.lmeresamp` has been fixed 31 | * If `var` is omitted from `plot.lmeresamp()` a halfeye plot with all terms is created. 32 | 33 | 0.2.0 34 | ===== 35 | 36 | * The case, parametric, and residual bootstraps now suppport `glmerMod` objects. 37 | * The Wild bootstrap is available for `lme` and `lmerMod` objects. 38 | * The CGR bootstrap is now the default "residual" bootstrap algorithm. 39 | * Objects returned by the `bootstrap()` call are now of class `lmeresamp`. 40 | * `lmeresamp` objects have a new structure, including a new `stats` dataframe (contains the observed value, bootstrap mean, standard error, and bias of each LME model parameter). 41 | * New generic `print()` function that is compatible with `lmeresamp` objects 42 | * New generic `confint()` function that is compatible with `lmeresamp` objects (the possible confidence intervals include: basic, normal, percentile, or all) 43 | * A package vignette is now available 44 | * Vignette outlines how to perform parallelization in `bootstrap()` using the `doParallel` and `foreach` packages 45 | * New `combine()` function that combines processes split for parallelization for unified output 46 | 47 | 0.1.1 48 | ===== 49 | 50 | * Unarchiving from CRAN - back to active development 51 | * Updating for use with the new version of dplyr (>= 0.8.0) 52 | * Bug fixed for `case_bootstrap.lme ` so that `.cases.resamp` can be found 53 | 54 | Version 0.1.0 55 | ============= 56 | 57 | Initial release, enjoy! 58 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/R/lmeresampler: -------------------------------------------------------------------------------- 1 | # File share/R/nspackloader.R 2 | # Part of the R package, https://www.R-project.org 3 | # 4 | # Copyright (C) 1995-2012 The R Core Team 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # A copy of the GNU General Public License is available at 17 | # https://www.r-project.org/Licenses/ 18 | 19 | local({ 20 | info <- loadingNamespaceInfo() 21 | pkg <- info$pkgname 22 | ns <- .getNamespace(as.name(pkg)) 23 | if (is.null(ns)) 24 | stop("cannot find namespace environment for ", pkg, domain = NA); 25 | dbbase <- file.path(info$libname, pkg, "R", pkg) 26 | lazyLoad(dbbase, ns, filter = function(n) n != ".__NAMESPACE__.") 27 | }) 28 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/R/lmeresampler.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/old/lmeresampler/R/lmeresampler.rdb -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/R/lmeresampler.rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/old/lmeresampler/R/lmeresampler.rdx -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/data/Rdata.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/old/lmeresampler/data/Rdata.rdb -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/data/Rdata.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/old/lmeresampler/data/Rdata.rds -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/data/Rdata.rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/old/lmeresampler/data/Rdata.rdx -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/help/AnIndex: -------------------------------------------------------------------------------- 1 | %>% pipe 2 | bootstrap bootstrap 3 | bootstrap.lme bootstrap 4 | bootstrap.merMod bootstrap 5 | bootstrap_pvals bootstrap_pvals 6 | bootstrap_pvals.lme bootstrap_pvals 7 | bootstrap_pvals.merMod bootstrap_pvals 8 | case_bootstrap case_bootstrap 9 | case_bootstrap.lme case_bootstrap 10 | case_bootstrap.merMod case_bootstrap 11 | combine_lmeresamp combine 12 | combine_pvals combine_pvals 13 | confint.lmeresamp confint 14 | extract_parameters extract_parameters 15 | jsp728 jsp728 16 | lmeresampler lmeresampler 17 | package-lmeresampler lmeresampler 18 | parametric_bootstrap parametric_bootstrap 19 | parametric_bootstrap.lme parametric_bootstrap 20 | parametric_bootstrap.merMod parametric_bootstrap 21 | plot.lmeresamp plot 22 | print.coef_tbl print.coef_tbl 23 | print.lmeresamp print 24 | reb_bootstrap reb_bootstrap 25 | reb_bootstrap.lme reb_bootstrap 26 | reb_bootstrap.lmerMod reb_bootstrap 27 | resid_bootstrap resid_bootstrap 28 | resid_bootstrap.lme resid_bootstrap 29 | resid_bootstrap.merMod resid_bootstrap 30 | summary.lmeresamp summary 31 | wild_bootstrap wild_bootstrap 32 | wild_bootstrap.lme wild_bootstrap 33 | wild_bootstrap.lmerMod wild_bootstrap 34 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/help/aliases.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/old/lmeresampler/help/aliases.rds -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/help/lmeresampler.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/old/lmeresampler/help/lmeresampler.rdb -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/help/lmeresampler.rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/old/lmeresampler/help/lmeresampler.rdx -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/help/paths.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/revdep/library.noindex/lmeresampler/old/lmeresampler/help/paths.rds -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/html/00Index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | R: Bootstrap Methods for Nested Linear Mixed-Effects Models 4 | 5 | 6 | 7 |
    8 |

    Bootstrap Methods for Nested Linear Mixed-Effects Models 9 | 10 |

    11 |
    12 |
    13 | [Up] 14 | [Top] 15 |

    Documentation for package ‘lmeresampler’ version 0.2.2

    16 | 17 | 21 | 22 |

    Help Pages

    23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 |
    bootstrapBootstrap Nested Linear Mixed-Effects Models
    bootstrap.lmeBootstrap Nested Linear Mixed-Effects Models
    bootstrap.merModBootstrap Nested Linear Mixed-Effects Models
    bootstrap_pvalsCalculate Bootstrap p-values for fixed effects Perform bootstrap tests based on the t-statistic for each fixed effect in order to calculate approximate p-values.
    bootstrap_pvals.lmeCalculate Bootstrap p-values for fixed effects Perform bootstrap tests based on the t-statistic for each fixed effect in order to calculate approximate p-values.
    bootstrap_pvals.merModCalculate Bootstrap p-values for fixed effects Perform bootstrap tests based on the t-statistic for each fixed effect in order to calculate approximate p-values.
    case_bootstrapCases Bootstrap for Nested LMEs
    case_bootstrap.lmeCases Bootstrap for Nested LMEs
    case_bootstrap.merModCases Bootstrap for Nested LMEs
    combine_lmeresampCombine bootstrap results
    combine_pvalsCombine p-values
    confint.lmeresampCalculate confidence intervals for a lmeresamp object
    extract_parametersExtract parameters from LME models
    jsp728Junior school project math score data.
    lmeresamplerlmeresampler: A package for bootstrapping nested linear mixed-effects models
    package-lmeresamplerlmeresampler: A package for bootstrapping nested linear mixed-effects models
    parametric_bootstrapParametric Bootstrap for Nested LMEs
    parametric_bootstrap.lmeParametric Bootstrap for Nested LMEs
    parametric_bootstrap.merModParametric Bootstrap for Nested LMEs
    plot.lmeresampPlot bootstrap results
    print.coef_tblPrint coefficients from a 'coef_tbl' object
    print.lmeresampPrint a summary of an 'lmeresamp' object
    reb_bootstrapREB Bootstrap for Two-Level Nested LMEs
    reb_bootstrap.lmeREB Bootstrap for Two-Level Nested LMEs
    reb_bootstrap.lmerModREB Bootstrap for Two-Level Nested LMEs
    resid_bootstrapResidual Bootstrap for Nested LMEs
    resid_bootstrap.lmeResidual Bootstrap for Nested LMEs
    resid_bootstrap.merModResidual Bootstrap for Nested LMEs
    summary.lmeresampCalculate summary statistics for 'lmeresamp' objects
    wild_bootstrapWild Bootstrap for LME models
    wild_bootstrap.lmeWild Bootstrap for LME models
    wild_bootstrap.lmerModWild Bootstrap for LME models
    91 |
    92 | -------------------------------------------------------------------------------- /revdep/library.noindex/lmeresampler/old/lmeresampler/html/R.css: -------------------------------------------------------------------------------- 1 | @media screen { 2 | .container { 3 | padding-right: 10px; 4 | padding-left: 10px; 5 | margin-right: auto; 6 | margin-left: auto; 7 | max-width: 900px; 8 | } 9 | } 10 | 11 | .rimage img { /* from knitr - for examples and demos */ 12 | width: 96%; 13 | margin-left: 2%; 14 | } 15 | 16 | .katex { font-size: 1.1em; } 17 | 18 | code { 19 | color: inherit; 20 | background: inherit; 21 | } 22 | 23 | body { 24 | line-height: 1.4; 25 | background: white; 26 | color: black; 27 | } 28 | 29 | a:link { 30 | background: white; 31 | color: blue; 32 | } 33 | 34 | a:visited { 35 | background: white; 36 | color: rgb(50%, 0%, 50%); 37 | } 38 | 39 | h1 { 40 | background: white; 41 | color: rgb(55%, 55%, 55%); 42 | font-family: monospace; 43 | font-size: 1.4em; /* x-large; */ 44 | text-align: center; 45 | } 46 | 47 | h2 { 48 | background: white; 49 | color: rgb(40%, 40%, 40%); 50 | font-family: monospace; 51 | font-size: 1.2em; /* large; */ 52 | text-align: center; 53 | } 54 | 55 | h3 { 56 | background: white; 57 | color: rgb(40%, 40%, 40%); 58 | font-family: monospace; 59 | font-size: 1.2em; /* large; */ 60 | } 61 | 62 | h4 { 63 | background: white; 64 | color: rgb(40%, 40%, 40%); 65 | font-family: monospace; 66 | font-style: italic; 67 | font-size: 1.2em; /* large; */ 68 | } 69 | 70 | h5 { 71 | background: white; 72 | color: rgb(40%, 40%, 40%); 73 | font-family: monospace; 74 | } 75 | 76 | h6 { 77 | background: white; 78 | color: rgb(40%, 40%, 40%); 79 | font-family: monospace; 80 | font-style: italic; 81 | } 82 | 83 | img.toplogo { 84 | width: 4em; 85 | vertical-align: middle; 86 | } 87 | 88 | img.arrow { 89 | width: 30px; 90 | height: 30px; 91 | border: 0; 92 | } 93 | 94 | span.acronym { 95 | font-size: small; 96 | } 97 | 98 | span.env { 99 | font-family: monospace; 100 | } 101 | 102 | span.file { 103 | font-family: monospace; 104 | } 105 | 106 | span.option{ 107 | font-family: monospace; 108 | } 109 | 110 | span.pkg { 111 | font-weight: bold; 112 | } 113 | 114 | span.samp{ 115 | font-family: monospace; 116 | } 117 | 118 | div.vignettes a:hover { 119 | background: rgb(85%, 85%, 85%); 120 | } 121 | -------------------------------------------------------------------------------- /revdep/problems.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(lmeresampler) 3 | 4 | 5 | 6 | test_check("lmeresampler") 7 | -------------------------------------------------------------------------------- /tests/testthat/reference_data_for_rbootnoise_test_A071022.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/tests/testthat/reference_data_for_rbootnoise_test_A071022.RData -------------------------------------------------------------------------------- /tests/testthat/reference_data_for_rbootnoise_test_B071022.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/lmeresampler/d5124646d9fd9f1e3cab4746b05927f5e05e0ae2/tests/testthat/reference_data_for_rbootnoise_test_B071022.RData -------------------------------------------------------------------------------- /tests/testthat/test-case-nlme.R: -------------------------------------------------------------------------------- 1 | library(nlme, quietly = TRUE) 2 | 3 | data(Socatt, package = "mlmRev") 4 | Socatt$religion <- relevel(Socatt$religion, ref = "none") 5 | Socatt$rv <- as.numeric(as.character(Socatt$numpos)) 6 | Socatt$rv <- scale(Socatt$rv) # a plot shows this is clearly non-normal 7 | 8 | 9 | 10 | # ============================================================================== 11 | context("case bootstrap (lme)") 12 | # ============================================================================== 13 | 14 | mySumm <- function(.) { 15 | c(beta = fixef(.), sigma = as.numeric(.$sigma), sig01 = as.numeric(VarCorr(.)[1,2])) 16 | } 17 | 18 | nsim <- 10 19 | 20 | test_that("two-level additive random intercept model",{ 21 | skip_on_cran() 22 | ## See p. 31 of Goldstein's book 23 | vcmodA <- lme(mathAge11 ~ mathAge8 + gender + class, 24 | random = ~ 1 | school, data = jsp728) 25 | 26 | orig.stats <- mySumm(vcmodA) 27 | 28 | boo <- case_bootstrap(model = vcmodA, .f = mySumm, B = nsim, resample = c(TRUE, TRUE)) 29 | 30 | expect_equal(class(boo), "lmeresamp") 31 | expect_equal(boo$observed, orig.stats) 32 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 33 | expect_equal(nrow(boo$replicates), nsim) 34 | expect_equal(ncol(boo$replicates), length(orig.stats)) 35 | expect_equal(boo$B, nsim) 36 | expect_equal(boo$type, "case") 37 | expect_equal(boo$.f, mySumm) 38 | 39 | boo <- case_bootstrap(model = vcmodA, .f = mySumm, B = nsim, resample = c(FALSE, TRUE)) 40 | 41 | expect_equal(class(boo), "lmeresamp") 42 | expect_equal(boo$observed, orig.stats) 43 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 44 | expect_equal(nrow(boo$replicates), nsim) 45 | expect_equal(ncol(boo$replicates), length(orig.stats)) 46 | expect_equal(boo$B, nsim) 47 | expect_equal(boo$type, "case") 48 | expect_equal(boo$.f, mySumm) 49 | 50 | boo <- case_bootstrap(model = vcmodA, .f = mySumm, B = nsim, resample = c(TRUE, FALSE)) 51 | 52 | expect_equal(class(boo), "lmeresamp") 53 | expect_equal(boo$observed, orig.stats) 54 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 55 | expect_equal(nrow(boo$replicates), nsim) 56 | expect_equal(ncol(boo$replicates), length(orig.stats)) 57 | expect_equal(boo$B, nsim) 58 | expect_equal(boo$type, "case") 59 | expect_equal(boo$.f, mySumm) 60 | }) 61 | 62 | 63 | # ------------------------------------------------------------------------------ 64 | 65 | test_that("two-level random intercept model with interaction",{ 66 | skip_on_cran() 67 | ## See p. 34 of Goldstein's book 68 | vcmodC <- lme(mathAge11 ~ mathAge8 * schoolMathAge8 + gender + class, 69 | random = ~ 1 | school, data = jsp728) 70 | 71 | orig.stats <- mySumm(vcmodC) 72 | boo <- case_bootstrap(model = vcmodC, .f = mySumm, B = nsim, resample = c(TRUE, TRUE)) 73 | 74 | expect_equal(class(boo), "lmeresamp") 75 | expect_equal(boo$observed, orig.stats) 76 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 77 | expect_equal(nrow(boo$replicates), nsim) 78 | expect_equal(ncol(boo$replicates), length(orig.stats)) 79 | expect_equal(boo$B, nsim) 80 | expect_equal(boo$type, "case") 81 | expect_equal(boo$.f, mySumm) 82 | 83 | boo <- case_bootstrap(model = vcmodC, .f = mySumm, B = nsim, resample = c(FALSE, TRUE)) 84 | 85 | expect_equal(class(boo), "lmeresamp") 86 | expect_equal(boo$observed, orig.stats) 87 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 88 | expect_equal(nrow(boo$replicates), nsim) 89 | expect_equal(ncol(boo$replicates), length(orig.stats)) 90 | expect_equal(boo$B, nsim) 91 | expect_equal(boo$type, "case") 92 | expect_equal(boo$.f, mySumm) 93 | }) 94 | 95 | 96 | # ------------------------------------------------------------------------------ 97 | 98 | test_that("two-level random coefficient model with interaction",{ 99 | skip_on_cran() 100 | ## See p. 35 of Goldstein's book 101 | rcmod <- lme(mathAge11 ~ mathAge8c * schoolMathAge8 + gender + class, 102 | random = ~ mathAge8c | school, data = jsp728) 103 | 104 | orig.stats <- mySumm(rcmod) 105 | boo <- case_bootstrap(model = rcmod, .f = mySumm, B = nsim, resample = c(TRUE, TRUE)) 106 | 107 | expect_equal(class(boo), "lmeresamp") 108 | expect_equal(boo$observed, orig.stats) 109 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 110 | expect_equal(nrow(boo$replicates), nsim) 111 | expect_equal(ncol(boo$replicates), length(orig.stats)) 112 | expect_equal(boo$B, nsim) 113 | expect_equal(boo$type, "case") 114 | expect_equal(boo$.f, mySumm) 115 | }) 116 | 117 | # ------------------------------------------------------------------------------ 118 | 119 | test_that("three-level random coefficient model with interaction",{ 120 | skip_on_cran() 121 | rmA <- lme(rv ~ religion + year, random = ~ 1 | district/respond, data = Socatt) 122 | 123 | 124 | mySumm <- function(.) { 125 | c(beta = fixef(.), sigma = as.numeric(.$sigma), 126 | sig.dist = as.numeric(VarCorr(.)[2,2]), 127 | sig.int = as.numeric(VarCorr(.)[4,2])) 128 | } 129 | 130 | orig.stats <- mySumm(rmA) 131 | 132 | boo <- case_bootstrap(model = rmA, .f = mySumm, B = nsim, 133 | resample = c(TRUE, TRUE, TRUE)) 134 | 135 | expect_equal(class(boo), "lmeresamp") 136 | expect_equal(boo$observed, orig.stats) 137 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 138 | expect_equal(nrow(boo$replicates), nsim) 139 | expect_equal(ncol(boo$replicates), length(orig.stats)) 140 | expect_equal(boo$B, nsim) 141 | expect_equal(boo$type, "case") 142 | expect_equal(boo$.f, mySumm) 143 | 144 | boo <- case_bootstrap(model = rmA, .f = mySumm, B = nsim, 145 | resample = c(FALSE, FALSE, TRUE)) 146 | 147 | expect_equal(class(boo), "lmeresamp") 148 | expect_equal(boo$observed, orig.stats) 149 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 150 | expect_equal(nrow(boo$replicates), nsim) 151 | expect_equal(ncol(boo$replicates), length(orig.stats)) 152 | expect_equal(boo$B, nsim) 153 | expect_equal(boo$type, "case") 154 | expect_equal(boo$.f, mySumm) 155 | 156 | boo <- case_bootstrap(model = rmA, .f = mySumm, B = nsim, 157 | resample = c(TRUE, TRUE, FALSE)) 158 | 159 | expect_equal(class(boo), "lmeresamp") 160 | expect_equal(boo$observed, orig.stats) 161 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 162 | expect_equal(nrow(boo$replicates), nsim) 163 | expect_equal(ncol(boo$replicates), length(orig.stats)) 164 | expect_equal(boo$B, nsim) 165 | expect_equal(boo$type, "case") 166 | expect_equal(boo$.f, mySumm) 167 | }) -------------------------------------------------------------------------------- /tests/testthat/test-parametric-nlme.R: -------------------------------------------------------------------------------- 1 | library(nlme, quietly = TRUE) 2 | 3 | data(Socatt, package = "mlmRev") 4 | Socatt$religion <- relevel(Socatt$religion, ref = "none") 5 | Socatt$rv <- as.numeric(as.character(Socatt$numpos)) 6 | Socatt$rv <- scale(Socatt$rv) # a plot shows this is clearly non-normal 7 | 8 | 9 | 10 | # ============================================================================== 11 | context("parametric bootstrap (lme)") 12 | # ============================================================================== 13 | 14 | mySumm <- function(.) { 15 | c(beta = fixef(.), sigma = as.numeric(.$sigma), sig01 = as.numeric(VarCorr(.)[1,2])) 16 | } 17 | 18 | nsim <- 10 19 | 20 | test_that("two-level additive random intercept model",{ 21 | skip_on_cran() 22 | ## See p. 31 of Goldstein's book 23 | vcmodA <- lme(mathAge11 ~ mathAge8 + gender + class, 24 | random = ~ 1 | school, data = jsp728) 25 | 26 | orig.stats <- mySumm(vcmodA) 27 | 28 | boo <- parametric_bootstrap(model = vcmodA, .f = mySumm, B = nsim) 29 | 30 | expect_equal(class(boo), "lmeresamp") 31 | expect_equal(boo$observed, orig.stats) 32 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 33 | expect_equal(nrow(boo$replicates), nsim) 34 | expect_equal(ncol(boo$replicates), length(orig.stats)) 35 | expect_equal(boo$B, nsim) 36 | expect_equal(boo$type, "parametric") 37 | expect_equal(boo$.f, mySumm) 38 | }) 39 | 40 | # ------------------------------------------------------------------------------ 41 | 42 | test_that("two-level random intercept model without interaction",{ 43 | skip_on_cran() 44 | ## See p. 97 of Goldstein's book 45 | rimod <- lme(mathAge11 ~ mathAge8c + gender + class, 46 | random = ~ 1 | school, data = jsp728) 47 | 48 | orig.stats <- mySumm(rimod) 49 | boo <- parametric_bootstrap(model = rimod, .f = mySumm, B = nsim) 50 | 51 | expect_equal(class(boo), "lmeresamp") 52 | expect_equal(boo$observed, orig.stats) 53 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 54 | expect_equal(nrow(boo$replicates), nsim) 55 | expect_equal(ncol(boo$replicates), length(orig.stats)) 56 | expect_equal(boo$B, nsim) 57 | expect_equal(boo$type, "parametric") 58 | expect_equal(boo$.f, mySumm) 59 | }) 60 | 61 | 62 | test_that("two-level random intercept model with interaction",{ 63 | skip_on_cran() 64 | ## See p. 34 of Goldstein's book 65 | vcmodC <- lme(mathAge11 ~ mathAge8 * schoolMathAge8 + gender + class, 66 | random = ~ 1 | school, data = jsp728) 67 | 68 | orig.stats <- mySumm(vcmodC) 69 | boo <- parametric_bootstrap(model = vcmodC, .f = mySumm, B = nsim) 70 | 71 | expect_equal(class(boo), "lmeresamp") 72 | expect_equal(boo$observed, orig.stats) 73 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 74 | expect_equal(nrow(boo$replicates), nsim) 75 | expect_equal(ncol(boo$replicates), length(orig.stats)) 76 | expect_equal(boo$B, nsim) 77 | expect_equal(boo$type, "parametric") 78 | expect_equal(boo$.f, mySumm) 79 | }) 80 | 81 | # ------------------------------------------------------------------------------ 82 | 83 | test_that("two-level random coefficient model with interaction",{ 84 | skip_on_cran() 85 | ## See p. 35 of Goldstein's book 86 | rcmod <- lme(mathAge11 ~ mathAge8c * schoolMathAge8 + gender + class, 87 | random = ~ mathAge8c | school, data = jsp728) 88 | 89 | orig.stats <- mySumm(rcmod) 90 | boo <- parametric_bootstrap(model = rcmod, .f = mySumm, B = nsim) 91 | 92 | expect_equal(class(boo), "lmeresamp") 93 | expect_equal(boo$observed, orig.stats) 94 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 95 | expect_equal(nrow(boo$replicates), nsim) 96 | expect_equal(ncol(boo$replicates), length(orig.stats)) 97 | expect_equal(boo$B, nsim) 98 | expect_equal(boo$type, "parametric") 99 | expect_equal(boo$.f, mySumm) 100 | }) 101 | 102 | # ------------------------------------------------------------------------------ 103 | 104 | # test_that("three-level random intercept model",{ 105 | # rmA <- lme(rv ~ religion + year, random = ~ 1 | district/respond, data = Socatt) 106 | # 107 | # 108 | # mySumm <- function(.) { 109 | # c(beta = fixef(.), sigma = as.numeric(.$sigma), sig01 = as.numeric(VarCorr(.)[1,2])) 110 | # } 111 | # 112 | # orig.stats <- mySumm(rmA) 113 | # boo <- parametric_bootstrap(model = rmA, .f = mySumm, B = nsim) 114 | # 115 | # expect_equal(class(boo), "boot") 116 | # expect_equal(boo$t0, orig.stats) 117 | # expect_equal(nrow(boo$t), nsim) 118 | # expect_equal(ncol(boo$t), length(orig.stats)) 119 | # expect_equal(boo$B, nsim) 120 | # expect_equal(boo$sim, "parametric") 121 | # expect_equal(boo$statistic, mySumm) 122 | # }) -------------------------------------------------------------------------------- /tests/testthat/test-resid-lme4.R: -------------------------------------------------------------------------------- 1 | library(lme4) 2 | 3 | data(Socatt, package = "mlmRev") 4 | Socatt$religion <- relevel(Socatt$religion, ref = "none") 5 | Socatt$rv <- as.numeric(as.character(Socatt$numpos)) 6 | Socatt$rv <- scale(Socatt$rv) # a plot shows this is clearly non-normal 7 | 8 | 9 | 10 | 11 | # ============================================================================== 12 | context("residual bootstrap (lmerMod)") 13 | # ============================================================================== 14 | 15 | mySumm <- function(.) { 16 | s <- lme4::getME(., "sigma") 17 | c(beta = lme4::getME(., "beta"), sigma = s, sig01 = unname(s * lme4::getME(., "theta"))) 18 | } 19 | 20 | nsim <- 10 21 | 22 | test_that("two-level additive random intercept model",{ 23 | skip_on_cran() 24 | ## See p. 31 of Goldstein's book 25 | vcmodA <- lme4::lmer(mathAge11 ~ mathAge8 + gender + class + 26 | (1 | school), data = jsp728) 27 | 28 | 29 | orig.stats <- mySumm(vcmodA) 30 | 31 | set.seed(7142015) 32 | boo <- resid_bootstrap(model = vcmodA, .f = mySumm, B = nsim) 33 | 34 | expect_equal(class(boo), "lmeresamp") 35 | expect_equal(boo$observed, orig.stats) 36 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 37 | expect_equal(nrow(boo$replicates), nsim) 38 | expect_equal(ncol(boo$replicates), length(orig.stats)) 39 | expect_equal(boo$B, nsim) 40 | expect_equal(boo$type, "residual") 41 | expect_equal(boo$.f, mySumm) 42 | }) 43 | 44 | # ------------------------------------------------------------------------------ 45 | 46 | test_that("two-level random intercept model without interaction",{ 47 | skip_on_cran() 48 | ## See p. 97 of Goldstein's book 49 | rimod <- lmer(normAge11 ~ mathAge8c + gender + class + 50 | (1 | school), data = jsp728) 51 | 52 | orig.stats <- mySumm(rimod) 53 | boo <- resid_bootstrap(model = rimod, .f = mySumm, B = nsim) 54 | 55 | 56 | expect_equal(class(boo), "lmeresamp") 57 | expect_equal(boo$observed, orig.stats) 58 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 59 | expect_equal(nrow(boo$replicates), nsim) 60 | expect_equal(ncol(boo$replicates), length(orig.stats)) 61 | expect_equal(boo$B, nsim) 62 | expect_equal(boo$type, "residual") 63 | expect_equal(boo$.f, mySumm) 64 | }) 65 | 66 | 67 | test_that("two-level random intercept model with interaction",{ 68 | skip_on_cran() 69 | ## See p. 34 of Goldstein's book 70 | vcmodC <- lmer(mathAge11 ~ mathAge8 * schoolMathAge8 + gender + class + 71 | (1 | school), data = jsp728) 72 | 73 | orig.stats <- mySumm(vcmodC) 74 | boo <- resid_bootstrap(model = vcmodC, .f = mySumm, B = nsim) 75 | 76 | expect_equal(class(boo), "lmeresamp") 77 | expect_equal(boo$observed, orig.stats) 78 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 79 | expect_equal(nrow(boo$replicates), nsim) 80 | expect_equal(ncol(boo$replicates), length(orig.stats)) 81 | expect_equal(boo$B, nsim) 82 | expect_equal(boo$type, "residual") 83 | expect_equal(boo$.f, mySumm) 84 | }) 85 | 86 | # ------------------------------------------------------------------------------ 87 | 88 | test_that("two-level random coefficient model with interaction",{ 89 | skip_on_cran() 90 | ## See p. 35 of Goldstein's book 91 | rcmod <- lme4::lmer(mathAge11 ~ mathAge8c * schoolMathAge8 + gender + class + 92 | (mathAge8c | school), data = jsp728) 93 | 94 | orig.stats <- mySumm(rcmod) 95 | boo <- resid_bootstrap(model = rcmod, .f = mySumm, B = nsim) 96 | 97 | expect_equal(class(boo), "lmeresamp") 98 | expect_equal(boo$observed, orig.stats) 99 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 100 | expect_equal(nrow(boo$replicates), nsim) 101 | expect_equal(ncol(boo$replicates), length(orig.stats)) 102 | expect_equal(boo$B, nsim) 103 | expect_equal(boo$type, "residual") 104 | expect_equal(boo$.f, mySumm) 105 | }) 106 | 107 | # ------------------------------------------------------------------------------ 108 | 109 | test_that("three-level random intercept model",{ 110 | skip_on_cran() 111 | rmA <- lmer(rv ~ religion + year + (1 | respond) + (1 | district), data = Socatt) 112 | 113 | orig.stats <- mySumm(rmA) 114 | boo <- resid_bootstrap(model = rmA, .f = mySumm, B = nsim) 115 | 116 | expect_equal(class(boo), "lmeresamp") 117 | expect_equal(boo$observed, orig.stats) 118 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 119 | expect_equal(nrow(boo$replicates), nsim) 120 | expect_equal(ncol(boo$replicates), length(orig.stats)) 121 | expect_equal(boo$B, nsim) 122 | expect_equal(boo$type, "residual") 123 | expect_equal(boo$.f, mySumm) 124 | }) 125 | 126 | # ============================================================================== 127 | context("residual bootstrap (glmerMod)") 128 | # ============================================================================== 129 | 130 | mySumm <- function(.) { 131 | c(beta = getME(., "beta"), sig01 = unname(getME(., "theta"))) 132 | } 133 | 134 | test_that("two-level binomial logistic regression",{ 135 | skip_on_cran() 136 | gm <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), 137 | data = cbpp, family = binomial) 138 | 139 | orig.stats <- mySumm(gm) 140 | boo <- resid_bootstrap(model = gm, .f = mySumm, B = nsim) 141 | 142 | expect_equal(class(boo), "lmeresamp") 143 | expect_equal(boo$observed, orig.stats) 144 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 145 | expect_equal(nrow(boo$replicates), nsim) 146 | expect_equal(ncol(boo$replicates), length(orig.stats)) 147 | expect_equal(boo$B, nsim) 148 | expect_equal(boo$type, "residual") 149 | expect_equal(boo$.f, mySumm) 150 | }) 151 | 152 | # ------------------------------------------------------------------------------ 153 | 154 | test_that("two-level poisson regression model",{ 155 | skip_on_cran() 156 | gm <- glmer(TICKS ~ YEAR + cHEIGHT + (1|LOCATION), 157 | family="poisson",data=grouseticks) 158 | 159 | orig.stats <- mySumm(gm) 160 | boo <- resid_bootstrap(model = gm, .f = mySumm, B = nsim) 161 | 162 | expect_equal(class(boo), "lmeresamp") 163 | expect_equal(boo$observed, orig.stats) 164 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 165 | expect_equal(nrow(boo$replicates), nsim) 166 | expect_equal(ncol(boo$replicates), length(orig.stats)) 167 | expect_equal(boo$B, nsim) 168 | expect_equal(boo$type, "residual") 169 | expect_equal(boo$.f, mySumm) 170 | }) 171 | 172 | 173 | test_that("three-level poisson regression model",{ 174 | skip_on_cran() 175 | gm <- glmer(TICKS ~ YEAR + cHEIGHT + (1|LOCATION/BROOD), 176 | family="poisson", data=grouseticks) 177 | 178 | orig.stats <- mySumm(gm) 179 | boo <- resid_bootstrap(model = gm, .f = mySumm, B = nsim) 180 | 181 | expect_equal(class(boo), "lmeresamp") 182 | expect_equal(boo$observed, orig.stats) 183 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 184 | expect_equal(nrow(boo$replicates), nsim) 185 | expect_equal(ncol(boo$replicates), length(orig.stats)) 186 | expect_equal(boo$B, nsim) 187 | expect_equal(boo$type, "residual") 188 | expect_equal(boo$.f, mySumm) 189 | }) 190 | 191 | 192 | -------------------------------------------------------------------------------- /tests/testthat/test-resid-nlme.R: -------------------------------------------------------------------------------- 1 | library(nlme, quietly = TRUE) 2 | 3 | data(Socatt, package = "mlmRev") 4 | Socatt$religion <- relevel(Socatt$religion, ref = "none") 5 | Socatt$rv <- as.numeric(as.character(Socatt$numpos)) 6 | Socatt$rv <- scale(Socatt$rv) # a plot shows this is clearly non-normal 7 | 8 | 9 | # ============================================================================== 10 | context("residual bootstrap (lme)") 11 | # ============================================================================== 12 | 13 | 14 | mySumm <- function(.) { 15 | c(beta = fixef(.), sigma = as.numeric(.$sigma), sig01 = as.numeric(VarCorr(.)[1,2])) 16 | } 17 | 18 | nsim <- 10 19 | 20 | test_that("two-level additive random intercept model",{ 21 | skip_on_cran() 22 | ## See p. 31 of Goldstein's book 23 | vcmodA <- lme(mathAge11 ~ mathAge8 + gender + class, 24 | random = ~ 1 | school, data = jsp728) 25 | 26 | orig.stats <- mySumm(vcmodA) 27 | 28 | set.seed(7142015) 29 | boo <- resid_bootstrap(model = vcmodA, .f = mySumm, B = nsim) 30 | 31 | expect_equal(class(boo), "lmeresamp") 32 | expect_equal(boo$observed, orig.stats) 33 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 34 | expect_equal(nrow(boo$replicates), nsim) 35 | expect_equal(ncol(boo$replicates), length(orig.stats)) 36 | expect_equal(boo$B, nsim) 37 | expect_equal(boo$type, "residual") 38 | expect_equal(boo$.f, mySumm) 39 | }) 40 | 41 | # ------------------------------------------------------------------------------ 42 | test_that("two-level random intercept model with interaction",{ 43 | skip_on_cran() 44 | ## See p. 34 of Goldstein's book 45 | vcmodC <- lme(mathAge11 ~ mathAge8 * schoolMathAge8 + gender + class, 46 | random = ~ 1 | school, data = jsp728) 47 | 48 | orig.stats <- mySumm(vcmodC) 49 | boo <- resid_bootstrap(model = vcmodC, .f = mySumm, B = nsim) 50 | 51 | expect_equal(class(boo), "lmeresamp") 52 | expect_equal(boo$observed, orig.stats) 53 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 54 | expect_equal(nrow(boo$replicates), nsim) 55 | expect_equal(ncol(boo$replicates), length(orig.stats)) 56 | expect_equal(boo$B, nsim) 57 | expect_equal(boo$type, "residual") 58 | expect_equal(boo$.f, mySumm) 59 | }) 60 | 61 | # ------------------------------------------------------------------------------ 62 | 63 | test_that("two-level random coefficient model with interaction",{ 64 | skip_on_cran() 65 | ## See p. 35 of Goldstein's book 66 | rcmod <- lme(mathAge11 ~ mathAge8c * schoolMathAge8 + gender + class, 67 | random = ~ mathAge8c | school, data = jsp728) 68 | 69 | orig.stats <- mySumm(rcmod) 70 | boo <- resid_bootstrap(model = rcmod, .f = mySumm, B = nsim) 71 | 72 | expect_equal(class(boo), "lmeresamp") 73 | expect_equal(boo$observed, orig.stats) 74 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 75 | expect_equal(nrow(boo$replicates), nsim) 76 | expect_equal(ncol(boo$replicates), length(orig.stats)) 77 | expect_equal(boo$B, nsim) 78 | expect_equal(boo$type, "residual") 79 | expect_equal(boo$.f, mySumm) 80 | }) 81 | 82 | # ------------------------------------------------------------------------------ 83 | 84 | test_that("three-level random intercept model",{ 85 | skip_on_cran() 86 | rmA <- lme(rv ~ religion + year, random = ~ 1 | district/respond, data = Socatt) 87 | 88 | 89 | mySumm <- function(.) { 90 | c(beta = fixef(.), sigma = as.numeric(.$sigma), 91 | sig.dist = as.numeric(VarCorr(.)[2,2]), 92 | sig.int = as.numeric(VarCorr(.)[4,2])) 93 | } 94 | 95 | orig.stats <- mySumm(rmA) 96 | 97 | boo <- resid_bootstrap(model = rmA, .f = mySumm, B = nsim) 98 | 99 | expect_equal(class(boo), "lmeresamp") 100 | expect_equal(boo$observed, orig.stats) 101 | expect_equal(unname(boo$stats$observed), unname(orig.stats)) 102 | expect_equal(nrow(boo$replicates), nsim) 103 | expect_equal(ncol(boo$replicates), length(orig.stats)) 104 | expect_equal(boo$B, nsim) 105 | expect_equal(boo$type, "residual") 106 | expect_equal(boo$.f, mySumm) 107 | }) 108 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | --------------------------------------------------------------------------------