├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ └── rhub.yaml ├── .gitignore ├── CRAN-RELEASE ├── DESCRIPTION ├── HLMdiag.Rproj ├── NAMESPACE ├── NEWS.md ├── R ├── .Rapp.history ├── HLMdiag-defunct.R ├── HLMdiag-deprecated.R ├── HLMdiag-package.R ├── LSresids.R ├── adjust_formula_lmList.R ├── ahd.R ├── autism.R ├── case_delete.R ├── diagnostic_functions.R ├── group_level_residual_functions.R ├── help.R ├── hlm_augment.R ├── hlm_influence.R ├── hlm_resid.R ├── identification.R ├── influence_functions.R ├── plot_functions.R ├── pull_resid.R ├── radon.R ├── residual_functions.R ├── rotate_ranefs.R └── utility_functions.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── cran-comments.md ├── data ├── ahd.RData ├── autism.RData ├── radon.RData └── wages.RData ├── docs ├── 404.html ├── articles │ ├── hlm_resid.html │ ├── hlm_resid_files │ │ └── figure-html │ │ │ ├── unnamed-chunk-17-1.png │ │ │ ├── unnamed-chunk-18-1.png │ │ │ ├── unnamed-chunk-19-1.png │ │ │ └── unnamed-chunk-20-1.png │ ├── index.html │ ├── influence_diagnostics.html │ └── influence_diagnostics_files │ │ └── figure-html │ │ ├── unnamed-chunk-13-1.png │ │ ├── unnamed-chunk-16-1.png │ │ ├── unnamed-chunk-18-1.png │ │ ├── unnamed-chunk-20-1.png │ │ ├── unnamed-chunk-40-1.png │ │ ├── unnamed-chunk-43-1.png │ │ └── unnamed-chunk-8-1.png ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── index.html ├── link.svg ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml └── reference │ ├── HLMdiag.html │ ├── HLMresid.mer.html │ ├── LSresids.mer.html │ ├── adjust_lmList.formula.html │ ├── ahd.html │ ├── autism.html │ ├── case_delete.mer.html │ ├── compare_eb_ls-1.png │ ├── compare_eb_ls-2.png │ ├── compare_eb_ls.html │ ├── cooks.distance.html │ ├── covratio.html │ ├── diagnostics.html │ ├── dotplot_diag-1.png │ ├── dotplot_diag-2.png │ ├── dotplot_diag-3.png │ ├── dotplot_diag-4.png │ ├── dotplot_diag.html │ ├── extract_design.html │ ├── ggplot_qqnorm.html │ ├── group_qqnorm.html │ ├── hlm_augment.lmerMod.html │ ├── hlm_influence.lmerMod.html │ ├── hlm_resid.lmerMod.html │ ├── index.html │ ├── leverage.mer.html │ ├── pull_resid.lmerMod.html │ ├── radon.html │ ├── rotate_ranef.mer.html │ ├── rvc.mer.html │ ├── varcomp.mer.html │ └── wages.html ├── inst ├── CITATION └── image │ └── HLMdiag_hex.png ├── man ├── HLMdiag-defunct.Rd ├── HLMdiag-deprecated.Rd ├── HLMdiag.Rd ├── LSresids.mer.Rd ├── adjust_lmList.formula.Rd ├── ahd.Rd ├── autism.Rd ├── case_delete.mer.Rd ├── compare_eb_ls.Rd ├── cooks.distance.Rd ├── covratio.Rd ├── dotplot_diag.Rd ├── extract_design.Rd ├── figures │ └── logo.png ├── hlm_augment.Rd ├── hlm_influence.Rd ├── hlm_resid.Rd ├── leverage.mer.Rd ├── pull_resid.lmerMod.Rd ├── radon.Rd ├── resid_conditional.Rd ├── resid_marginal.Rd ├── resid_ranef.Rd ├── rotate_ranef.mer.Rd ├── rvc.mer.Rd ├── varcomp.mer.Rd └── wages.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 ├── cran.md ├── email.yml ├── failures.md └── problems.md ├── src ├── .gitignore ├── HLMdiag.dll ├── HLMdiag_init.c ├── Makevars ├── Makevars.win ├── cooksd_obs.cpp ├── cooksd_subset.cpp ├── covratio.cpp ├── covtrace.cpp ├── linear_algebra_fnc.cpp └── mdffits_subset.cpp ├── tests ├── testthat.R └── testthat │ ├── test-case_delete.R │ ├── test-hlm_augment.R │ ├── test-hlm_influence.R │ ├── test-hlm_resid.R │ ├── test-influence_functions.R │ └── test-pull_resid.R └── vignettes ├── .gitignore ├── hlm_resid.Rmd ├── influence_diagnostics.Rmd └── jss_update.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^.gitignore$ 4 | ^cran-comments\.md$ 5 | ^doc$ 6 | ^Meta$ 7 | ^README.Rmd$ 8 | ^_pkgdown\.yml$ 9 | ^docs$ 10 | ^pkgdown$ 11 | ^revdep$ 12 | ^jss_update$ 13 | ^CRAN-RELEASE$ 14 | ^\.github$ 15 | ^CRAN-SUBMISSION$ 16 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. 2 | # https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | pull_request: 9 | branches: 10 | - main 11 | - master 12 | 13 | name: R-CMD-check 14 | 15 | jobs: 16 | R-CMD-check: 17 | runs-on: ${{ matrix.config.os }} 18 | 19 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 20 | 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | config: 25 | - {os: windows-latest, r: 'release'} 26 | - {os: macOS-latest, r: 'release'} 27 | - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} 28 | - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} 29 | 30 | env: 31 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 32 | RSPM: ${{ matrix.config.rspm }} 33 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 34 | 35 | steps: 36 | - uses: actions/checkout@v2 37 | 38 | - uses: r-lib/actions/setup-r@v1 39 | with: 40 | r-version: ${{ matrix.config.r }} 41 | 42 | - uses: r-lib/actions/setup-pandoc@v1 43 | 44 | - name: Query dependencies 45 | run: | 46 | install.packages('remotes') 47 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 48 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") 49 | shell: Rscript {0} 50 | 51 | - name: Cache R packages 52 | if: runner.os != 'Windows' 53 | uses: actions/cache@v2 54 | with: 55 | path: ${{ env.R_LIBS_USER }} 56 | key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} 57 | restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- 58 | 59 | - name: Install system dependencies 60 | if: runner.os == 'Linux' 61 | run: | 62 | while read -r cmd 63 | do 64 | eval sudo $cmd 65 | done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') 66 | 67 | - name: Install dependencies 68 | run: | 69 | remotes::install_deps(dependencies = TRUE) 70 | remotes::install_cran("rcmdcheck") 71 | shell: Rscript {0} 72 | 73 | - name: Check 74 | env: 75 | _R_CHECK_CRAN_INCOMING_REMOTE_: false 76 | run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") 77 | shell: Rscript {0} 78 | 79 | - name: Upload check results 80 | if: failure() 81 | uses: actions/upload-artifact@main 82 | with: 83 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results 84 | path: check 85 | -------------------------------------------------------------------------------- /.github/workflows/rhub.yaml: -------------------------------------------------------------------------------- 1 | # R-hub's generic GitHub Actions workflow file. It's canonical location is at 2 | # https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml 3 | # You can update this file to a newer version using the rhub2 package: 4 | # 5 | # rhub::rhub_setup() 6 | # 7 | # It is unlikely that you need to modify this file manually. 8 | 9 | name: R-hub 10 | run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" 11 | 12 | on: 13 | workflow_dispatch: 14 | inputs: 15 | config: 16 | description: 'A comma separated list of R-hub platforms to use.' 17 | type: string 18 | default: 'linux,windows,macos' 19 | name: 20 | description: 'Run name. You can leave this empty now.' 21 | type: string 22 | id: 23 | description: 'Unique ID. You can leave this empty now.' 24 | type: string 25 | 26 | jobs: 27 | 28 | setup: 29 | runs-on: ubuntu-latest 30 | outputs: 31 | containers: ${{ steps.rhub-setup.outputs.containers }} 32 | platforms: ${{ steps.rhub-setup.outputs.platforms }} 33 | 34 | steps: 35 | # NO NEED TO CHECKOUT HERE 36 | - uses: r-hub/actions/setup@v1 37 | with: 38 | config: ${{ github.event.inputs.config }} 39 | id: rhub-setup 40 | 41 | linux-containers: 42 | needs: setup 43 | if: ${{ needs.setup.outputs.containers != '[]' }} 44 | runs-on: ubuntu-latest 45 | name: ${{ matrix.config.label }} 46 | strategy: 47 | fail-fast: false 48 | matrix: 49 | config: ${{ fromJson(needs.setup.outputs.containers) }} 50 | container: 51 | image: ${{ matrix.config.container }} 52 | 53 | steps: 54 | - uses: r-hub/actions/checkout@v1 55 | - uses: r-hub/actions/platform-info@v1 56 | with: 57 | token: ${{ secrets.RHUB_TOKEN }} 58 | job-config: ${{ matrix.config.job-config }} 59 | - uses: r-hub/actions/setup-deps@v1 60 | with: 61 | token: ${{ secrets.RHUB_TOKEN }} 62 | job-config: ${{ matrix.config.job-config }} 63 | - uses: r-hub/actions/run-check@v1 64 | with: 65 | token: ${{ secrets.RHUB_TOKEN }} 66 | job-config: ${{ matrix.config.job-config }} 67 | 68 | other-platforms: 69 | needs: setup 70 | if: ${{ needs.setup.outputs.platforms != '[]' }} 71 | runs-on: ${{ matrix.config.os }} 72 | name: ${{ matrix.config.label }} 73 | strategy: 74 | fail-fast: false 75 | matrix: 76 | config: ${{ fromJson(needs.setup.outputs.platforms) }} 77 | 78 | steps: 79 | - uses: r-hub/actions/checkout@v1 80 | - uses: r-hub/actions/setup-r@v1 81 | with: 82 | job-config: ${{ matrix.config.job-config }} 83 | token: ${{ secrets.RHUB_TOKEN }} 84 | - uses: r-hub/actions/platform-info@v1 85 | with: 86 | token: ${{ secrets.RHUB_TOKEN }} 87 | job-config: ${{ matrix.config.job-config }} 88 | - uses: r-hub/actions/setup-deps@v1 89 | with: 90 | job-config: ${{ matrix.config.job-config }} 91 | token: ${{ secrets.RHUB_TOKEN }} 92 | - uses: r-hub/actions/run-check@v1 93 | with: 94 | job-config: ${{ matrix.config.job-config }} 95 | token: ${{ secrets.RHUB_TOKEN }} 96 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user/E458F1A9/build_options 2 | *.pper 3 | *.pper 4 | .Rproj.user/E458F1A9/pcs/source-pane.pper 5 | .Rproj.user/E458F1A9/pcs/files-pane.pper 6 | *.pper 7 | .Rproj.user/E458F1A9/pcs/windowlayoutstate.pper 8 | .Rproj.user/E458F1A9/pcs/workbench-pane.pper 9 | .Rproj.user/E458F1A9/persistent-state 10 | .Rproj.user/E458F1A9/sdb/prop/10DEE9B6 11 | .Rproj.user/E458F1A9/sdb/prop/11401061 12 | .Rproj.user/E458F1A9/sdb/prop/14946CF9 13 | .Rproj.user/E458F1A9/sdb/prop/1537EF2A 14 | .Rproj.user/E458F1A9/sdb/prop/17EA334E 15 | .Rproj.user/E458F1A9/sdb/prop/1E46324D 16 | .Rproj.user/E458F1A9/sdb/prop/1E9668F1 17 | .Rproj.user/E458F1A9/sdb/prop/1FDDD672 18 | .Rproj.user/E458F1A9/sdb/prop/22368FF2 19 | .Rproj.user/E458F1A9/sdb/prop/23AC7EF0 20 | .Rproj.user/E458F1A9/sdb/prop/25CAAE7B 21 | .Rhistory 22 | .Rproj.user/E458F1A9/sdb/prop/2769B0B7 23 | .Rproj.user/E458F1A9/sdb/prop/277AAC40 24 | .Rproj.user/E458F1A9/sdb/prop/2908AA97 25 | .Rproj.user/E458F1A9/sdb/prop/3A5BAEEC 26 | .Rproj.user/E458F1A9/sdb/prop/3B70B907 27 | .Rproj.user/E458F1A9/sdb/prop/3BDB25E6 28 | .Rproj.user/E458F1A9/sdb/prop/415CA22 29 | .Rproj.user/E458F1A9/sdb/prop/4D40144B 30 | .Rproj.user/E458F1A9/sdb/prop/4FA179CA 31 | .Rproj.user/E458F1A9/sdb/prop/4FB7447D 32 | .Rproj.user 33 | 34 | *.history 35 | 36 | *.o 37 | *.so 38 | *.dll 39 | 40 | src/HLMdiag.so 41 | 42 | .RData 43 | inst/doc 44 | doc 45 | Meta 46 | docs 47 | -------------------------------------------------------------------------------- /CRAN-RELEASE: -------------------------------------------------------------------------------- 1 | This package was submitted to CRAN on 2021-05-01. 2 | Once it is accepted, delete this file and tag the release (commit 05b6aa2). 3 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: HLMdiag 2 | Type: Package 3 | Title: Diagnostic Tools for Hierarchical (Multilevel) Linear Models 4 | Version: 0.5.1.9000 5 | Authors@R: c(person("Adam", "Loy", email = "loyad01@gmail.com", role = c("cre", "aut")), person("Jaylin", "Lowe", role = "aut"), person("Jack", "Moran", role = "aut")) 6 | Maintainer: Adam Loy 7 | Description: A suite of diagnostic tools for hierarchical 8 | (multilevel) linear models. The tools include 9 | not only leverage and traditional deletion diagnostics (Cook's 10 | distance, covratio, covtrace, and MDFFITS) but also 11 | convenience functions and graphics for residual analysis. Models 12 | can be fit using either lmer in the 'lme4' package or lme in the 'nlme' package. 13 | Depends: 14 | R (>= 3.5.0) 15 | Imports: 16 | ggplot2 (>= 0.9.2), 17 | stats, 18 | methods, 19 | plyr, 20 | reshape2, 21 | MASS, 22 | Matrix, 23 | mgcv, 24 | dplyr, 25 | magrittr, 26 | stringr, 27 | purrr, 28 | tibble, 29 | tidyselect, 30 | janitor, 31 | Rcpp, 32 | rlang, 33 | ggrepel, 34 | diagonals 35 | LinkingTo: Rcpp, RcppArmadillo 36 | Suggests: 37 | mlmRev, 38 | WWGbook, 39 | lme4 (>= 1.0), 40 | nlme, 41 | testthat, 42 | knitr, 43 | rmarkdown, 44 | car, 45 | gridExtra, 46 | qqplotr 47 | License: GPL-2 48 | LazyLoad: yes 49 | LazyData: yes 50 | Collate: 51 | 'diagnostic_functions.R' 52 | 'group_level_residual_functions.R' 53 | 'identification.R' 54 | 'plot_functions.R' 55 | 'adjust_formula_lmList.R' 56 | 'case_delete.R' 57 | 'LSresids.R' 58 | 'HLMdiag-deprecated.R' 59 | 'HLMdiag-package.R' 60 | 'hlm_augment.R' 61 | 'hlm_influence.R' 62 | 'hlm_resid.R' 63 | 'help.R' 64 | 'influence_functions.R' 65 | 'utility_functions.R' 66 | 'rotate_ranefs.R' 67 | 'autism.R' 68 | 'ahd.R' 69 | 'radon.R' 70 | 'pull_resid.R' 71 | 'residual_functions.R' 72 | 'HLMdiag-defunct.R' 73 | Encoding: UTF-8 74 | URL: https://github.com/aloy/HLMdiag 75 | BugReports: https://github.com/aloy/HLMdiag/issues 76 | RoxygenNote: 7.3.2 77 | VignetteBuilder: knitr 78 | -------------------------------------------------------------------------------- /HLMdiag.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: 2be58e0c-e9e9-4a2a-9f46-b518468b820e 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: Default 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: knitr 14 | LaTeX: pdfLaTeX 15 | 16 | BuildType: Package 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(LSresids,default) 4 | S3method(LSresids,lme) 5 | S3method(LSresids,lmerMod) 6 | S3method(LSresids,mer) 7 | S3method(adjust_lmList,formula) 8 | S3method(case_delete,default) 9 | S3method(case_delete,lme) 10 | S3method(case_delete,lmerMod) 11 | S3method(case_delete,mer) 12 | S3method(coef,adjust_lmList) 13 | S3method(confint,adjust_lmList) 14 | S3method(cooks.distance,case_delete) 15 | S3method(cooks.distance,lme) 16 | S3method(cooks.distance,lmerMod) 17 | S3method(cooks.distance,mer) 18 | S3method(covratio,case_delete) 19 | S3method(covratio,default) 20 | S3method(covratio,lme) 21 | S3method(covratio,lmerMod) 22 | S3method(covratio,mer) 23 | S3method(covtrace,case_delete) 24 | S3method(covtrace,default) 25 | S3method(covtrace,lme) 26 | S3method(covtrace,lmerMod) 27 | S3method(covtrace,mer) 28 | S3method(hlm_augment,default) 29 | S3method(hlm_augment,lme) 30 | S3method(hlm_augment,lmerMod) 31 | S3method(hlm_influence,default) 32 | S3method(hlm_influence,lme) 33 | S3method(hlm_influence,lmerMod) 34 | S3method(hlm_resid,default) 35 | S3method(hlm_resid,lme) 36 | S3method(hlm_resid,lmerMod) 37 | S3method(leverage,default) 38 | S3method(leverage,lme) 39 | S3method(leverage,lmerMod) 40 | S3method(leverage,mer) 41 | S3method(mdffits,case_delete) 42 | S3method(mdffits,default) 43 | S3method(mdffits,lme) 44 | S3method(mdffits,lmerMod) 45 | S3method(mdffits,mer) 46 | S3method(plot,adjust_lmList.confint) 47 | S3method(print,adjust_lmList) 48 | S3method(pull_resid,default) 49 | S3method(pull_resid,lme) 50 | S3method(pull_resid,lmerMod) 51 | S3method(resid_conditional,default) 52 | S3method(resid_conditional,lme) 53 | S3method(resid_conditional,lmerMod) 54 | S3method(resid_marginal,default) 55 | S3method(resid_marginal,lme) 56 | S3method(resid_marginal,lmerMod) 57 | S3method(rotate_ranef,default) 58 | S3method(rotate_ranef,lme) 59 | S3method(rotate_ranef,lmerMod) 60 | S3method(rotate_ranef,mer) 61 | S3method(rvc,case_delete) 62 | S3method(rvc,default) 63 | S3method(rvc,lme) 64 | S3method(rvc,lmerMod) 65 | S3method(rvc,mer) 66 | export(LSresids) 67 | export(adjust_lmList) 68 | export(case_delete) 69 | export(compare_eb_ls) 70 | export(covratio) 71 | export(covtrace) 72 | export(dotplot_diag) 73 | export(extract_design) 74 | export(hlm_augment) 75 | export(hlm_influence) 76 | export(hlm_resid) 77 | export(leverage) 78 | export(mdffits) 79 | export(pull_resid) 80 | export(resid_conditional) 81 | export(resid_marginal) 82 | export(rotate_ranef) 83 | export(rvc) 84 | export(varcomp.mer) 85 | import(Matrix) 86 | import(ggplot2) 87 | import(methods) 88 | importFrom(MASS,rlm) 89 | importFrom(Rcpp,sourceCpp) 90 | importFrom(diagonals,fatdiag) 91 | importFrom(diagonals,split_vector) 92 | importFrom(dplyr,across) 93 | importFrom(dplyr,arrange) 94 | importFrom(dplyr,bind_cols) 95 | importFrom(dplyr,desc) 96 | importFrom(dplyr,filter) 97 | importFrom(dplyr,left_join) 98 | importFrom(dplyr,mutate) 99 | importFrom(dplyr,select) 100 | importFrom(grDevices,devAskNewPage) 101 | importFrom(janitor,clean_names) 102 | importFrom(magrittr,"%>%") 103 | importFrom(mgcv,tensor.prod.model.matrix) 104 | importFrom(plyr,adply) 105 | importFrom(plyr,ddply) 106 | importFrom(plyr,rbind.fill) 107 | importFrom(purrr,map) 108 | importFrom(purrr,map_dbl) 109 | importFrom(purrr,map_df) 110 | importFrom(purrr,map_dfc) 111 | importFrom(purrr,map_dfr) 112 | importFrom(purrr,map_lgl) 113 | importFrom(reshape2,dcast) 114 | importFrom(reshape2,melt) 115 | importFrom(rlang,.data) 116 | importFrom(stats,IQR) 117 | importFrom(stats,aggregate) 118 | importFrom(stats,as.formula) 119 | importFrom(stats,coef) 120 | importFrom(stats,complete.cases) 121 | importFrom(stats,confint) 122 | importFrom(stats,cooks.distance) 123 | importFrom(stats,covratio) 124 | importFrom(stats,fitted) 125 | importFrom(stats,formula) 126 | importFrom(stats,getCall) 127 | importFrom(stats,lm) 128 | importFrom(stats,lm.influence) 129 | importFrom(stats,model.frame) 130 | importFrom(stats,model.matrix) 131 | importFrom(stats,na.exclude) 132 | importFrom(stats,ppoints) 133 | importFrom(stats,predict) 134 | importFrom(stats,qnorm) 135 | importFrom(stats,qt) 136 | importFrom(stats,quantile) 137 | importFrom(stats,reorder) 138 | importFrom(stats,resid) 139 | importFrom(stats,rstandard) 140 | importFrom(stats,sigma) 141 | importFrom(stats,varimax) 142 | importFrom(stats,vcov) 143 | importFrom(stringr,str_c) 144 | importFrom(stringr,str_detect) 145 | importFrom(stringr,str_split) 146 | importFrom(tibble,tibble) 147 | importFrom(tidyselect,all_of) 148 | useDynLib(HLMdiag, .registration = TRUE) 149 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # HLMdiag (development version) 2 | 3 | # HLMdiag 0.5.1 4 | 5 | * Added a `NEWS.md` file to track changes to the package. 6 | * `cooks.distance()` and `mdffits()` with `include.attr = TRUE` now returns a tibble with column names for the fixed effects in agreement with the fixef() output. 7 | * First columns of `hlm_resid()` output is now `.id` to avoid conflicts with `id` columns 8 | 9 | # Version 0.5.0 10 | 11 | ## NEW FEATURES 12 | 13 | Added separate functions to calculate residuals for LMEs. 14 | 15 | * `resid_marginal()` calculates (raw, studentized, Pearson, or Cholesky) marginal residuals. 16 | * `resid_conditional` calculates (raw, studentized, Pearson, or Cholesky) conditional residuals (i.e., error terms). 17 | * `resid_ranef` calculates raw and standardized predicted random effects. 18 | 19 | 20 | ## USER-VISIBLE CHANGES 21 | 22 | The following functions are now defunct 23 | 24 | * `HLMresid` 25 | * `diagnostics` 26 | * `group_qqnorm` 27 | * `ggplot_qqnorm` 28 | 29 | 30 | # Version 0.4.0 31 | 32 | ## DEVELOPMENT 33 | 34 | * Influence diagnostics are now avaliable through the `case_delete` function and accompaning functions for `lme` objects from the `nlme` package. These diagnostics are also avaliable for three-level models. 35 | * Residual diagnostics are also now available via `hlm_resid` for `lme` model objects and three-level models. 36 | 37 | ## USER-VISIBLE CHANGES 38 | 39 | * The `group` parameter for influence diagnostics has been changed to `level` in order to match the residual functions. 40 | `level` defaults to NULL, which will delete individual observations iteratively as `group = NULL` did. 41 | * The `cooks.distance` and `mdffits` functions now only return the values as a numeric vector, instead of also returning the 42 | beta values as attributes. If these attributes are desired, the user can now set `include.attr = TRUE`, and a tibble 43 | will be returned instead with the influence diagnostics and the beta attributes. 44 | * The `dotplot_diag` function has been updated to be more efficient. Additionally, it no longer places labels on the y-axis 45 | and only labels the top five observations in order to improve visibility. 46 | * `LSresid` now returns only the residual values, excluding the model frame 47 | * The `sim` argument for `LSresid` has been removed 48 | 49 | ## NEW FEATURES 50 | 51 | * The `hlm_influence` function has been added. This function returns influence diagnostics appended to the model frame. 52 | * The `hlm_resid` function has been added. This function returns residual diagnostics appended to the model frame. 53 | * The `hlm_augment` function has been added, which combines `hlm_influence` and `hlm_resid` to return influence diagnostics and residuals appended to the model frame. 54 | * The `pull_resid` function has been added. This funciton returns a vector of a specified type of residual prioritizing computational efficiency. 55 | * The `delete` parameter in `case_delete`, `hlm_influence`, and `hlm_augment` now also accepts character vectors at the second or third level. Observations or groups to be deleted can be specified by row indices in a numeric vector (as previously), or as character vectors of group level names found in `model@flist` (lmerMod models) or `model$groups` (lme models). 56 | 57 | ## BUG FIXES 58 | 59 | * `cooks.distance` and `mdffits` functions were fixed to solve an issue with the number of columns. 60 | * Fixed an issue with `case_delete` so that it works with three level models. 61 | * `hlm_resid`, `hlm_influence`, and `hlm_augment` properly respect `na.action` and work with models fit in `nlme` 62 | * `LSresids` doesn't break with three-level models, or with models containing tranformed variables 63 | 64 | 65 | # Version 0.3.1 66 | 67 | 68 | ## BUG FIXES 69 | * `.extractV.lme` (and thus `.lme_matrices`) was fixed to work with more complex covariance structures fit via nlme. 70 | * Updated package to work with the most recent version of `ggplot2` 71 | 72 | # Version 0.3.0 73 | 74 | ## DEVELOPMENT 75 | 76 | * Influence diagnostics in HLMdiag 0.3.0 are available for two-level models fit 77 | using the `lmer` function in lme4` or the `lme` function in `nlme`. I am still 78 | working to implement these methods for higher-level models using `lme`. 79 | * HLMdiag no longer loads lme4 automatically (see above for the reason). 80 | 81 | ## NEW FEATURES 82 | 83 | * The `rotate_ranef` function has been added. This function rotates the random 84 | effects in an effort to find the least confounded residuals for distributional 85 | assessment. 86 | 87 | ## BUG FIXES 88 | 89 | * `LSresids` was fixed for an issue with the order of the resulting data frame. 90 | * `case_delete` was fixed so that numeric group labels work properly, which fixes an issue 91 | with `rvc`. 92 | * Fixed an issue with `group_qqnorm`, by using `ppoints` rather than `.SampleQuantiles`. 93 | * Fixed an issue with `case_delete.lmerMod`, to use the `getME()` function to extract `n`. 94 | * A bug in the calculation of the Cholesky residuals was fixed (thanks to Harry Hiemstra for reporting the bug and the fix) 95 | 96 | 97 | # Version 0.2.5 98 | 99 | * Fixed a compatibility issue with Rcpp 100 | 101 | # Version 0.2.4 102 | 103 | * Added citation for the JSS paper 104 | * Fixed a bug with the calculation of Cook's distance 105 | 106 | # Version 0.2.3 107 | 108 | * Added a function to calculate rotated random effects 109 | * Added new data sets 110 | * Maintenance for compatibility with lme4 1.0 and R 3.0.2 111 | 112 | # Version 0.2.2 113 | 114 | * Changed the standardization of the EB level-1 residuals in `HLMresid` 115 | to a more appropriate definition: e / var(\hat{e}). 116 | * Added functions to add compatibility with the development version of lme4. 117 | 118 | 119 | # Version 0.2.1 120 | 121 | * Fixed a bug in `group_qqnorm` 122 | * Checked compatibility with R 2.15.3 123 | 124 | 125 | # Version 0.2.0 126 | 127 | ## DEVELOPMENT 128 | 129 | * Influence diagnostics in HLMdiag 0.2.0 are compatible with hierarchical 130 | (multilevel) linear models of any size and with models with crossed factors. 131 | * HLMdiag 0.2.0 offers significantly faster computation of the deletion 132 | diagnostics for fixed effects that are based on one-step approximations. 133 | * S3 methods have been created for `cooks.distance`, `mdffits`, `covratio`, 134 | `covtrace`, `rvc`, and `leverage` for objects of class `mer`. 135 | * Full deletions are still available using the `case_delete` function, with 136 | corresponding S3 methods for objects of class `case_delete`. 137 | 138 | ## NEW FEATURES 139 | 140 | * A `leverage` function has been added. 141 | * `case_delete` and other deletion functions now allow for the user to 142 | manually specify a subset to delete. 143 | 144 | ## OTHER USER-VISIBLE CHANGES 145 | 146 | * changes to the arguments of `dotplot_diag` to accomodate a more general 147 | usage. 148 | * `diagnostics` no longer requires a `model` parameter to be specified. 149 | * A `delete` parameter has been added to `case_delete` to allow for manual 150 | specification of a subset that should be deleted. 151 | * For observation-level deletion using `case_delete` the user should specify 152 | `group = NULL` rather than `group = FALSE`. 153 | 154 | 155 | # Version 0.1.6 156 | 157 | * Updates for compatibility with ggplot2 >= 0.9.2 158 | * Updates to NAMESPACE 159 | 160 | # Version 0.1.5 161 | 162 | * Updates to NAMESPACE to fix compatibility issues 163 | 164 | # Version 0.1.4 165 | 166 | * Updates for compatibility with ggplot2 0.9.0 167 | 168 | # Version 0.1.3 169 | 170 | * Added "marginal" residuals to the type argument for HLMresid. 171 | 172 | # Version 0.1.2 173 | 174 | 175 | ## USER-VISIBLE CHANGES: 176 | 177 | * Removed the formula argument from LSresids. The formula is now obtained automatically from the mer object. Note: we are still working on automatic recognition of math operators such as log(), but anything in I() is recognized. 178 | * Added the function HLMresid, a wrapper that will extract both the LS and EB residuals given an mer object. 179 | * Added a level argument to LSresids, so the function can extract LS residuals from either level of the model. 180 | 181 | ## BUG FIXES: 182 | 183 | * Fixed the ordering of output from 'LSresids' to match the mode frame obtained from the mer object. 184 | 185 | # Version 0.1.1 186 | 187 | * Created 'adjust_lmList' class to handle fitting separate linear models when a factor is constant across the group. 188 | * 'random_ls_coef' was removed and replaced by the 'coef' method for 'adjust_lmList' objects. 189 | * Added 'rvc' diagnostic. 190 | * Extended 'case_delete' from only handling deletion for fixed effects to also handling deletion for variance components. 191 | * Improved 'dotplot_diag' to handle modified dotplots. 192 | -------------------------------------------------------------------------------- /R/.Rapp.history: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/R/.Rapp.history -------------------------------------------------------------------------------- /R/HLMdiag-defunct.R: -------------------------------------------------------------------------------- 1 | #' Defunct functions in package HLMdiag 2 | #' 3 | #' These functions are defunct and no longer available. 4 | #' 5 | #' @param ... arguments passed to defunct functions 6 | #' 7 | #' @details 8 | #' \code{HLMresid} is replaced by \code{\link{hlm_resid}} 9 | #' 10 | #' \code{diagnostics} is replaced by \code{\link{hlm_influence}} 11 | #' 12 | #' \code{group_qqnorm} and \code{group_qqnorm} are replaced by functions in \pkg{qqplotr}. 13 | #' See \code{\link[qqplotr]{stat_qq_point}}, \code{\link[qqplotr]{stat_qq_line}}, and 14 | #' \code{\link[qqplotr]{stat_qq_band}}. 15 | #' 16 | #' @name HLMdiag-defunct 17 | NULL 18 | 19 | #' @rdname HLMdiag-defunct 20 | HLMresid <- function (...) { 21 | .Defunct("hlm_resid", package = "HLMresid") 22 | } 23 | 24 | #' @rdname HLMdiag-defunct 25 | HLMresid.default <- function (...) { 26 | .Defunct("hlm_resid", package = "HLMresid") 27 | } 28 | 29 | #' @rdname HLMdiag-defunct 30 | HLMresid.lmerMod <- function (...) { 31 | .Defunct("hlm_resid", package = "HLMresid") 32 | } 33 | 34 | #' @rdname HLMdiag-defunct 35 | HLMresid.mer <- function (...) { 36 | .Defunct("hlm_resid", package = "HLMresid") 37 | } 38 | 39 | #' @rdname HLMdiag-defunct 40 | diagnostics <- function (...) { 41 | .Defunct("hlm_influence", package = "HLMresid") 42 | } 43 | 44 | #' @rdname HLMdiag-defunct 45 | group_qqnorm <- function(...) { 46 | .Defunct("stat_qq_point", package = "qqplotr") 47 | } 48 | 49 | #' @rdname HLMdiag-defunct 50 | ggplot_qqnorm <- function(...) { 51 | .Defunct("stat_qq_point", package = "qqplotr") 52 | } -------------------------------------------------------------------------------- /R/HLMdiag-deprecated.R: -------------------------------------------------------------------------------- 1 | #' Deprecated functions in HLMdiag 2 | #' 3 | #' These functions still work but will be removed (defunct) in the next version. 4 | #' 5 | #' \itemize{ 6 | #' \item \code{\link{HLMresid}}: This function is deprecated, and will 7 | #' be removed in the next version of this package. 8 | #' \item \code{\link{diagnostics}}: This function is deprecated, and will 9 | #' be removed in the next version of this package. 10 | #' } 11 | #' 12 | #' @name HLMdiag-deprecated 13 | NULL -------------------------------------------------------------------------------- /R/HLMdiag-package.R: -------------------------------------------------------------------------------- 1 | ## usethis namespace: start 2 | #' @useDynLib HLMdiag, .registration = TRUE 3 | #' @importFrom Rcpp sourceCpp 4 | ## usethis namespace: end 5 | NULL 6 | 7 | .onUnload <- function (libpath) { 8 | library.dynam.unload("HLMdiag", libpath) 9 | } -------------------------------------------------------------------------------- /R/ahd.R: -------------------------------------------------------------------------------- 1 | #' Methylprednisolone data 2 | #' 3 | #' Data from a longitudinal study examining the effectiveness of Methylprednisolone 4 | #' as a treatment for patients with severe alcoholic hepatitis. Subjects were 5 | #' randomly assigned to a treatment (31 received a placebo, 35 received the 6 | #' treatment) and serum bilirubin was measures each week for four weeks. 7 | #' 8 | #' @usage data(ahd) 9 | #' @format A data frame with 330 observations on the following 5 variables: 10 | #' \describe{ 11 | #' \item{treatment}{The treatment a subject received - a factor. Levels are 12 | #' \code{placebo} and \code{treated}.} 13 | #' \item{subject}{Subject ID - a factor.} 14 | #' \item{week}{Week of the study (0--4) - the time variable.} 15 | #' \item{sbvalue}{Serum bilirubin level (in \eqn{\mu}mol/L). } 16 | #' \item{baseline}{A subject's serum bilirubin level at week 0.} 17 | #' } 18 | #' @name ahd 19 | #' @docType data 20 | #' @keywords datasets 21 | #' @source 22 | #' Vonesh, E. F. and Chinchilli, V. M. (1997) \emph{Linear and Nonlinear Models for the 23 | #' Analysis of Repeated Measurements}. Marcel Dekker, New York. 24 | #' @references 25 | #' Carithers, R. L., Herlong, H. F., Diehl, A. M., Shaw, E. W., Combes, B., 26 | #' Fallon, H. J. & Maddrey, W. C. (1989) Methylprednisolone therapy in 27 | #' patients with severe alcoholic hepatitis. \emph{Annals of Internal Medicine}, 28 | #' \bold{110}(9), 685--690. 29 | NULL -------------------------------------------------------------------------------- /R/autism.R: -------------------------------------------------------------------------------- 1 | #' Autism data 2 | #' 3 | #' Data from a prospective longitudinal study following 214 children between 4 | #' the ages of 2 and 13 who were diagnosed with either autism spectrum disorder 5 | #' or non-spectrum developmental delays at age 2. 6 | #' 7 | #' @usage data(autism) 8 | #' @format A data frame with 604 observation on the following 7 variables: 9 | #' \describe{ 10 | #' \item{childid}{Child ID.} 11 | #' \item{sicdegp}{Sequenced Inventory of Communication Development group (an 12 | #' assessment of expressive language development) - a factor. Levels are 13 | #' \code{low}, \code{med}, and \code{high}.} 14 | #' \item{age2}{Age (in years) centered around age 2 (age at diagnosis).} 15 | #' \item{vsae}{Vineland Socialization Age Equivalent} 16 | #' \item{gender}{Child's gender - a factor. Levels are \code{male} and \code{female}.} 17 | #' \item{race}{Child's race - a factor. Levels are \code{white} and \code{nonwhite}.} 18 | #' \item{bestest2}{Diagnosis at age 2 - a factor. Levels are \code{autism} and 19 | #' \code{pdd} (pervasive developmental disorder).} 20 | #' } 21 | #' @name autism 22 | #' @docType data 23 | #' @keywords datasets 24 | #' @source \url{http://www-personal.umich.edu/~kwelch/} 25 | #' @references 26 | #' Anderson, D. K., Lord, C., Risi, S., DiLavore, P. S., Shulman, C., 27 | #' Thurm, A., et al. (2007). Patterns of growth in verbal abilities among 28 | #' children with autism spectrum disorder. \emph{Journal of Consulting and 29 | #' Clinical Psychology}, \bold{75}(4), 594--604. 30 | #' 31 | #' Anderson, D. K., Oti, R. S., Lord, C., & Welch, K. (2009). 32 | #' Patterns of Growth in Adaptive Social Abilities Among Children with Autism 33 | #' Spectrum Disorders. \emph{Journal of Abnormal Child Psychology}, 34 | #' \bold{37}(7), 1019--1034. 35 | NULL -------------------------------------------------------------------------------- /R/diagnostic_functions.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | #' @rdname hlm_influence 3 | #' @param model an object containing the output returned by \code{case_delete()}. 4 | #' This is only named differently to agree with the generic. 5 | #' @method cooks.distance case_delete 6 | cooks.distance.case_delete <- function(model, ...){ 7 | p <- length(model$fixef.original) 8 | 9 | if (colnames(model$fixef.delete)[1] == "deleted") { 10 | model$fixef.delete <- model$fixef.delete[,-1] 11 | } 12 | 13 | if(is(model$fixef.delete, "matrix")) { 14 | groups <- rownames(model$fixef.delete, do.NULL = FALSE, prefix = "") 15 | cook <- NULL 16 | for(i in 1:length(groups)){ 17 | change.fixef <- as.matrix(model$fixef.original - model$fixef.delete[i,]) 18 | cook <- c(cook, t(change.fixef) %*% solve( as.matrix( model$vcov.original ) ) %*% change.fixef / p) 19 | } 20 | } 21 | else{ 22 | change.fixef <- as.matrix(model$fixef.original - model$fixef.delete) 23 | cook <- t(change.fixef) %*% solve( as.matrix( model$vcov.original ) ) %*% change.fixef / p 24 | } 25 | 26 | return(cook) 27 | } 28 | 29 | 30 | #' @export 31 | #' @rdname hlm_influence 32 | #' @method mdffits case_delete 33 | mdffits.case_delete <- function(model, ...){ 34 | p <- length(model$fixef.original) 35 | 36 | if (colnames(model$fixef.delete)[1] == "deleted") { 37 | model$fixef.delete <- model$fixef.delete[,-1] 38 | } 39 | 40 | if(is(model$fixef.delete, "matrix")) { 41 | groups <- rownames(model$fixef.delete, do.NULL = FALSE, prefix = "") 42 | MDFFITS <- NULL 43 | for(i in 1:length(groups)){ 44 | change.fixef <- as.matrix(model$fixef.original - model$fixef.delete[i,]) 45 | MDFFITS <- c(MDFFITS, t(change.fixef) %*% solve( as.matrix(model$vcov.delete[[i]]) ) %*% change.fixef / p) 46 | } 47 | } 48 | else{ 49 | change.fixef <- as.matrix(model$fixef.original - model$fixef.delete) 50 | MDFFITS <- t(change.fixef) %*% solve( as.matrix(model$vcov.delete) ) %*% change.fixef / p 51 | } 52 | 53 | return(MDFFITS) 54 | } 55 | 56 | 57 | #' @export 58 | #' @rdname hlm_influence 59 | #' @method covtrace case_delete 60 | covtrace.case_delete <- function(model, ...){ 61 | p <- length(model$fixef.original) 62 | 63 | if(is(model$vcov.delete, "list")) { 64 | groups <- rownames(model$fixef.delete, do.NULL = FALSE, prefix = "") 65 | COVTRACE <- NULL 66 | for(i in 1:length(groups)){ 67 | V.original <- as.matrix(model$vcov.original) 68 | V.delete <- as.matrix(model$vcov.delete[[i]]) 69 | COVTRACE <- c(COVTRACE, abs(sum(diag(solve(V.original) %*% V.delete)) - p)) 70 | } 71 | } 72 | else{ 73 | V.original <- as.matrix(model$vcov.original) 74 | V.delete <- as.matrix(model$vcov.delete) 75 | COVTRACE <- abs(sum(diag(solve(V.original) %*% V.delete)) - p) 76 | } 77 | 78 | return(COVTRACE) 79 | } 80 | 81 | 82 | 83 | #' @export 84 | #' @rdname hlm_influence 85 | #' @method covratio case_delete 86 | covratio.case_delete <- function(model, ...){ 87 | if(is(model$vcov.delete, "list")) { 88 | groups <- rownames(model$fixef.delete, do.NULL = FALSE, prefix = "") 89 | COVRATIO <- NULL 90 | for(i in 1:length(groups)){ 91 | V.original <- as.matrix(model$vcov.original) 92 | V.delete <- as.matrix(model$vcov.delete[[i]]) 93 | COVRATIO <- c(COVRATIO, det(V.delete) / det(V.original)) 94 | } 95 | } 96 | else{ 97 | V.original <- as.matrix(model$vcov.original) 98 | V.delete <- as.matrix(model$vcov.delete) 99 | COVRATIO <- det(V.delete) / det(V.original) 100 | } 101 | 102 | return(COVRATIO) 103 | } 104 | 105 | 106 | 107 | #' @export 108 | #' @rdname hlm_influence 109 | #' @param ... do not use 110 | #' @method rvc case_delete 111 | rvc.case_delete <- function(model, ...){ 112 | if(inherits(model$varcomp.delete, "list")) { 113 | res <- do.call('rbind', lapply(model$varcomp.delete, function(x){ (x / model$varcomp.original) - 1})) 114 | } 115 | else{ 116 | res <- (model$varcomp.delete / model$varcomp.original) - 1 117 | } 118 | return(res) 119 | } 120 | -------------------------------------------------------------------------------- /R/group_level_residual_functions.R: -------------------------------------------------------------------------------- 1 | #'Visually comparing shrinkage and LS estimates 2 | #' 3 | #'This function creates a plot (using \code{qplot()}) where the shrinkage 4 | #'estimate appears on the horizontal axis and the LS estimate appears on the 5 | #'vertical axis. 6 | #' 7 | #' 8 | #'@param eb a matrix of random effects 9 | #'@param ols a matrix of the OLS estimates found using \code{random_ls_coef} 10 | #'@param identify the percentage of points to identify as unusual, 11 | #'\code{FALSE} if you do not want the points identified. 12 | #'@param silent logical: should the list of data frames used to make the plots 13 | #' be suppressed. 14 | #'@param ... other arguments to be passed to \code{qplot()} 15 | #'@author Adam Loy \email{loyad01@@gmail.com} 16 | #'@export 17 | #'@examples 18 | #' 19 | #'wages.fm1 <- lme4::lmer(lnw ~ exper + (exper | id), data = wages) 20 | #'wages.sepLM <- adjust_lmList(lnw ~ exper | id, data = wages) 21 | #'rancoef.eb <- coef(wages.fm1)$id 22 | #'rancoef.ols <- coef(wages.sepLM) 23 | #'compare_eb_ls(eb = rancoef.eb, ols = rancoef.ols, identify = 0.01) 24 | #' 25 | compare_eb_ls <- function(eb, ols, identify = FALSE, silent = TRUE, ...){ 26 | unusual <- ids <- NULL # Make codetools happy 27 | ret <- NULL 28 | for(i in 1:dim(ols)[2]){ 29 | p <- qplot(x = eb[,i], y = ols[,i], geom = "point", main = colnames(eb)[i], 30 | xlab = "EB resid", ylab = "LS resid", ...) + 31 | geom_abline(intercept = 0, slope = 1, linetype = I(2)) + 32 | geom_smooth(method = "lm", se = FALSE) 33 | if(identify != FALSE){ 34 | temp_eb <- eb[,i] 35 | attr(temp_eb, "names") <- rownames(eb) 36 | extreme <- identify_resid(eb = temp_eb, ols = ols[,i], identify = identify) 37 | dat <- cbind(eb = temp_eb, ols = ols[,i]) 38 | dat <- as.data.frame(dat) 39 | dat$ids <- names(temp_eb) 40 | extreme <- merge(x = dat, y = extreme) 41 | # extreme <- cbind(dat, extreme) 42 | # extreme <- extreme[order(abs(extreme$residual), decreasing = TRUE), ] 43 | # n <- round(dim(extreme)[1] * identify) 44 | 45 | p <- p + geom_text(data = subset(extreme, unusual == TRUE), aes(x = eb, y = ols, label = ids, hjust=.5, vjust=1.5), size=I(3)) 46 | #ret <- list(ret, subset(extreme, unusual == TRUE)) 47 | ret <- list(ret, extreme) 48 | } 49 | oask <- grDevices::devAskNewPage(TRUE) 50 | on.exit(grDevices::devAskNewPage(oask)) 51 | print(p) 52 | } 53 | 54 | if(silent == FALSE){ 55 | ret <- list(ret[[1]][[2]], ret[[2]]) 56 | return(ret) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /R/help.R: -------------------------------------------------------------------------------- 1 | #' Diagnostic tools for hierarchical (multilevel) linear models 2 | #' 3 | #' HLMdiag provides a suite of diagnostic tools for hierarchical 4 | #' (multilevel) linear models fit using the \code{lme4} or \code{nlme} 5 | #' packages. These tools are grouped below by purpose. 6 | #' See the help documentation for additional information 7 | #' about each function. 8 | #' 9 | #' \bold{Residual analysis} 10 | #' 11 | #' HLMdiag's \code{\link{hlm_resid}} function provides a wrapper that 12 | #' extracts residuals and fitted values for individual observations 13 | #' or groups of observations. In addition to being a wrapper function for functions 14 | #' implemented in the \code{lme4} and \code{nlme} packages, 15 | #' \code{\link{hlm_resid}} provides access to the marginal and least squares 16 | #' residuals. 17 | #' 18 | #' \bold{Influence analysis} 19 | #' 20 | #' HLMdiag's \code{\link{hlm_influence}} function provides a convenient wrapper 21 | #' to obtain influence diagnostics for each observation or group of observations 22 | #' appended to the data used to fit the model. The diagnostics returned by 23 | #' \code{\link{hlm_influence}} include Cook's distance, MDFFITS, covariance trace (covtrace), 24 | #' covariance ratio (covratio), leverage, and relative variance change (RVC). 25 | #' HLMdiag also contains functions to calculate these diagnostics individually, as discussed below. 26 | #' 27 | #' Influence on fitted values 28 | #' 29 | #' HLMdiag provides \code{\link{leverage}} that calculates the influence 30 | #' that observations/groups have on the fitted values (leverage). 31 | #' For mixed/hierarchical models leverage can be decomposed into two parts: the 32 | #' fixed part and the random part. We refer the user to the references 33 | #' cited in the help documentation for additional explanation. 34 | #' 35 | #' Influence on fixed effects estimates 36 | #' 37 | #' HLMdiag provides \code{\link{cooks.distance}} and \code{\link{mdffits}} 38 | #' to assess the influence of subsets of observations on the fixed effects. 39 | #' 40 | #' Influence on precision of fixed effects 41 | #' 42 | #' HLMdiag provides \code{\link{covratio}} and \code{\link{covtrace}} 43 | #' to assess the influence of subsets of observations on the precision of 44 | #' the fixed effects. 45 | #' 46 | #' Influence on variance components 47 | #' 48 | #' HLMdiag's \code{\link{rvc}} calculates the relative variance change to 49 | #' assess the influence of subsets of observations on the variance 50 | #' components. 51 | #' 52 | #' \bold{Graphics} 53 | #' 54 | #' HLMdiag also strives to make graphical assessment easier in the 55 | #' \code{ggplot2} framework by providing dotplots for influence diagnostics 56 | #' (\code{\link{dotplot_diag}}), grouped Q-Q plots (\code{\link{group_qqnorm}}), 57 | #' and Q-Q plots that combine the functionality of \code{\link{qqnorm}} and 58 | #' \code{\link{qqline}} (\code{\link{ggplot_qqnorm}}). 59 | #' 60 | #' @useDynLib HLMdiag, .registration = TRUE 61 | #' @importFrom magrittr %>% 62 | #' @importFrom reshape2 melt dcast 63 | #' @importFrom plyr adply ddply 64 | #' @importFrom MASS rlm 65 | #' @importFrom mgcv tensor.prod.model.matrix 66 | #' @importFrom dplyr select left_join mutate across bind_cols filter arrange desc 67 | #' @importFrom stringr str_c str_detect str_split 68 | #' @importFrom purrr map map_lgl map_df map_dfc map_dfr map_dbl 69 | #' @importFrom tibble tibble 70 | #' @importFrom tidyselect all_of 71 | #' @importFrom janitor clean_names 72 | #' @import Matrix 73 | #' @import methods 74 | #' @import ggplot2 75 | #' @importFrom grDevices devAskNewPage 76 | #' @importFrom stats coef confint IQR aggregate 77 | #' complete.cases fitted formula lm lm.influence model.frame 78 | #' model.matrix ppoints qnorm qt quantile reorder resid rstandard 79 | #' varimax vcov cooks.distance covratio as.formula getCall na.exclude 80 | #' predict sigma 81 | #' @name HLMdiag 82 | #' @aliases HLMdiag package-HLMdiag 83 | #' @keywords package 84 | "_PACKAGE" -------------------------------------------------------------------------------- /R/hlm_augment.R: -------------------------------------------------------------------------------- 1 | #' Calculating residuals and influence diagnostics for HLMs 2 | #' 3 | #' 4 | #' This function is used to compute residuals, fitted values, and influence diagnostics for a 5 | #' hierarchical linear model. The residuals and fitted values are computed using Least Squares(LS) 6 | #' and Empirical Bayes (EB) methods. The influence diagnostics are computed through one step 7 | #' approximations. 8 | #' 9 | #' @export 10 | #' @param object an object of class \code{lmerMod} or \code{lme}. 11 | #' @param level which residuals should be extracted and what cases should be deleted for influence diagnostics. 12 | #'If \code{level = 1} (default), then within-group (case-level) residuals are returned and influence diagnostics 13 | #'are calculated for individual observations. Otherwise, \code{level} should be the name of a grouping 14 | #'factor as defined in \code{flist} for a \code{lmerMod} object or as in \code{groups} for a \code{lme} object. 15 | #'This will return between-group residuals and influence diagnostics calculated for each group. 16 | #' @param include.ls a logical indicating if LS residuals should be included in the 17 | #'return tibble. \code{include.ls = FALSE} decreases runtime substantially. 18 | #' @param data the original data frame passed to `lmer`. This is only necessary for `lmerMod` models where 19 | #'`na.action = "na.exclude"` 20 | #' @param ... currently not used 21 | #' @details The \code{hlm_augment} function combines functionality from \code{hlm_resid} 22 | #'and \code{hlm_influence} for a simpler way of obtaining residuals and influence 23 | #'diagnostics. Please see \code{?hlm_resid} and \code{?hlm_influence} for additional information 24 | #'about the returned values. 25 | #'@note \code{hlm_augment} does not allow for the deletion of specific cases, the specification of other 26 | #'types of leverage, or the use of full refits of the model instead of one step approximations for influence 27 | #'diagnostics. If this additional functionality is desired, \code{hlm_influence} should be used instead. The additional 28 | #'parameter \code{standardize} is available in \code{hlm_resid}; if this are desired, \code{hlm_resid} 29 | #'should be used instead. 30 | hlm_augment <- function(object, ...){ 31 | UseMethod("hlm_augment", object) 32 | } 33 | 34 | #' @export 35 | #' @rdname hlm_augment 36 | #' @method hlm_augment default 37 | hlm_augment.default <- function(object, ...){ 38 | stop(paste("there is no hlm_augment() method for objects of class", 39 | paste(class(object), collapse=", "))) 40 | } 41 | 42 | 43 | 44 | #' @export 45 | #' @method hlm_augment lmerMod 46 | #' @rdname hlm_augment 47 | hlm_augment.lmerMod <- function(object, level = 1, include.ls = TRUE, data = NULL, ...) { 48 | residuals <- hlm_resid(object, level = level, include.ls = include.ls, data = data) 49 | infl <- hlm_influence(object, level = level, data = data) 50 | if (level == 1) { 51 | infl <- infl[,-c(1:(1+ncol(object@frame)))] 52 | } 53 | else { 54 | infl <- infl[,-1] 55 | } 56 | aug.tibble <- tibble::add_column(residuals, infl) 57 | return(aug.tibble) 58 | } 59 | 60 | #' @export 61 | #' @rdname hlm_augment 62 | #' @method hlm_augment lme 63 | #' @aliases hlm_augment 64 | hlm_augment.lme <- function(object, level = 1, include.ls = TRUE, ...) { 65 | residuals <- hlm_resid(object, level = level, include.ls = include.ls) 66 | infl <- hlm_influence(object, level = level) 67 | 68 | #getting correct model frame, without extra variables 69 | fixed <- as.character(formula(object)) 70 | dataform <- paste(fixed[2], fixed[1], fixed[3], " + ", 71 | paste(names(object$groups), collapse = " + ")) 72 | data <- object$data %>% 73 | dplyr::mutate(across(where(is.character), ~ as.factor(.x))) %>% 74 | as.data.frame() 75 | newdata <- model.frame(formula(dataform), data) 76 | 77 | if (level == 1) { 78 | infl <- infl[,-c(1:(1+ncol(newdata)))] 79 | } 80 | else { 81 | infl <- infl[,-1] 82 | } 83 | aug.tibble <- tibble::add_column(residuals, infl) 84 | return(aug.tibble) 85 | } 86 | -------------------------------------------------------------------------------- /R/identification.R: -------------------------------------------------------------------------------- 1 | # Identifying unusual points 2 | # 3 | # This function will identify the unusual points found when 4 | # looking at the plot comparing the shrinkage estimates and 5 | # the random coefficients found through OLS. 6 | # 7 | # @param formula a formula that can be used with \code{lm()} 8 | # @param identify the percentage of points to identify as unusual 9 | # @author Adam Loy \email{loyad01@@gmail.com} 10 | identify_resid <- function(eb, ols, identify){ 11 | # model <- lm(formula = formula) 12 | yhat <- eb 13 | # attr(yhat, "names") <- rownames(eb) 14 | res <- ols - yhat 15 | # res <- resid(model) 16 | res <- res[order(abs(res), decreasing = TRUE)] 17 | unusual <- rep(FALSE, length(res)) 18 | n <- round(length(res) * identify) 19 | unusual[1:n] <- TRUE 20 | return(data.frame(ids = names(res), residual = res, unusual = unusual)) 21 | } 22 | -------------------------------------------------------------------------------- /R/pull_resid.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | pull_resid <- function(object, ...){ 3 | UseMethod("pull_resid", object) 4 | } 5 | 6 | #' @export 7 | #' @rdname pull_resid.lmerMod 8 | #' @method pull_resid default 9 | pull_resid.default <- function(object, ...){ 10 | stop(paste("there is no pull_resid() method for objects of class", 11 | paste(class(object), collapse=", "))) 12 | } 13 | 14 | #' Computationally Efficient HLM Residuals 15 | #' 16 | #' \code{pull_resid} takes a hierarchical linear model fit as a \code{lmerMod} 17 | #' or \code{lme} object and returns various types of level-1 residuals as a 18 | #' vector. Because the \code{pull_resid} only calculates one type of residual, 19 | #' it is more efficient than using \code{\link{hlm_resid}} and indexing the 20 | #' resulting tibble. \code{pull_resid} is designed to be used with methods that 21 | #' take a long time to run, such as the resampling methods found in the 22 | #' \code{lmeresampler} package. 23 | #' @param object an object of class \code{lmerMod} or \code{lme}. 24 | #' @param type which residuals should be returned. Can be either 'ls', 'eb', or 25 | #' 'marginal' 26 | #' @param standardize a logical indicating if residuals should be standardized 27 | #' @param ... not in use 28 | #' @details \describe{ 29 | #' \item{\code{type = "ls"}}{Residuals calculated by fitting separate LS 30 | #' regression models for each group. LS residuals are unconfounded by higher 31 | #' level residuals, but unreliable for small within-group sample sizes. When 32 | #' \code{standardize = TRUE}, residuals are standardized by sigma components of 33 | #' the model object.} 34 | #' \item{\code{type = "eb"}}{Residuals calculated using the empirical Bayes (EB) 35 | #' method using maximum likelihood. EB residuals are interrelated with higher 36 | #' level residuals. When \code{standardize = TRUE}, residuals are standardized 37 | #' by sigma components of the model object.} 38 | #' \item{\code{type = "marginal"}}{Marginal residuals only consider the fixed 39 | #' effect portion of the estimates. When \code{standardize = TRUE}, Cholesky 40 | #' residuals are returned.} 41 | #' } 42 | #' @seealso \link[HLMdiag]{hlm_resid} 43 | #' 44 | #' @export 45 | #' @method pull_resid lmerMod 46 | #' @aliases pull_resid 47 | 48 | pull_resid.lmerMod <- function(object, type = "ls", standardize = FALSE, ...) { 49 | 50 | if(!is.null(standardize) && !standardize %in% c(TRUE, FALSE)) { 51 | stop("standardize can only be specified to be TRUE or FALSE.") 52 | } 53 | if(!type %in% c("ls", "eb", "marginal")) { 54 | stop("type must be either 'ls', 'eb', or 'marginal'.") 55 | } 56 | 57 | if(type == "ls") { 58 | ls.resid <- LSresids(object, level = 1, standardize = standardize) 59 | ls.resid <- ls.resid[order(as.numeric(rownames(ls.resid))),] 60 | 61 | return(ls.resid[,1]) 62 | } 63 | 64 | if(type == "eb") { 65 | if (standardize == TRUE) { 66 | eb.resid <- data.frame(.std.resid = resid(object, scale = TRUE)) 67 | } else { 68 | eb.resid <- data.frame(.resid = resid(object)) 69 | } 70 | return(eb.resid[,1]) 71 | } 72 | 73 | if(type == "marginal") { 74 | mr <- object@resp$y - lme4::getME(object, "X") %*% lme4::fixef(object) 75 | if (standardize == TRUE) { 76 | sig0 <- lme4::getME(object, "sigma") 77 | ZDZt <- sig0^2 * crossprod( lme4::getME(object, "A") ) 78 | n <- nrow(ZDZt) 79 | R <- Diagonal( n = n, x = sig0^2 ) 80 | V <- R + ZDZt 81 | V.chol <- chol( V ) 82 | 83 | Lt <- solve(t(V.chol)) 84 | mar.resid <- data.frame(.chol.mar.resid = (Lt %*% mr)[,1]) 85 | 86 | } else { 87 | mar.resid <- data.frame(.mar.resid = mr[,1]) 88 | } 89 | return(mar.resid[,1]) 90 | } 91 | } 92 | 93 | 94 | #' @export 95 | #' @rdname pull_resid.lmerMod 96 | #' @method pull_resid lme 97 | pull_resid.lme <- function(object, type = "ls", standardize = FALSE, ...) { 98 | 99 | if(!is.null(standardize) && !standardize %in% c(TRUE, FALSE)) { 100 | stop("standardize can only be specified to be TRUE or FALSE.") 101 | } 102 | if(!type %in% c("ls", "eb", "marginal")) { 103 | stop("type must be either 'ls', 'eb', or 'marginal'.") 104 | } 105 | 106 | if(type == "ls") { 107 | ls.resid <- LSresids(object, level = 1, standardize = standardize) 108 | ls.resid <- ls.resid[order(as.numeric(rownames(ls.resid))),] 109 | 110 | return(ls.resid[,1]) 111 | } 112 | 113 | if(type == "eb") { 114 | if(standardize == TRUE) { 115 | eb.resid <- data.frame(.std.resid = resid(object, type = "normalized")) 116 | } else { 117 | eb.resid <- data.frame(.resid = resid(object, type = "response")) 118 | } 119 | return(eb.resid[,1]) 120 | } 121 | 122 | if(type == "marginal") { 123 | mr <- resid(object, type="response", level=0) 124 | if (standardize == TRUE) { 125 | V <- extract_design(object)$V 126 | V.chol <- chol( V ) 127 | 128 | Lt <- solve(t(V.chol)) 129 | mar.resid <- data.frame(.chol.mar.resid = (Lt %*% mr)[,1]) 130 | 131 | } else { 132 | mar.resid <- data.frame(.mar.resid = mr) 133 | } 134 | return(mar.resid[,1]) 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /R/radon.R: -------------------------------------------------------------------------------- 1 | #' Radon data 2 | #' 3 | #' Radon measurements of 919 owner-occupied homes in 85 counties of Minnesota. 4 | #' 5 | #' @usage data(radon) 6 | #' @docType data 7 | #' @name radon 8 | #' @keywords datasets 9 | #' @format A data frame with 919 observations on the following 5 variables: 10 | #' \describe{ 11 | #' \item{log.radon}{Radon measurement (in log pCi/L, i.e., log picoCurie per liter)} 12 | #' \item{basement}{Indicator for the level of the home at which the radon measurement 13 | #' was taken - 0 = basement, 1 = first floor.} 14 | #' \item{uranium}{Average county-level soil uranium content.} 15 | #' \item{county}{County ID.} 16 | #' \item{county.name}{County name - a factor.} 17 | #' } 18 | #' @references 19 | #' Price, P. N., Nero, A. V. and Gelman, A. (1996) Bayesian prediction of mean 20 | #' indoor radon concentrations for Minnesota counties. \emph{Health Physics}. 21 | #' \bold{71}(6), 922--936. 22 | #' 23 | #' Gelman, A. and Hill, J. (2007) \emph{Data analysis using regression and 24 | #' multilevel/hierarchical models}. Cambridge University Press. 25 | NULL -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: 3 | md_document: 4 | variant: gfm 5 | html_preview: false 6 | --- 7 | 8 | # HLMdiag 9 | ```{r setup, echo = FALSE} 10 | knitr::opts_chunk$set( 11 | collapse = TRUE, 12 | comment = "#>", 13 | fig.path = "man/figures/README-" 14 | ) 15 | ``` 16 | [![R build status](https://github.com/aloy/HLMdiag/workflows/R-CMD-check/badge.svg)](https://github.com/aloy/HLMdiag/actions) 17 | [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/HLMdiag)](https://cran.r-project.org/package=HLMdiag) 18 | ![CRAN_Downloads_Badge](http://cranlogs.r-pkg.org/badges/HLMdiag) 19 | 20 | The package `HLMdiag` was created in order to provide a unified framework for analysts to diagnose hierarchical linear models (HLMs). When `HLMdiag` was created in 2014, it made diagnostic procedures available for HLMs that had not yet been implemented in statistical software. Over the past 6 years, other packages have gradually implemented some of these procedures; however, diagnosing a model still often requires multiple packages, each of which has its own syntax and quirks. `HLMdiag` provides diagnostic tools targeting all aspects and levels of hierarchical linear models in a single package. `HLMdiag` provides wrapper functions to all types of residuals implemented in `lme4` and `nlme` as well as providing access to the marginal and least squares residuals. For influence diagnostics, `HLMdiag` provides functions to calculate Cook's distance, MDFFITS, covariance trace and ratio, relative variance change, and leverage. 21 | 22 | ## Installation 23 | 24 | If you would like to install the development version of `HLMdiag`, you may do so using `devtools`: 25 | ```{r, eval = FALSE} 26 | #install.packages("devtools") 27 | library(devtools) 28 | devtools::install_github("aloy/HLMdiag") 29 | ``` 30 | 31 | To instead download the stable CRAN version instead, use: 32 | ```{r, eval = FALSE} 33 | install.packages("HLMdiag") 34 | ``` 35 | 36 | ## Details 37 | 38 | The functions provided by this package can be separated into three groups: residual analysis, influence analysis, and graphical tools. 39 | 40 | ## Residual Analysis 41 | The residual functions in `HLMdiag` allow the analyst to estimate all types of residuals defined for a hierarchical linear model. They provide access to level-1, higher-level, and marginal residuals and use both Least Squares and Empirical Bayes estimation methods to provide the analyst with more choices in evaluating a model. The `hlm_resid` method is inspired by the `augment()` function in `broom` and appends all types of residuals and fitted values for a given level to the model frame; however, individual types of residuals can be calculated with the `pull_resid` method. 42 | 43 | The functions available for residual analysis in `HLMdiag` are: 44 | *`hlm_resid()` calculates all residual diagnostics for a given level, returning a tibble with the residuals and fitted values appended to the original model frame. 45 | 46 | *`pull_resid()` calculates a specified type of residual, returning a vector and prioritizing computational efficiency. 47 | 48 | *`hlm_augment()` combines `hlm_influence()` and `hlm_resid()` to return a tibble with residual values and influence diagnostics appended to the original model frame. 49 | 50 | ### Influence Analysis 51 | The influence analysis functions provide functionality to calculate Cook's distance, MDFFITS, covariance ratio, covariance trace, relative variance change, and leverage. Additionally, two functions to calculate Cook's distance, MDFFITS, covariance ratio, and covariance trace are provided: a one step approximation, and a full refit method that refits the model and recalculates the fixed and random effects. This functionality is available through individual functions for each diagnostic; however, the `hlm_influence` function can be used to calculate all available diagnostics for each observation or group of observations. 52 | 53 | The functions available for influence analysis in `HLMdiag` are: 54 | 55 | * `cooks.distance()` calculates Cook's distance values, which measures the difference between the original fixed effects and the deleted ones. 56 | * `mdffits()` calculates MDFFITS, a multivariate version of the DFFITS statistic, which is also a measure of the difference in fixed effects. 57 | * `covtrace()` calculates covariance trace, the ratio between the covariance matrices with and without unit *i* to the identity matrix. 58 | * `covratio()` calculate covariance ratio, a comparison of the two covariance matrices with and without unit *i* using their determinants. 59 | * `rvc()` calculates relative variance change, a measurement of the ratio of estimates of the *l* th variance component with and without unit *i*. 60 | * `leverage()` calculates leverage, he rate of change in the predicted response with respect to the observed response. 61 | * `case_delete()` iteratively deletes observations or groups of observations, returning a list of fixed and random components from the original model and the models created by deletion. 62 | * `hlm_influence()` calculates all of the influence diagnostics, returning a tibble with the influence values appended to the original model frame. 63 | * `hlm_augment()` combines `hlm_influence()` and `hlm_resid()` to return a tibble with residual values and influence diagnostics appended to the original model frame. 64 | 65 | ### Graphical Tools 66 | 67 | `HLMdiag` provides the function `dotplot_diag()`, which creates dotplots to visually represent influence diagnostics. It is especially useful when used with the values returned by `hlm_influence()`. `HLMdiag` also provides grouped Q-Q plots (`group_qqnorm()`), and Q-Q plots that combine the functionality of qqnorm and qqline (`ggplot_qqnorm()`). 68 | 69 | ## Usage 70 | 71 | ### Residual Analysis 72 | We will use the `sleepstudy` data set from the `lme4` package. 73 | ```{r} 74 | library(lme4) 75 | library(HLMdiag) 76 | data(sleepstudy, package = "lme4") 77 | sleep.lmer <- lme4::lmer(Reaction ~ Days + (Days|Subject), data = sleepstudy) 78 | ``` 79 | 80 | We calculate the unstandardized level-1 and marginal residuals for each observation below. 81 | ```{r} 82 | hlm_resid(sleep.lmer) 83 | ``` 84 | 85 | For more information and examples of the functionality of `hlm_resid()`, see the residual diagnostics vignette. 86 | 87 | ### Influence Analysis 88 | We calculate influence diagnostics for each observation with the following line: 89 | ```{r} 90 | hlm_influence(sleep.lmer) 91 | ``` 92 | 93 | For more information and examples of the functionality of `hlm_influence()`, see the influence diagnostics vignette. 94 | 95 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/_pkgdown.yml -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Resubmission 2 | 3 | This is a resubmission. In this version I have: 4 | 5 | * Fixed the CITATION file and Rd \links{} for proper format. 6 | * Dropped the C++11 specification 7 | 8 | 9 | ## Test environments 10 | 11 | * local OS X install, R 4.5.0 12 | * winbuilder test environments: release and R-devel 13 | * rhub test environments: clang16, intel, ubuntu-next, ubuntu-release, linux (R-devel), 14 | m1-san (R-devel), maxos-arm64 (R-devel), macos (R-devel), windows (R-devel) 15 | 16 | 17 | ## R CMD check results 18 | 19 | 0 errors | 0 warnings | 0 notes 20 | 21 | 22 | ## revdepcheck results 23 | 24 | We checked 4 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 25 | 26 | * We saw 0 new problems 27 | * We failed to check 0 packages -------------------------------------------------------------------------------- /data/ahd.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/data/ahd.RData -------------------------------------------------------------------------------- /data/autism.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/data/autism.RData -------------------------------------------------------------------------------- /data/radon.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/data/radon.RData -------------------------------------------------------------------------------- /data/wages.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/data/wages.RData -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Page not found (404) • HLMdiag 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 | 128 | 129 | 130 | 131 |
132 | 133 |
134 |
135 | 138 | 139 | Content not found. Please use links in the navbar. 140 | 141 |
142 | 143 | 148 | 149 |
150 | 151 | 152 | 153 |
154 | 157 | 158 |
159 |

Site built with pkgdown 1.6.1.

160 |
161 | 162 |
163 |
164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /docs/articles/hlm_resid_files/figure-html/unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/hlm_resid_files/figure-html/unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /docs/articles/hlm_resid_files/figure-html/unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/hlm_resid_files/figure-html/unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /docs/articles/hlm_resid_files/figure-html/unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/hlm_resid_files/figure-html/unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /docs/articles/hlm_resid_files/figure-html/unnamed-chunk-20-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/hlm_resid_files/figure-html/unnamed-chunk-20-1.png -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Articles • HLMdiag 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 | 128 | 129 | 130 | 131 |
132 | 133 |
134 |
135 | 138 | 139 |
140 |

All vignettes

141 |

142 | 143 |
144 |
Residual Diagnostics
145 |
146 |
Influence Diagnostics
147 |
148 |
Updated JSS code
149 |
150 |
151 |
152 |
153 |
154 | 155 | 156 |
157 | 160 | 161 |
162 |

Site built with pkgdown 1.6.1.

163 |
164 | 165 |
166 |
167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-20-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-20-1.png -------------------------------------------------------------------------------- /docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-40-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-40-1.png -------------------------------------------------------------------------------- /docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-43-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-43-1.png -------------------------------------------------------------------------------- /docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/articles/influence_diagnostics_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Citation and Authors • HLMdiag 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 | 128 | 129 | 130 | 131 |
132 | 133 |
134 |
135 | 139 | 140 |

Adam Loy, Heike Hofmann (2014). HLMdiag: A Suite of Diagnostics for Hierarchical Linear Models in R. Journal of Statistical Software, 56(5), 1-28. URL https://www.jstatsoft.org/article/view/v056i05.

141 |
@Article{,
142 |   title = {{HLMdiag}: A Suite of Diagnostics for Hierarchical Linear Models in {R}},
143 |   author = {Adam Loy and Heike Hofmann},
144 |   journal = {Journal of Statistical Software},
145 |   year = {2014},
146 |   volume = {56},
147 |   number = {5},
148 |   pages = {1--28},
149 |   url = {https://www.jstatsoft.org/article/view/v056i05},
150 | }
151 | 152 | 155 | 156 |
    157 |
  • 158 |

    Adam Loy. Maintainer, author. 159 |

    160 |
  • 161 |
  • 162 |

    Jaylin Lowe. Author. 163 |

    164 |
  • 165 |
  • 166 |

    Jack Moran. Author. 167 |

    168 |
  • 169 |
170 | 171 |
172 | 173 |
174 | 175 | 176 | 177 |
178 | 181 | 182 |
183 |

Site built with pkgdown 1.6.1.

184 |
185 | 186 |
187 |
188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | -------------------------------------------------------------------------------- /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/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | img { 60 | max-width: 100%; 61 | } 62 | 63 | /* Fix bug in bootstrap (only seen in firefox) */ 64 | summary { 65 | display: list-item; 66 | } 67 | 68 | /* Typographic tweaking ---------------------------------*/ 69 | 70 | .contents .page-header { 71 | margin-top: calc(-60px + 1em); 72 | } 73 | 74 | dd { 75 | margin-left: 3em; 76 | } 77 | 78 | /* Section anchors ---------------------------------*/ 79 | 80 | a.anchor { 81 | margin-left: -30px; 82 | display:inline-block; 83 | width: 30px; 84 | height: 30px; 85 | visibility: hidden; 86 | 87 | background-image: url(./link.svg); 88 | background-repeat: no-repeat; 89 | background-size: 20px 20px; 90 | background-position: center center; 91 | } 92 | 93 | .hasAnchor:hover a.anchor { 94 | visibility: visible; 95 | } 96 | 97 | @media (max-width: 767px) { 98 | .hasAnchor:hover a.anchor { 99 | visibility: hidden; 100 | } 101 | } 102 | 103 | 104 | /* Fixes for fixed navbar --------------------------*/ 105 | 106 | .contents h1, .contents h2, .contents h3, .contents h4 { 107 | padding-top: 60px; 108 | margin-top: -40px; 109 | } 110 | 111 | /* Navbar submenu --------------------------*/ 112 | 113 | .dropdown-submenu { 114 | position: relative; 115 | } 116 | 117 | .dropdown-submenu>.dropdown-menu { 118 | top: 0; 119 | left: 100%; 120 | margin-top: -6px; 121 | margin-left: -1px; 122 | border-radius: 0 6px 6px 6px; 123 | } 124 | 125 | .dropdown-submenu:hover>.dropdown-menu { 126 | display: block; 127 | } 128 | 129 | .dropdown-submenu>a:after { 130 | display: block; 131 | content: " "; 132 | float: right; 133 | width: 0; 134 | height: 0; 135 | border-color: transparent; 136 | border-style: solid; 137 | border-width: 5px 0 5px 5px; 138 | border-left-color: #cccccc; 139 | margin-top: 5px; 140 | margin-right: -10px; 141 | } 142 | 143 | .dropdown-submenu:hover>a:after { 144 | border-left-color: #ffffff; 145 | } 146 | 147 | .dropdown-submenu.pull-left { 148 | float: none; 149 | } 150 | 151 | .dropdown-submenu.pull-left>.dropdown-menu { 152 | left: -100%; 153 | margin-left: 10px; 154 | border-radius: 6px 0 6px 6px; 155 | } 156 | 157 | /* Sidebar --------------------------*/ 158 | 159 | #pkgdown-sidebar { 160 | margin-top: 30px; 161 | position: -webkit-sticky; 162 | position: sticky; 163 | top: 70px; 164 | } 165 | 166 | #pkgdown-sidebar h2 { 167 | font-size: 1.5em; 168 | margin-top: 1em; 169 | } 170 | 171 | #pkgdown-sidebar h2:first-child { 172 | margin-top: 0; 173 | } 174 | 175 | #pkgdown-sidebar .list-unstyled li { 176 | margin-bottom: 0.5em; 177 | } 178 | 179 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 180 | 181 | /* All levels of nav */ 182 | 183 | nav[data-toggle='toc'] .nav > li > a { 184 | padding: 4px 20px 4px 6px; 185 | font-size: 1.5rem; 186 | font-weight: 400; 187 | color: inherit; 188 | } 189 | 190 | nav[data-toggle='toc'] .nav > li > a:hover, 191 | nav[data-toggle='toc'] .nav > li > a:focus { 192 | padding-left: 5px; 193 | color: inherit; 194 | border-left: 1px solid #878787; 195 | } 196 | 197 | nav[data-toggle='toc'] .nav > .active > a, 198 | nav[data-toggle='toc'] .nav > .active:hover > a, 199 | nav[data-toggle='toc'] .nav > .active:focus > a { 200 | padding-left: 5px; 201 | font-size: 1.5rem; 202 | font-weight: 400; 203 | color: inherit; 204 | border-left: 2px solid #878787; 205 | } 206 | 207 | /* Nav: second level (shown on .active) */ 208 | 209 | nav[data-toggle='toc'] .nav .nav { 210 | display: none; /* Hide by default, but at >768px, show it */ 211 | padding-bottom: 10px; 212 | } 213 | 214 | nav[data-toggle='toc'] .nav .nav > li > a { 215 | padding-left: 16px; 216 | font-size: 1.35rem; 217 | } 218 | 219 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 220 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 221 | padding-left: 15px; 222 | } 223 | 224 | nav[data-toggle='toc'] .nav .nav > .active > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 226 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 227 | padding-left: 15px; 228 | font-weight: 500; 229 | font-size: 1.35rem; 230 | } 231 | 232 | /* orcid ------------------------------------------------------------------- */ 233 | 234 | .orcid { 235 | font-size: 16px; 236 | color: #A6CE39; 237 | /* margins are required by official ORCID trademark and display guidelines */ 238 | margin-left:4px; 239 | margin-right:4px; 240 | vertical-align: middle; 241 | } 242 | 243 | /* Reference index & topics ----------------------------------------------- */ 244 | 245 | .ref-index th {font-weight: normal;} 246 | 247 | .ref-index td {vertical-align: top; min-width: 100px} 248 | .ref-index .icon {width: 40px;} 249 | .ref-index .alias {width: 40%;} 250 | .ref-index-icons .alias {width: calc(40% - 40px);} 251 | .ref-index .title {width: 60%;} 252 | 253 | .ref-arguments th {text-align: right; padding-right: 10px;} 254 | .ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} 255 | .ref-arguments .name {width: 20%;} 256 | .ref-arguments .desc {width: 80%;} 257 | 258 | /* Nice scrolling for wide elements --------------------------------------- */ 259 | 260 | table { 261 | display: block; 262 | overflow: auto; 263 | } 264 | 265 | /* Syntax highlighting ---------------------------------------------------- */ 266 | 267 | pre { 268 | word-wrap: normal; 269 | word-break: normal; 270 | border: 1px solid #eee; 271 | } 272 | 273 | pre, code { 274 | background-color: #f8f8f8; 275 | color: #333; 276 | } 277 | 278 | pre code { 279 | overflow: auto; 280 | word-wrap: normal; 281 | white-space: pre; 282 | } 283 | 284 | pre .img { 285 | margin: 5px 0; 286 | } 287 | 288 | pre .img img { 289 | background-color: #fff; 290 | display: block; 291 | height: auto; 292 | } 293 | 294 | code a, pre a { 295 | color: #375f84; 296 | } 297 | 298 | a.sourceLine:hover { 299 | text-decoration: none; 300 | } 301 | 302 | .fl {color: #1514b5;} 303 | .fu {color: #000000;} /* function */ 304 | .ch,.st {color: #036a07;} /* string */ 305 | .kw {color: #264D66;} /* keyword */ 306 | .co {color: #888888;} /* comment */ 307 | 308 | .message { color: black; font-weight: bolder;} 309 | .error { color: orange; font-weight: bolder;} 310 | .warning { color: #6A0366; font-weight: bolder;} 311 | 312 | /* Clipboard --------------------------*/ 313 | 314 | .hasCopyButton { 315 | position: relative; 316 | } 317 | 318 | .btn-copy-ex { 319 | position: absolute; 320 | right: 0; 321 | top: 0; 322 | visibility: hidden; 323 | } 324 | 325 | .hasCopyButton:hover button.btn-copy-ex { 326 | visibility: visible; 327 | } 328 | 329 | /* headroom.js ------------------------ */ 330 | 331 | .headroom { 332 | will-change: transform; 333 | transition: transform 200ms linear; 334 | } 335 | .headroom--pinned { 336 | transform: translateY(0%); 337 | } 338 | .headroom--unpinned { 339 | transform: translateY(-100%); 340 | } 341 | 342 | /* mark.js ----------------------------*/ 343 | 344 | mark { 345 | background-color: rgba(255, 255, 51, 0.5); 346 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 347 | padding: 1px; 348 | } 349 | 350 | /* vertical spacing after htmlwidgets */ 351 | .html-widget { 352 | margin-bottom: 10px; 353 | } 354 | 355 | /* fontawesome ------------------------ */ 356 | 357 | .fab { 358 | font-family: "Font Awesome 5 Brands" !important; 359 | } 360 | 361 | /* don't display links in code chunks when printing */ 362 | /* source: https://stackoverflow.com/a/10781533 */ 363 | @media print { 364 | code a:link:after, code a:visited:after { 365 | content: ""; 366 | } 367 | } 368 | -------------------------------------------------------------------------------- /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.2 2 | pkgdown: 1.6.1 3 | pkgdown_sha: ~ 4 | articles: 5 | hlm_resid: hlm_resid.html 6 | influence_diagnostics: influence_diagnostics.html 7 | jss_update: jss_update.html 8 | last_built: 2021-05-01T19:22Z 9 | 10 | -------------------------------------------------------------------------------- /docs/reference/compare_eb_ls-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/reference/compare_eb_ls-1.png -------------------------------------------------------------------------------- /docs/reference/compare_eb_ls-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/reference/compare_eb_ls-2.png -------------------------------------------------------------------------------- /docs/reference/dotplot_diag-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/reference/dotplot_diag-1.png -------------------------------------------------------------------------------- /docs/reference/dotplot_diag-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/reference/dotplot_diag-2.png -------------------------------------------------------------------------------- /docs/reference/dotplot_diag-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/reference/dotplot_diag-3.png -------------------------------------------------------------------------------- /docs/reference/dotplot_diag-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/docs/reference/dotplot_diag-4.png -------------------------------------------------------------------------------- /docs/reference/radon.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Radon data — radon • HLMdiag 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 | 129 | 130 | 131 | 132 |
    133 | 134 |
    135 |
    136 | 141 | 142 |
    143 |

    Radon measurements of 919 owner-occupied homes in 85 counties of Minnesota.

    144 |
    145 | 146 |
    data(radon)
    147 | 148 | 149 |

    Format

    150 | 151 |

    A data frame with 919 observations on the following 5 variables:

    152 |
    log.radon

    Radon measurement (in log pCi/L, i.e., log picoCurie per liter)

    153 |
    basement

    Indicator for the level of the home at which the radon measurement 154 | was taken - 0 = basement, 1 = first floor.

    155 |
    uranium

    Average county-level soil uranium content.

    156 |
    county

    County ID.

    157 |
    county.name

    County name - a factor.

    158 | 159 |
    160 | 161 |

    Source

    162 | 163 |

    http://www.stat.columbia.edu/~gelman/arm/software/

    164 |

    References

    165 | 166 |

    Price, P. N., Nero, A. V. and Gelman, A. (1996) Bayesian prediction of mean 167 | indoor radon concentrations for Minnesota counties. Health Physics. 168 | 71(6), 922--936.

    169 |

    Gelman, A. and Hill, J. (2007) Data analysis using regression and 170 | multilevel/hierarchical models. Cambridge University Press.

    171 | 172 |
    173 | 178 |
    179 | 180 | 181 |
    182 | 185 | 186 |
    187 |

    Site built with pkgdown 1.6.1.

    188 |
    189 | 190 |
    191 |
    192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry( 2 | bibtype = "Article", 3 | title = "HLMdiag: A Suite of Diagnostics for Hierarchical Linear Models in R ", 4 | author = "Adam Loy, Heike Hofmann", 5 | journal = "Journal of Statistical Software", 6 | year = "2014", 7 | volume = "56", 8 | number = "5", 9 | pages = "1--28", 10 | doi = "10.18637/jss.v056.i05" 11 | ) 12 | -------------------------------------------------------------------------------- /inst/image/HLMdiag_hex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/inst/image/HLMdiag_hex.png -------------------------------------------------------------------------------- /man/HLMdiag-defunct.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/HLMdiag-defunct.R 3 | \name{HLMdiag-defunct} 4 | \alias{HLMdiag-defunct} 5 | \alias{HLMresid} 6 | \alias{HLMresid.default} 7 | \alias{HLMresid.lmerMod} 8 | \alias{HLMresid.mer} 9 | \alias{diagnostics} 10 | \alias{group_qqnorm} 11 | \alias{ggplot_qqnorm} 12 | \title{Defunct functions in package HLMdiag} 13 | \usage{ 14 | HLMresid(...) 15 | 16 | HLMresid.default(...) 17 | 18 | HLMresid.lmerMod(...) 19 | 20 | HLMresid.mer(...) 21 | 22 | diagnostics(...) 23 | 24 | group_qqnorm(...) 25 | 26 | ggplot_qqnorm(...) 27 | } 28 | \arguments{ 29 | \item{...}{arguments passed to defunct functions} 30 | } 31 | \description{ 32 | These functions are defunct and no longer available. 33 | } 34 | \details{ 35 | \code{HLMresid} is replaced by \code{\link{hlm_resid}} 36 | 37 | \code{diagnostics} is replaced by \code{\link{hlm_influence}} 38 | 39 | \code{group_qqnorm} and \code{group_qqnorm} are replaced by functions in \pkg{qqplotr}. 40 | See \code{\link[qqplotr]{stat_qq_point}}, \code{\link[qqplotr]{stat_qq_line}}, and 41 | \code{\link[qqplotr]{stat_qq_band}}. 42 | } 43 | -------------------------------------------------------------------------------- /man/HLMdiag-deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/HLMdiag-deprecated.R 3 | \name{HLMdiag-deprecated} 4 | \alias{HLMdiag-deprecated} 5 | \title{Deprecated functions in HLMdiag} 6 | \description{ 7 | These functions still work but will be removed (defunct) in the next version. 8 | } 9 | \details{ 10 | \itemize{ 11 | \item \code{\link{HLMresid}}: This function is deprecated, and will 12 | be removed in the next version of this package. 13 | \item \code{\link{diagnostics}}: This function is deprecated, and will 14 | be removed in the next version of this package. 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /man/HLMdiag.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/help.R 3 | \docType{package} 4 | \name{HLMdiag} 5 | \alias{HLMdiag-package} 6 | \alias{HLMdiag} 7 | \alias{package-HLMdiag} 8 | \title{Diagnostic tools for hierarchical (multilevel) linear models} 9 | \description{ 10 | HLMdiag provides a suite of diagnostic tools for hierarchical 11 | (multilevel) linear models fit using the \code{lme4} or \code{nlme} 12 | packages. These tools are grouped below by purpose. 13 | See the help documentation for additional information 14 | about each function. 15 | } 16 | \details{ 17 | \bold{Residual analysis} 18 | 19 | HLMdiag's \code{\link{hlm_resid}} function provides a wrapper that 20 | extracts residuals and fitted values for individual observations 21 | or groups of observations. In addition to being a wrapper function for functions 22 | implemented in the \code{lme4} and \code{nlme} packages, 23 | \code{\link{hlm_resid}} provides access to the marginal and least squares 24 | residuals. 25 | 26 | \bold{Influence analysis} 27 | 28 | HLMdiag's \code{\link{hlm_influence}} function provides a convenient wrapper 29 | to obtain influence diagnostics for each observation or group of observations 30 | appended to the data used to fit the model. The diagnostics returned by 31 | \code{\link{hlm_influence}} include Cook's distance, MDFFITS, covariance trace (covtrace), 32 | covariance ratio (covratio), leverage, and relative variance change (RVC). 33 | HLMdiag also contains functions to calculate these diagnostics individually, as discussed below. 34 | 35 | Influence on fitted values 36 | 37 | HLMdiag provides \code{\link{leverage}} that calculates the influence 38 | that observations/groups have on the fitted values (leverage). 39 | For mixed/hierarchical models leverage can be decomposed into two parts: the 40 | fixed part and the random part. We refer the user to the references 41 | cited in the help documentation for additional explanation. 42 | 43 | Influence on fixed effects estimates 44 | 45 | HLMdiag provides \code{\link{cooks.distance}} and \code{\link{mdffits}} 46 | to assess the influence of subsets of observations on the fixed effects. 47 | 48 | Influence on precision of fixed effects 49 | 50 | HLMdiag provides \code{\link{covratio}} and \code{\link{covtrace}} 51 | to assess the influence of subsets of observations on the precision of 52 | the fixed effects. 53 | 54 | Influence on variance components 55 | 56 | HLMdiag's \code{\link{rvc}} calculates the relative variance change to 57 | assess the influence of subsets of observations on the variance 58 | components. 59 | 60 | \bold{Graphics} 61 | 62 | HLMdiag also strives to make graphical assessment easier in the 63 | \code{ggplot2} framework by providing dotplots for influence diagnostics 64 | (\code{\link{dotplot_diag}}), grouped Q-Q plots (\code{\link{group_qqnorm}}), 65 | and Q-Q plots that combine the functionality of \code{\link{qqnorm}} and 66 | \code{\link{qqline}} (\code{\link{ggplot_qqnorm}}). 67 | } 68 | \seealso{ 69 | Useful links: 70 | \itemize{ 71 | \item \url{https://github.com/aloy/HLMdiag} 72 | \item Report bugs at \url{https://github.com/aloy/HLMdiag/issues} 73 | } 74 | 75 | } 76 | \author{ 77 | \strong{Maintainer}: Adam Loy \email{loyad01@gmail.com} 78 | 79 | Authors: 80 | \itemize{ 81 | \item Jaylin Lowe 82 | \item Jack Moran 83 | } 84 | 85 | } 86 | \keyword{package} 87 | -------------------------------------------------------------------------------- /man/LSresids.mer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LSresids.R 3 | \name{LSresids.default} 4 | \alias{LSresids.default} 5 | \alias{LSresids.mer} 6 | \alias{LSresids} 7 | \alias{LSresids.lmerMod} 8 | \alias{LSresids.lme} 9 | \title{Calculating least squares residuals} 10 | \usage{ 11 | \method{LSresids}{default}(object, ...) 12 | 13 | \method{LSresids}{mer}(object, level, sim = NULL, standardize = FALSE, ...) 14 | 15 | \method{LSresids}{lmerMod}(object, level, standardize = FALSE, ...) 16 | 17 | \method{LSresids}{lme}(object, level, standardize = FALSE, ...) 18 | } 19 | \arguments{ 20 | \item{object}{an object of class \code{mer} or \code{lmerMod}.} 21 | 22 | \item{...}{do not use} 23 | 24 | \item{level}{which residuals should be extracted: 1 for case-level 25 | residuals or the name of a grouping factor (as defined in \code{flist} of the 26 | \code{mer} object) for between-group residuals.} 27 | 28 | \item{sim}{optional argument giving the data frame used for LS residuals. This 29 | is used mainly when dealing with simulations. Removed in version 0.3.2.} 30 | 31 | \item{standardize}{if \code{TRUE} the standardized level-1 32 | residuals will also be returned (if \code{level = 1}); if \code{"semi"} then 33 | the semi-standardized level-1 residuals will be returned.} 34 | } 35 | \description{ 36 | This function calculates least squares (LS) residuals 37 | found by fitting separate LS regression models to each case. 38 | For examples see the documentation for \code{HLMresid}. 39 | } 40 | \references{ 41 | Hilden-Minton, J. (1995) Multilevel diagnostics for mixed and hierarchical 42 | linear models. University of California Los Angeles. 43 | } 44 | \seealso{ 45 | \code{\link{HLMresid}} 46 | } 47 | \author{ 48 | Adam Loy \email{loyad01@gmail.com} 49 | } 50 | \keyword{models} 51 | \keyword{regression} 52 | -------------------------------------------------------------------------------- /man/adjust_lmList.formula.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/adjust_formula_lmList.R 3 | \name{adjust_lmList.formula} 4 | \alias{adjust_lmList.formula} 5 | \alias{adjust_lmList} 6 | \alias{adjust_lmList,formula,data.frame-method} 7 | \title{Fitting Common Models via \code{lm}} 8 | \usage{ 9 | \method{adjust_lmList}{formula}(object, data, pool) 10 | } 11 | \arguments{ 12 | \item{object}{a linear formula such as that used by \code{lmList}, e.g. 13 | \code{y ~ x1 + ... + xn | g}, where \code{g} is a grouping factor.} 14 | 15 | \item{data}{a data frame containing the variables in the model.} 16 | 17 | \item{pool}{a logical value that indicates whether the pooled standard 18 | deviation/error should be used.} 19 | } 20 | \description{ 21 | Separate linear models are fit via \code{lm} similar to \code{lmList}, 22 | however, \code{adjust_lmList} can handle models where a factor takes only one 23 | level within a group. In this case, the \code{formula} is updated eliminating 24 | the offending factors from the formula for that group as the effect is 25 | absorbed into the intercept. 26 | } 27 | \examples{ 28 | 29 | data(Exam, package = 'mlmRev') 30 | sepLM <- adjust_lmList(normexam ~ standLRT + sex + schgend | school, data = Exam) 31 | confint(sepLM) 32 | 33 | } 34 | \references{ 35 | Douglas Bates, Martin Maechler and Ben Bolker (2012). lme4: 36 | Linear mixed-effects models using S4 classes. R package version 0.999999-0. 37 | } 38 | \seealso{ 39 | \code{\link[lme4]{lmList}, \link[stats]{lm}} 40 | } 41 | \keyword{models} 42 | \keyword{regression} 43 | -------------------------------------------------------------------------------- /man/ahd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ahd.R 3 | \docType{data} 4 | \name{ahd} 5 | \alias{ahd} 6 | \title{Methylprednisolone data} 7 | \format{ 8 | A data frame with 330 observations on the following 5 variables: 9 | \describe{ 10 | \item{treatment}{The treatment a subject received - a factor. Levels are 11 | \code{placebo} and \code{treated}.} 12 | \item{subject}{Subject ID - a factor.} 13 | \item{week}{Week of the study (0--4) - the time variable.} 14 | \item{sbvalue}{Serum bilirubin level (in \eqn{\mu}mol/L). } 15 | \item{baseline}{A subject's serum bilirubin level at week 0.} 16 | } 17 | } 18 | \source{ 19 | Vonesh, E. F. and Chinchilli, V. M. (1997) \emph{Linear and Nonlinear Models for the 20 | Analysis of Repeated Measurements}. Marcel Dekker, New York. 21 | } 22 | \usage{ 23 | data(ahd) 24 | } 25 | \description{ 26 | Data from a longitudinal study examining the effectiveness of Methylprednisolone 27 | as a treatment for patients with severe alcoholic hepatitis. Subjects were 28 | randomly assigned to a treatment (31 received a placebo, 35 received the 29 | treatment) and serum bilirubin was measures each week for four weeks. 30 | } 31 | \references{ 32 | Carithers, R. L., Herlong, H. F., Diehl, A. M., Shaw, E. W., Combes, B., 33 | Fallon, H. J. & Maddrey, W. C. (1989) Methylprednisolone therapy in 34 | patients with severe alcoholic hepatitis. \emph{Annals of Internal Medicine}, 35 | \bold{110}(9), 685--690. 36 | } 37 | \keyword{datasets} 38 | -------------------------------------------------------------------------------- /man/autism.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/autism.R 3 | \docType{data} 4 | \name{autism} 5 | \alias{autism} 6 | \title{Autism data} 7 | \format{ 8 | A data frame with 604 observation on the following 7 variables: 9 | \describe{ 10 | \item{childid}{Child ID.} 11 | \item{sicdegp}{Sequenced Inventory of Communication Development group (an 12 | assessment of expressive language development) - a factor. Levels are 13 | \code{low}, \code{med}, and \code{high}.} 14 | \item{age2}{Age (in years) centered around age 2 (age at diagnosis).} 15 | \item{vsae}{Vineland Socialization Age Equivalent} 16 | \item{gender}{Child's gender - a factor. Levels are \code{male} and \code{female}.} 17 | \item{race}{Child's race - a factor. Levels are \code{white} and \code{nonwhite}.} 18 | \item{bestest2}{Diagnosis at age 2 - a factor. Levels are \code{autism} and 19 | \code{pdd} (pervasive developmental disorder).} 20 | } 21 | } 22 | \source{ 23 | \url{http://www-personal.umich.edu/~kwelch/} 24 | } 25 | \usage{ 26 | data(autism) 27 | } 28 | \description{ 29 | Data from a prospective longitudinal study following 214 children between 30 | the ages of 2 and 13 who were diagnosed with either autism spectrum disorder 31 | or non-spectrum developmental delays at age 2. 32 | } 33 | \references{ 34 | Anderson, D. K., Lord, C., Risi, S., DiLavore, P. S., Shulman, C., 35 | Thurm, A., et al. (2007). Patterns of growth in verbal abilities among 36 | children with autism spectrum disorder. \emph{Journal of Consulting and 37 | Clinical Psychology}, \bold{75}(4), 594--604. 38 | 39 | Anderson, D. K., Oti, R. S., Lord, C., & Welch, K. (2009). 40 | Patterns of Growth in Adaptive Social Abilities Among Children with Autism 41 | Spectrum Disorders. \emph{Journal of Abnormal Child Psychology}, 42 | \bold{37}(7), 1019--1034. 43 | } 44 | \keyword{datasets} 45 | -------------------------------------------------------------------------------- /man/case_delete.mer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/case_delete.R 3 | \name{case_delete.default} 4 | \alias{case_delete.default} 5 | \alias{case_delete.mer} 6 | \alias{case_delete} 7 | \alias{case_delete.lmerMod} 8 | \alias{case_delete.lme} 9 | \title{Case Deletion for \code{mer}/\code{lmerMod} objects} 10 | \usage{ 11 | \method{case_delete}{default}(model, ...) 12 | 13 | \method{case_delete}{mer}( 14 | model, 15 | level = 1, 16 | type = c("both", "fixef", "varcomp"), 17 | delete = NULL, 18 | ... 19 | ) 20 | 21 | \method{case_delete}{lmerMod}( 22 | model, 23 | level = 1, 24 | type = c("both", "fixef", "varcomp"), 25 | delete = NULL, 26 | ... 27 | ) 28 | 29 | \method{case_delete}{lme}( 30 | model, 31 | level = 1, 32 | type = c("both", "fixef", "varcomp"), 33 | delete = NULL, 34 | ... 35 | ) 36 | } 37 | \arguments{ 38 | \item{model}{the original hierarchical model fit using \code{lmer()}} 39 | 40 | \item{...}{do not use} 41 | 42 | \item{level}{a variable used to define the group for which cases will be 43 | deleted. If \code{level = 1} (default), then the function will delete 44 | individual observations.} 45 | 46 | \item{type}{the part of the model for which you are obtaining deletion 47 | diagnostics: the fixed effects (\code{"fixef"}), variance components 48 | (\code{"varcomp"}), or \code{"both"} (default).} 49 | 50 | \item{delete}{numeric index of individual cases to be deleted. If the \code{level} parameter 51 | is specified, \code{delete} may also take the form of a character vector consisting of group 52 | names as they appear in \code{flist}. It is possible to set \code{level} and delete individual 53 | cases from different groups using \code{delete}, so numeric indices should be double checked 54 | to confirm that they encompass entire groups. If \code{delete = NULL} then all cases are iteratively deleted.} 55 | } 56 | \value{ 57 | a list with the following components: 58 | \describe{ 59 | \item{\code{fixef.original}}{the original fixed effects estimates} 60 | \item{\code{ranef.original}}{the original predicted random effects} 61 | \item{\code{vcov.original}}{the original variance-covariance matrix for the fixed effects} 62 | \item{\code{varcomp.original}}{the original estimated variance components} 63 | \item{\code{fixef.delete}}{a list of the fixed effects estimated after case deletion} 64 | \item{\code{ranef.delete}}{a list of the random effects predicted after case deletion} 65 | \item{\code{vcov.delete}}{a list of the variance-covariance matrices for the fixed 66 | effects obtained after case deletion} 67 | \item{\code{fitted.delete}}{a list of the fitted values obtained after case 68 | deletion} 69 | \item{\code{varcomp.delete}}{a list of the estimated variance components obtained after 70 | case deletion} 71 | } 72 | } 73 | \description{ 74 | This function is used to iteratively delete groups corresponding to the 75 | levels of a hierarchical linear model. It uses \code{lmer()} to fit 76 | the models for each deleted case (i.e. uses brute force). To investigate 77 | numerous levels of the model, the function will need to be called multiple 78 | times, specifying the group (level) of interest each time. 79 | } 80 | \examples{ 81 | data(sleepstudy, package = 'lme4') 82 | fm <- lme4::lmer(Reaction ~ Days + (Days|Subject), sleepstudy) 83 | 84 | # Deleting every Subject 85 | fmDel <- case_delete(model = fm, level = "Subject", type = "both") 86 | 87 | # Deleting only subject 308 88 | del308 <- case_delete(model = fm, level = "Subject", type = "both", delete = 308) 89 | 90 | # Deleting a subset of subjects 91 | delSubset <- case_delete(model = fm, level = "Subject", type = "both", delete = 308:310) 92 | 93 | } 94 | \references{ 95 | Christensen, R., Pearson, L.M., and Johnson, W. (1992) 96 | Case-Deletion Diagnostics for Mixed Models, \emph{Technometrics}, \bold{34}, 38 97 | -- 45. 98 | 99 | Schabenberger, O. (2004) Mixed Model Influence Diagnostics, in 100 | \emph{Proceedings of the Twenty-Ninth SAS Users Group International 101 | Conference}, SAS Users Group International. 102 | } 103 | \author{ 104 | Adam Loy \email{loyad01@gmail.com} 105 | } 106 | \keyword{models} 107 | \keyword{regression} 108 | -------------------------------------------------------------------------------- /man/compare_eb_ls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/group_level_residual_functions.R 3 | \name{compare_eb_ls} 4 | \alias{compare_eb_ls} 5 | \title{Visually comparing shrinkage and LS estimates} 6 | \usage{ 7 | compare_eb_ls(eb, ols, identify = FALSE, silent = TRUE, ...) 8 | } 9 | \arguments{ 10 | \item{eb}{a matrix of random effects} 11 | 12 | \item{ols}{a matrix of the OLS estimates found using \code{random_ls_coef}} 13 | 14 | \item{identify}{the percentage of points to identify as unusual, 15 | \code{FALSE} if you do not want the points identified.} 16 | 17 | \item{silent}{logical: should the list of data frames used to make the plots 18 | be suppressed.} 19 | 20 | \item{...}{other arguments to be passed to \code{qplot()}} 21 | } 22 | \description{ 23 | This function creates a plot (using \code{qplot()}) where the shrinkage 24 | estimate appears on the horizontal axis and the LS estimate appears on the 25 | vertical axis. 26 | } 27 | \examples{ 28 | 29 | wages.fm1 <- lme4::lmer(lnw ~ exper + (exper | id), data = wages) 30 | wages.sepLM <- adjust_lmList(lnw ~ exper | id, data = wages) 31 | rancoef.eb <- coef(wages.fm1)$id 32 | rancoef.ols <- coef(wages.sepLM) 33 | compare_eb_ls(eb = rancoef.eb, ols = rancoef.ols, identify = 0.01) 34 | 35 | } 36 | \author{ 37 | Adam Loy \email{loyad01@gmail.com} 38 | } 39 | -------------------------------------------------------------------------------- /man/cooks.distance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/influence_functions.R 3 | \name{mdffits.default} 4 | \alias{mdffits.default} 5 | \alias{cooks.distance.mer} 6 | \alias{cooks.distance} 7 | \alias{cooks.distance.lmerMod} 8 | \alias{cooks.distance.lme} 9 | \alias{mdffits.mer} 10 | \alias{mdffits} 11 | \alias{mdffits.lmerMod} 12 | \alias{mdffits.lme} 13 | \title{Influence on fixed effects of HLMs} 14 | \usage{ 15 | \method{mdffits}{default}(model, ...) 16 | 17 | \method{cooks.distance}{mer}(model, level = 1, delete = NULL, ...) 18 | 19 | \method{cooks.distance}{lmerMod}(model, level = 1, delete = NULL, include.attr = FALSE, ...) 20 | 21 | \method{cooks.distance}{lme}(model, level = 1, delete = NULL, include.attr = FALSE, ...) 22 | 23 | \method{mdffits}{mer}(object, level = 1, delete = NULL, ...) 24 | 25 | \method{mdffits}{lmerMod}(model, level = 1, delete = NULL, include.attr = FALSE, ...) 26 | 27 | \method{mdffits}{lme}(model, level = 1, delete = NULL, include.attr = FALSE, ...) 28 | } 29 | \arguments{ 30 | \item{model}{fitted model of class \code{mer} or \code{lmerMod}} 31 | 32 | \item{...}{do not use} 33 | 34 | \item{level}{variable used to define the group for which cases will be 35 | deleted. If \code{level = 1} (default), then individual cases will be deleted.} 36 | 37 | \item{delete}{index of individual cases to be deleted. To delete specific 38 | observations the row number must be specified. To delete higher level 39 | units the group ID and \code{group} parameter must be specified. 40 | If \code{delete = NULL} then all cases are iteratively deleted.} 41 | 42 | \item{include.attr}{logical value determining whether the difference between 43 | the full and deleted parameter estimates should be included. If \code{FALSE} 44 | (default), a numeric vector of Cook's distance or MDFFITS is returned. 45 | If \code{TRUE}, a tibble with the Cook's distance or MDFFITS values in the 46 | first column and the parameter differences in the remaining columns is returned.} 47 | 48 | \item{object}{fitted object of class \code{mer} or \code{lmerMod}} 49 | } 50 | \value{ 51 | Both functions return a numeric vector (or single value if 52 | \code{delete} has been specified) as the default. If \code{include.attr = TRUE}, 53 | then a tibble is returned. The first column consists of the Cook's distance or 54 | MDFFITS values, and the later columns capture the difference between the full 55 | and deleted parameter estimates. 56 | } 57 | \description{ 58 | These functions calculate measures of the change in the fixed effects 59 | estimates based on the deletion of an observation, or group of 60 | observations, for a hierarchical linear model fit using \code{lmer}. 61 | } 62 | \details{ 63 | Both Cook's distance and MDFFITS measure the change in the 64 | fixed effects estimates based on the deletion of a subset of observations. 65 | The key difference between the two diagnostics is that Cook's distance uses 66 | the covariance matrix for the fixed effects from the original 67 | model while MDFFITS uses the covariance matrix from the deleted 68 | model. 69 | } 70 | \note{ 71 | Because MDFFITS requires the calculation of the covariance matrix 72 | for the fixed effects for every model, it will be slower. 73 | } 74 | \examples{ 75 | data(sleepstudy, package = 'lme4') 76 | ss <- lme4::lmer(Reaction ~ Days + (Days | Subject), sleepstudy) 77 | 78 | # Cook's distance for individual observations 79 | ss.cd.lev1 <- cooks.distance(ss) 80 | 81 | # Cook's distance for each Subject 82 | ss.cd.subject <- cooks.distance(ss, level = "Subject") 83 | 84 | \dontrun{ 85 | data(Exam, package = 'mlmRev') 86 | fm <- lme4::lmer(normexam ~ standLRT * schavg + (standLRT | school), Exam) 87 | 88 | # Cook's distance for individual observations 89 | cd.lev1 <- cooks.distance(fm) 90 | 91 | # Cook's distance for each school 92 | cd.school <- cooks.distance(fm, level = "school") 93 | 94 | # Cook's distance when school 1 is deleted 95 | cd.school1 <- cooks.distance(fm, level = "school", delete = 1) 96 | 97 | } 98 | 99 | 100 | # MDFFITS for individual observations 101 | ss.m1 <- mdffits(ss) 102 | 103 | # MDFFITS for each Subject 104 | ss.m.subject <- mdffits(ss, level = "Subject") 105 | 106 | \dontrun{ 107 | 108 | # MDFFITS for individual observations 109 | m1 <- mdffits(fm) 110 | 111 | # MDFFITS for each school 112 | m.school <- mdffits(fm, level = "school") 113 | } 114 | } 115 | \references{ 116 | Christensen, R., Pearson, L., & Johnson, W. (1992) 117 | Case-deletion diagnostics for mixed models. \emph{Technometrics}, \bold{34}, 118 | 38--45. 119 | 120 | Schabenberger, O. (2004) Mixed Model Influence Diagnostics, 121 | in \emph{Proceedings of the Twenty-Ninth SAS Users Group International Conference}, 122 | SAS Users Group International. 123 | } 124 | \seealso{ 125 | \code{\link{leverage.mer}}, 126 | \code{\link{covratio.mer}}, \code{\link{covtrace.mer}}, \code{\link{rvc.mer}} 127 | } 128 | \author{ 129 | Adam Loy \email{loyad01@gmail.com} 130 | } 131 | \keyword{models} 132 | \keyword{regression} 133 | -------------------------------------------------------------------------------- /man/covratio.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/influence_functions.R 3 | \name{covratio.default} 4 | \alias{covratio.default} 5 | \alias{covtrace.default} 6 | \alias{covratio.mer} 7 | \alias{covratio} 8 | \alias{covratio.lmerMod} 9 | \alias{covratio.lme} 10 | \alias{covtrace.mer} 11 | \alias{covtrace} 12 | \alias{covtrace.lmerMod} 13 | \alias{covtrace.lme} 14 | \title{Influence on precision of fixed effects in HLMs} 15 | \usage{ 16 | \method{covratio}{default}(model, ...) 17 | 18 | \method{covtrace}{default}(model, ...) 19 | 20 | \method{covratio}{mer}(model, level = 1, delete = NULL, ...) 21 | 22 | \method{covratio}{lmerMod}(model, level = 1, delete = NULL, ...) 23 | 24 | \method{covratio}{lme}(model, level = 1, delete = NULL, ...) 25 | 26 | \method{covtrace}{mer}(model, level = 1, delete = NULL, ...) 27 | 28 | \method{covtrace}{lmerMod}(model, level = 1, delete = NULL, ...) 29 | 30 | \method{covtrace}{lme}(model, level = 1, delete = NULL, ...) 31 | } 32 | \arguments{ 33 | \item{model}{fitted model object of class \code{mer} or \code{lmerMod}} 34 | 35 | \item{...}{do not use} 36 | 37 | \item{level}{variable used to define the group for which cases will be 38 | deleted. If \code{level = 1} (default), then individual cases will be deleted.} 39 | 40 | \item{delete}{index of individual cases to be deleted. To delete specific 41 | observations the row number must be specified. To delete higher level 42 | units the group ID and \code{group} parameter must be specified. 43 | If \code{delete = NULL} then all cases are iteratively deleted.} 44 | } 45 | \value{ 46 | If \code{delete = NULL} then a vector corresponding to each deleted 47 | observation/group is returned. 48 | 49 | If \code{delete} is specified then a single value is returned corresponding 50 | to the deleted subset specified. 51 | } 52 | \description{ 53 | These functions calculate measures of the change in the covariance 54 | matrices for the fixed effects based on the deletion of an 55 | observation, or group of observations, for a hierarchical 56 | linear model fit using \code{lmer}. 57 | } 58 | \details{ 59 | Both the covariance ratio (\code{covratio}) and the covariance trace 60 | (\code{covtrace}) measure the change in the covariance matrix 61 | of the fixed effects based on the deletion of a subset of observations. 62 | The key difference is how the variance covariance matrices are compared: 63 | \code{covratio} compares the ratio of the determinants while \code{covtrace} 64 | compares the trace of the ratio. 65 | } 66 | \examples{ 67 | 68 | data(sleepstudy, package = 'lme4') 69 | ss <- lme4::lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) 70 | 71 | # covratio for individual observations 72 | ss.cr1 <- covratio(ss) 73 | 74 | # covratio for subject-level deletion 75 | ss.cr2 <- covratio(ss, level = "Subject") 76 | 77 | \dontrun{ 78 | ## A larger example 79 | data(Exam, package = 'mlmRev') 80 | fm <- lme4::lmer(normexam ~ standLRT * schavg + (standLRT | school), data = Exam) 81 | 82 | # covratio for individual observations 83 | cr1 <- covratio(fm) 84 | 85 | # covratio for school-level deletion 86 | cr2 <- covratio(fm, level = "school") 87 | } 88 | 89 | # covtrace for individual observations 90 | ss.ct1 <- covtrace(ss) 91 | 92 | # covtrace for subject-level deletion 93 | ss.ct2 <- covtrace(ss, level = "Subject") 94 | 95 | \dontrun{ 96 | ## Returning to the larger example 97 | # covtrace for individual observations 98 | ct1 <- covtrace(fm) 99 | 100 | # covtrace for school-level deletion 101 | ct2 <- covtrace(fm, level = "school") 102 | } 103 | } 104 | \references{ 105 | Christensen, R., Pearson, L., & Johnson, W. (1992) 106 | Case-deletion diagnostics for mixed models. \emph{Technometrics}, \bold{34}(1), 107 | 38--45. 108 | 109 | Schabenberger, O. (2004) Mixed Model Influence Diagnostics, 110 | in \emph{Proceedings of the Twenty-Ninth SAS Users Group International Conference}, 111 | SAS Users Group International. 112 | } 113 | \seealso{ 114 | \code{\link{leverage.mer}}, \code{\link{cooks.distance.mer}} 115 | \code{\link{mdffits.mer}}, \code{\link{rvc.mer}} 116 | } 117 | \author{ 118 | Adam Loy \email{loyad01@gmail.com} 119 | } 120 | \keyword{models} 121 | \keyword{regression} 122 | -------------------------------------------------------------------------------- /man/dotplot_diag.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_functions.R 3 | \name{dotplot_diag} 4 | \alias{dotplot_diag} 5 | \title{Dot plots for influence diagnostics} 6 | \usage{ 7 | dotplot_diag( 8 | x, 9 | cutoff, 10 | name = c("cooks.distance", "mdffits", "covratio", "covtrace", "rvc", "leverage"), 11 | data, 12 | index = NULL, 13 | modify = FALSE, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{x}{values of the diagnostic of interest} 19 | 20 | \item{cutoff}{value(s) specifying the boundary for unusual values of the 21 | diagnostic. The cutoff(s) can either be supplied by the user, or automatically 22 | calculated using measures of internal scaling if \code{cutoff = "internal"}.} 23 | 24 | \item{name}{what diagnostic is being plotted 25 | (one of \code{"cooks.distance"}, \code{"mdffits"}, \code{"covratio"}, 26 | \code{"covtrace"}, \code{"rvc"}, or \code{"leverage"}). 27 | This is used for the calculation of "internal" cutoffs.} 28 | 29 | \item{data}{data frame to use (optional)} 30 | 31 | \item{index}{optional parameter to specify index (IDs) of \code{x} values. 32 | If \code{NULL}(default), values will be indexed in the order of the vector 33 | passed to \code{x}.} 34 | 35 | \item{modify}{specifies the \code{geom} to be used to produce a 36 | space-saving modification: either \code{"dotplot"} or \code{"boxplot"}} 37 | 38 | \item{...}{other arguments to be passed to \code{ggplot()}} 39 | } 40 | \description{ 41 | This is a function that can be used to create (modified) dotplots for the 42 | diagnostic measures. The plot allows the user to understand the distribution 43 | of the diagnostic measure and visually identify unusual cases. 44 | } 45 | \note{ 46 | The resulting plot uses \code{coord_flip} to rotate the plot, so when 47 | adding customized axis labels you will need to flip the names 48 | between the x and y axes. 49 | } 50 | \examples{ 51 | data(sleepstudy, package = 'lme4') 52 | fm <- lme4::lmer(Reaction ~ Days + (Days | Subject), sleepstudy) 53 | 54 | #Observation level deletion and diagnostics 55 | obs.infl <- hlm_influence(fm, level = 1) 56 | 57 | dotplot_diag(x = obs.infl$cooksd, cutoff = "internal", name = "cooks.distance", modify = FALSE) 58 | 59 | dotplot_diag(x = obs.infl$mdffits, cutoff = "internal", name = "cooks.distance", modify = FALSE) 60 | 61 | # Subject level deletion and diagnostics 62 | subject.infl <- hlm_influence(fm, level = "Subject") 63 | 64 | dotplot_diag(x = subject.infl$cooksd, cutoff = "internal", 65 | name = "cooks.distance", modify = FALSE) 66 | 67 | dotplot_diag(x = subject.infl$mdffits, cutoff = "internal", name = "mdffits", modify = "dotplot") 68 | } 69 | \author{ 70 | Adam Loy \email{loyad01@gmail.com} 71 | } 72 | \keyword{hplot} 73 | -------------------------------------------------------------------------------- /man/extract_design.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utility_functions.R 3 | \name{extract_design} 4 | \alias{extract_design} 5 | \title{Extracting covariance matrices from lme} 6 | \usage{ 7 | extract_design(b) 8 | } 9 | \arguments{ 10 | \item{b}{a fitted model object of class \code{lme}.} 11 | } 12 | \value{ 13 | A list of matrices is returned. 14 | \itemize{ 15 | \item{\code{D} contains the covariance matrix of the random effects.} 16 | \item{\code{V} contains the covariance matrix of the response.} 17 | \item{\code{X} contains the fixed-effect model matrix.} 18 | \item{\code{Z} contains the random-effect model matrix.}} 19 | } 20 | \description{ 21 | This function extracts the full covariance matrices from a mixed/hierarchical 22 | linear model fit using \code{lme}. 23 | } 24 | \references{ 25 | This method has been adapted from the method 26 | \code{mgcv::extract.lme.cov} in the \code{mgcv} package, written by Simon 27 | N. Wood \email{simon.wood@r-project.org}. 28 | } 29 | \author{ 30 | Adam Loy \email{loyad01@gmail.com} 31 | } 32 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/man/figures/logo.png -------------------------------------------------------------------------------- /man/hlm_augment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hlm_augment.R 3 | \name{hlm_augment} 4 | \alias{hlm_augment} 5 | \alias{hlm_augment.default} 6 | \alias{hlm_augment.lmerMod} 7 | \alias{hlm_augment.lme} 8 | \title{Calculating residuals and influence diagnostics for HLMs} 9 | \usage{ 10 | hlm_augment(object, ...) 11 | 12 | \method{hlm_augment}{default}(object, ...) 13 | 14 | \method{hlm_augment}{lmerMod}(object, level = 1, include.ls = TRUE, data = NULL, ...) 15 | 16 | \method{hlm_augment}{lme}(object, level = 1, include.ls = TRUE, ...) 17 | } 18 | \arguments{ 19 | \item{object}{an object of class \code{lmerMod} or \code{lme}.} 20 | 21 | \item{...}{currently not used} 22 | 23 | \item{level}{which residuals should be extracted and what cases should be deleted for influence diagnostics. 24 | If \code{level = 1} (default), then within-group (case-level) residuals are returned and influence diagnostics 25 | are calculated for individual observations. Otherwise, \code{level} should be the name of a grouping 26 | factor as defined in \code{flist} for a \code{lmerMod} object or as in \code{groups} for a \code{lme} object. 27 | This will return between-group residuals and influence diagnostics calculated for each group.} 28 | 29 | \item{include.ls}{a logical indicating if LS residuals should be included in the 30 | return tibble. \code{include.ls = FALSE} decreases runtime substantially.} 31 | 32 | \item{data}{the original data frame passed to `lmer`. This is only necessary for `lmerMod` models where 33 | `na.action = "na.exclude"`} 34 | } 35 | \description{ 36 | This function is used to compute residuals, fitted values, and influence diagnostics for a 37 | hierarchical linear model. The residuals and fitted values are computed using Least Squares(LS) 38 | and Empirical Bayes (EB) methods. The influence diagnostics are computed through one step 39 | approximations. 40 | } 41 | \details{ 42 | The \code{hlm_augment} function combines functionality from \code{hlm_resid} 43 | and \code{hlm_influence} for a simpler way of obtaining residuals and influence 44 | diagnostics. Please see \code{?hlm_resid} and \code{?hlm_influence} for additional information 45 | about the returned values. 46 | } 47 | \note{ 48 | \code{hlm_augment} does not allow for the deletion of specific cases, the specification of other 49 | types of leverage, or the use of full refits of the model instead of one step approximations for influence 50 | diagnostics. If this additional functionality is desired, \code{hlm_influence} should be used instead. The additional 51 | parameter \code{standardize} is available in \code{hlm_resid}; if this are desired, \code{hlm_resid} 52 | should be used instead. 53 | } 54 | -------------------------------------------------------------------------------- /man/hlm_influence.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/diagnostic_functions.R, R/hlm_influence.R 3 | \name{cooks.distance.case_delete} 4 | \alias{cooks.distance.case_delete} 5 | \alias{mdffits.case_delete} 6 | \alias{covtrace.case_delete} 7 | \alias{covratio.case_delete} 8 | \alias{rvc.case_delete} 9 | \alias{hlm_influence} 10 | \alias{hlm_influence.default} 11 | \alias{hlm_influence.lmerMod} 12 | \alias{hlm_influence.lme} 13 | \title{Calculating influence diagnostics for HLMs} 14 | \usage{ 15 | \method{cooks.distance}{case_delete}(model, ...) 16 | 17 | \method{mdffits}{case_delete}(model, ...) 18 | 19 | \method{covtrace}{case_delete}(model, ...) 20 | 21 | \method{covratio}{case_delete}(model, ...) 22 | 23 | \method{rvc}{case_delete}(model, ...) 24 | 25 | hlm_influence(model, ...) 26 | 27 | \method{hlm_influence}{default}(model, ...) 28 | 29 | \method{hlm_influence}{lmerMod}( 30 | model, 31 | level = 1, 32 | delete = NULL, 33 | approx = TRUE, 34 | leverage = "overall", 35 | data = NULL, 36 | ... 37 | ) 38 | 39 | \method{hlm_influence}{lme}( 40 | model, 41 | level = 1, 42 | delete = NULL, 43 | approx = TRUE, 44 | leverage = "overall", 45 | ... 46 | ) 47 | } 48 | \arguments{ 49 | \item{model}{an object of class \code{lmerMod} or \code{lme}} 50 | 51 | \item{...}{not in use} 52 | 53 | \item{level}{used to define the group for which cases are deleted and influence 54 | diagnostics are calculated. If \code{level = 1} (default), then influence diagnostics are 55 | calculated for individual observations. Otherwise, \code{level} should be the name of a grouping 56 | factor as defined in \code{flist} for a \code{lmerMod} object or as in \code{groups} for a \code{lme} object.} 57 | 58 | \item{delete}{numeric index of individual cases to be deleted. If the \code{level} parameter 59 | is specified, \code{delete} may also take the form of a character vector consisting of group 60 | names as they appear in \code{flist} for \code{lme4} models or as in \code{groups} for \code{nlme} models. 61 | If \code{delete = NULL} then all cases are iteratively deleted.} 62 | 63 | \item{approx}{logical parameter used to determine how the influence diagnostics are calculated. 64 | If \code{FALSE} (default), influence diagnostics are calculated using a one step approximation. 65 | If \code{TRUE}, influence diagnostics are calculated by iteratively deleting groups and refitting 66 | the model using \code{lmer}. This method is more accurate, but slower than the one step approximation. 67 | If \code{approx = FALSE}, the returned tibble also contains columns for relative variance change (RVC).} 68 | 69 | \item{leverage}{a character vector to determine which types of leverage should be included in the 70 | returned tibble. There are four options: 'overall' (default), 'fixef', 'ranef', or 'ranef.uc'. 71 | One or more types may be specified. For additional information about the types of leverage, see 72 | \code{?leverage}.} 73 | 74 | \item{data}{(optional) the data frame used to fit the model. This is only necessary for \code{lmerMod} models if 75 | \code{na.action = "na.exclude"} was set.} 76 | } 77 | \description{ 78 | This function is used to compute influence diagnostics for a hierarchical linear model. 79 | It takes a model fit as a \code{lmerMod} object or as a \code{lme} object and returns a tibble with Cook's 80 | distance, MDFFITS, covtrace, covratio, and leverage. 81 | } 82 | \details{ 83 | The \code{hlm_influence} function provides a wrapper that appends influence diagnostics 84 | to the original data. The approximated influence diagnostics returned by this 85 | function are equivalent to those returned by \code{cooks.distance}, \code{mdffits}, \code{covtrace}, 86 | \code{covratio}, and \code{leverage}. The exact influence diagnostics obtained through a full 87 | refit of the data are also available through \code{case_delete} and the accompanying functions 88 | \code{cooks.distance}, \code{mdffits}, \code{covtrace}, and \code{covratio} that can be called 89 | directly on the \code{case_delete} object. 90 | } 91 | \note{ 92 | It is possible to set \code{level} and delete individual cases from different groups using 93 | \code{delete}, so numeric indices should be double checked to confirm that they encompass entire groups. 94 | Additionally, if \code{delete} is specified, leverage values are not returned in the resulting tibble. 95 | } 96 | \examples{ 97 | \dontrun{ 98 | data(sleepstudy, package = 'lme4') 99 | fm <- lme4::lmer(Reaction ~ Days + (Days | Subject), sleepstudy) 100 | 101 | # Subject level deletion and diagnostics 102 | subject.del <- case_delete(model = fm, group = "Subject", type = "both") 103 | subject.cooks <- cooks.distance(subject.del) 104 | subject.covtrace <- covtrace(subject.del) 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /man/hlm_resid.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hlm_resid.R 3 | \name{hlm_resid.default} 4 | \alias{hlm_resid.default} 5 | \alias{hlm_resid} 6 | \alias{hlm_resid.lmerMod} 7 | \alias{hlm_resid.lme} 8 | \title{Calculating residuals from HLMs} 9 | \usage{ 10 | \method{hlm_resid}{default}(object, ...) 11 | 12 | \method{hlm_resid}{lmerMod}( 13 | object, 14 | level = 1, 15 | standardize = FALSE, 16 | include.ls = TRUE, 17 | data = NULL, 18 | ... 19 | ) 20 | 21 | \method{hlm_resid}{lme}( 22 | object, 23 | level = 1, 24 | standardize = FALSE, 25 | include.ls = TRUE, 26 | data = NULL, 27 | ... 28 | ) 29 | } 30 | \arguments{ 31 | \item{object}{an object of class \code{lmerMod} or \code{lme}.} 32 | 33 | \item{...}{do not use} 34 | 35 | \item{level}{which residuals should be extracted: 1 for within-group 36 | (case-level) residuals, the name of a grouping factor for between-group 37 | residuals (as defined in \code{flist} in \code{lmerMod} objects or in 38 | \code{groups} in \code{lme} objects)} 39 | 40 | \item{standardize}{for any level, if \code{standardize = TRUE} the 41 | standardized residuals will be returned for any group; for level-1 only, if 42 | \code{standardize = "semi"} then the semi-standardized level-1 residuals 43 | will be returned} 44 | 45 | \item{include.ls}{a logical indicating if LS residuals be included in the 46 | return tibble. \code{include.ls = FALSE} decreases runtime substantially.} 47 | 48 | \item{data}{if \code{na.action = na.exclude}, the user must provide the data 49 | set used to fit the model, otherwise \code{NULL}.} 50 | } 51 | \description{ 52 | \code{hlm_resid} takes a hierarchical linear model fit as a \code{lmerMod} or 53 | \code{lme} object and extracts residuals and predicted values from the model, 54 | using Least Squares (LS) and Empirical Bayes (EB) methods. It then appends 55 | them to the model data frame in the form of a tibble inspired by the \code{augment} 56 | function in \code{broom}. This unified framework enables the analyst to more 57 | easily conduct an upward residual analysis during model exploration/checking. 58 | } 59 | \details{ 60 | The \code{hlm_resid} function provides a wrapper that will extract 61 | residuals and predicted values from a fitted \code{lmerMod} or \code{lme} 62 | object. The function provides access to residual quantities already made available by 63 | the functions \code{resid}, \code{predict}, and \code{ranef}, but adds 64 | additional functionality. Below is a list of types of residuals and predicted 65 | values that are extracted and appended to the model data. 66 | \describe{ 67 | \item{\strong{level-1 residuals}}{} 68 | \item{\code{.resid} and \code{.fitted}}{Residuals calculated using 69 | the EB method (using maximum likelihood). Level-1 EB residuals are interrelated 70 | with higher level residuals. Equivalent to the residuals extracted by 71 | \code{resid(object)} and \code{predict(object)} respectively. When 72 | \code{standardize = TRUE}, residuals are standardized by sigma components of 73 | the model object.} 74 | \item{\code{.ls.resid} and \code{.ls.fitted}}{Residuals calculated calculated 75 | by fitting separate LS regression models for each group. Level-1 LS residuals 76 | are unconfounded by higher level residuals, but unreliable for small 77 | within-group sample sizes.} 78 | \item{\code{.mar.resid} and \code{.mar.fitted}}{Marginal residuals only 79 | consider the fixed effect portion of the estimates. Equivalent to 80 | \code{resid(object, level=0)} in \code{nlme}, not currently implemented 81 | within the \code{lme4::resid} function. When \code{standardize = TRUE}, 82 | Cholesky marginal residuals are returned.} 83 | \item{\strong{higher-level residuals} (random effects)}{} 84 | \item{\code{.ranef.var_name}}{The group level random effects using the EB method of 85 | estimating parameters. Equivalent to \code{ranef(object)} on the specified 86 | level. EB residuals are preferred at higher levels as LS residuals are dependent 87 | on a large sample size.} 88 | \item{\code{.ls.var_name}}{The group level random effects using the LS method of 89 | estimating parameters. Calculated using \code{ranef} on a \code{lmList} 90 | object to compare the random effects of individual models to the global 91 | model.} 92 | } 93 | Note that \code{standardize = "semi"} is only implemented for level-1 LS residuals. 94 | } 95 | \examples{ 96 | data(sleepstudy, package = "lme4") 97 | fm.lmer <- lme4::lmer(Reaction ~ Days + (Days|Subject), sleepstudy) 98 | fm.lme <- nlme::lme(Reaction ~ Days, random = ~Days|Subject, sleepstudy) 99 | 100 | # level-1 and marginal residuals 101 | fm.lmer.res1 <- hlm_resid(fm.lmer) ## raw level-1 and mar resids 102 | fm.lmer.res1 103 | fm.lme.std1 <- hlm_resid(fm.lme, standardize = TRUE) ## std level-1 and mar resids 104 | fm.lme.std1 105 | 106 | # level-2 residuals 107 | fm.lmer.res2 <- hlm_resid(fm.lmer, level = "Subject") ## level-2 ranefs 108 | fm.lmer.res2 109 | fm.lme.res2 <- hlm_resid(fm.lme, level = "Subject", include.ls = FALSE) ##level-2 ranef, no LS 110 | fm.lme.res2 111 | } 112 | \references{ 113 | Hilden-Minton, J. (1995) Multilevel diagnostics for mixed and hierarchical 114 | linear models. University of California Los Angeles. 115 | 116 | Houseman, E. A., Ryan, L. M., & Coull, B. A. (2004) 117 | Cholesky Residuals for Assessing Normal Errors in a Linear 118 | Model With Correlated Outcomes. 119 | \emph{Journal of the American Statistical Association}, 99(466), 383--394. 120 | 121 | David Robinson and Alex Hayes (2020). broom: Convert Statistical Analysis 122 | Objects into Tidy Tibbles. R package version 0.5.6. 123 | \url{https://CRAN.R-project.org/package=broom} 124 | } 125 | \seealso{ 126 | \code{\link{hlm_augment}}, \code{\link{resid}}, \code{\link[lme4:ranef]{lme4::ranef}} 127 | } 128 | \author{ 129 | Adam Loy \email{loyad01@gmail.com}, Jack Moran, Jaylin Lowe 130 | } 131 | \keyword{models} 132 | \keyword{regression} 133 | -------------------------------------------------------------------------------- /man/leverage.mer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/influence_functions.R 3 | \name{leverage.default} 4 | \alias{leverage.default} 5 | \alias{leverage.mer} 6 | \alias{leverage} 7 | \alias{leverage.lmerMod} 8 | \alias{leverage.lme} 9 | \title{Leverage for HLMs} 10 | \usage{ 11 | \method{leverage}{default}(model, ...) 12 | 13 | \method{leverage}{mer}(model, level = 1, ...) 14 | 15 | \method{leverage}{lmerMod}(model, level = 1, ...) 16 | 17 | \method{leverage}{lme}(model, level = 1, ...) 18 | } 19 | \arguments{ 20 | \item{model}{fitted model object of class \code{mer} of \code{lmerMod}} 21 | 22 | \item{...}{do not use} 23 | 24 | \item{level}{the level at which the leverage should be calculated: either 25 | 1 for observation level leverage (default) or the name of the grouping factor 26 | (as defined in \code{flist} of the \code{mer} object) for group level 27 | leverage. \code{leverage} assumes that the grouping factors are unique; 28 | thus, if IDs are repeated within each unit, unique IDs must be generated 29 | by the user prior to use of \code{leverage}.} 30 | } 31 | \value{ 32 | \code{leverage} returns a data frame with the following columns: 33 | \describe{ 34 | \item{\code{overall}}{The overall leverage, i.e. \eqn{H = H_1 + H_2}.} 35 | \item{\code{fixef}}{The leverage corresponding to the fixed effects.} 36 | \item{\code{ranef}}{The leverage corresponding to the random effects 37 | proposed by Demidenko and Stukel (2005).} 38 | \item{\code{ranef.uc}}{The (unconfounded) leverage corresponding to the 39 | random effects proposed by Nobre and Singer (2011).} 40 | } 41 | } 42 | \description{ 43 | This function calculates the leverage of 44 | a hierarchical linear model fit by \code{lmer}. 45 | } 46 | \details{ 47 | Demidenko and Stukel (2005) describe leverage for mixed (hierarchical) 48 | linear models as being the sum of two components, a leverage associated with the 49 | fixed (\eqn{H_1}) and a leverage associated with the random effects (\eqn{H_2}) where 50 | \deqn{H_1 = X (X^\prime V^{-1} X)^{-1} X^\prime V^{-1}} 51 | and 52 | \deqn{H_2 = ZDZ^{\prime} V^{-1} (I - H_1)} 53 | Nobre and Singer (2011) propose using 54 | \deqn{H_2^* = ZDZ^{\prime}} 55 | as the random effects leverage as it does not rely on the fixed effects. 56 | 57 | For individual observations \code{leverage} uses the diagonal elements of the 58 | above matrices as the measure of leverage. For higher-level units, 59 | \code{leverage} uses the mean trace of the above matrices associated with each 60 | higher-level unit. 61 | } 62 | \examples{ 63 | data(sleepstudy, package = 'lme4') 64 | fm <- lme4::lmer(Reaction ~ Days + (Days | Subject), sleepstudy) 65 | 66 | # Observation level leverage 67 | lev1 <- leverage(fm, level = 1) 68 | head(lev1) 69 | 70 | # Group level leverage 71 | lev2 <- leverage(fm, level = "Subject") 72 | head(lev2) 73 | } 74 | \references{ 75 | Demidenko, E., & Stukel, T. A. (2005) 76 | Influence analysis for linear mixed-effects models. 77 | \emph{Statistics in Medicine}, \bold{24}(6), 893--909. 78 | 79 | Nobre, J. S., & Singer, J. M. (2011) 80 | Leverage analysis for linear mixed models. 81 | \emph{Journal of Applied Statistics}, \bold{38}(5), 1063--1072. 82 | } 83 | \seealso{ 84 | \code{\link{cooks.distance.mer}}, \code{\link{mdffits.mer}}, 85 | \code{\link{covratio.mer}}, \code{\link{covtrace.mer}}, \code{\link{rvc.mer}} 86 | } 87 | \author{ 88 | Adam Loy \email{loyad01@gmail.com} 89 | } 90 | \keyword{models} 91 | \keyword{regression} 92 | -------------------------------------------------------------------------------- /man/pull_resid.lmerMod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pull_resid.R 3 | \name{pull_resid.default} 4 | \alias{pull_resid.default} 5 | \alias{pull_resid.lmerMod} 6 | \alias{pull_resid} 7 | \alias{pull_resid.lme} 8 | \title{Computationally Efficient HLM Residuals} 9 | \usage{ 10 | \method{pull_resid}{default}(object, ...) 11 | 12 | \method{pull_resid}{lmerMod}(object, type = "ls", standardize = FALSE, ...) 13 | 14 | \method{pull_resid}{lme}(object, type = "ls", standardize = FALSE, ...) 15 | } 16 | \arguments{ 17 | \item{object}{an object of class \code{lmerMod} or \code{lme}.} 18 | 19 | \item{...}{not in use} 20 | 21 | \item{type}{which residuals should be returned. Can be either 'ls', 'eb', or 22 | 'marginal'} 23 | 24 | \item{standardize}{a logical indicating if residuals should be standardized} 25 | } 26 | \description{ 27 | \code{pull_resid} takes a hierarchical linear model fit as a \code{lmerMod} 28 | or \code{lme} object and returns various types of level-1 residuals as a 29 | vector. Because the \code{pull_resid} only calculates one type of residual, 30 | it is more efficient than using \code{\link{hlm_resid}} and indexing the 31 | resulting tibble. \code{pull_resid} is designed to be used with methods that 32 | take a long time to run, such as the resampling methods found in the 33 | \code{lmeresampler} package. 34 | } 35 | \details{ 36 | \describe{ 37 | \item{\code{type = "ls"}}{Residuals calculated by fitting separate LS 38 | regression models for each group. LS residuals are unconfounded by higher 39 | level residuals, but unreliable for small within-group sample sizes. When 40 | \code{standardize = TRUE}, residuals are standardized by sigma components of 41 | the model object.} 42 | \item{\code{type = "eb"}}{Residuals calculated using the empirical Bayes (EB) 43 | method using maximum likelihood. EB residuals are interrelated with higher 44 | level residuals. When \code{standardize = TRUE}, residuals are standardized 45 | by sigma components of the model object.} 46 | \item{\code{type = "marginal"}}{Marginal residuals only consider the fixed 47 | effect portion of the estimates. When \code{standardize = TRUE}, Cholesky 48 | residuals are returned.} 49 | } 50 | } 51 | \seealso{ 52 | \link[HLMdiag]{hlm_resid} 53 | } 54 | -------------------------------------------------------------------------------- /man/radon.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/radon.R 3 | \docType{data} 4 | \name{radon} 5 | \alias{radon} 6 | \title{Radon data} 7 | \format{ 8 | A data frame with 919 observations on the following 5 variables: 9 | \describe{ 10 | \item{log.radon}{Radon measurement (in log pCi/L, i.e., log picoCurie per liter)} 11 | \item{basement}{Indicator for the level of the home at which the radon measurement 12 | was taken - 0 = basement, 1 = first floor.} 13 | \item{uranium}{Average county-level soil uranium content.} 14 | \item{county}{County ID.} 15 | \item{county.name}{County name - a factor.} 16 | } 17 | } 18 | \usage{ 19 | data(radon) 20 | } 21 | \description{ 22 | Radon measurements of 919 owner-occupied homes in 85 counties of Minnesota. 23 | } 24 | \references{ 25 | Price, P. N., Nero, A. V. and Gelman, A. (1996) Bayesian prediction of mean 26 | indoor radon concentrations for Minnesota counties. \emph{Health Physics}. 27 | \bold{71}(6), 922--936. 28 | 29 | Gelman, A. and Hill, J. (2007) \emph{Data analysis using regression and 30 | multilevel/hierarchical models}. Cambridge University Press. 31 | } 32 | \keyword{datasets} 33 | -------------------------------------------------------------------------------- /man/resid_conditional.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/residual_functions.R 3 | \name{resid_conditional.default} 4 | \alias{resid_conditional.default} 5 | \alias{resid_conditional.lmerMod} 6 | \alias{resid_conditional} 7 | \alias{resid_conditional.lme} 8 | \title{Conditional residuals} 9 | \usage{ 10 | \method{resid_conditional}{default}(object, type) 11 | 12 | \method{resid_conditional}{lmerMod}( 13 | object, 14 | type = c("raw", "pearson", "studentized", "cholesky") 15 | ) 16 | 17 | \method{resid_conditional}{lme}( 18 | object, 19 | type = c("raw", "pearson", "studentized", "cholesky") 20 | ) 21 | } 22 | \arguments{ 23 | \item{object}{an object of class \code{lmerMod} or \code{lme}.} 24 | 25 | \item{type}{a character string specifying what type of residuals should be calculated. 26 | It is set to \code{"raw"} (observed - fitted) by default. Other options include 27 | \code{"pearson"}, \code{"studentized"}, and \code{"cholesky"}. 28 | Partial matching of arguments is used, so only the first character needs to be provided.} 29 | } 30 | \value{ 31 | A vector of conditional residuals. 32 | } 33 | \description{ 34 | Calculates conditional residuals of \code{lmerMod} and \code{lme} model objects. 35 | } 36 | \details{ 37 | For a model of the form \eqn{Y = X \beta + Z b + \epsilon}, 38 | four types of marginal residuals can be calculated: 39 | 40 | \describe{ 41 | \item{\code{raw}}{\eqn{e = Y - X \hat{beta} - Z \hat{b}}} 42 | \item{\code{pearson}}{\eqn{e / \sqrt{diag(\hat{Var}(Y|b)})}} 43 | \item{\code{studentized}}{\eqn{e / \sqrt{diag(\hat{Var}(e))}}} 44 | \item{\code{cholesky}}{\eqn{\hat{C}^{-1} e} where \eqn{\hat{C}\hat{C}^\prime = \hat{Var}(e)}} 45 | } 46 | } 47 | \references{ 48 | Singer, J. M., Rocha, F. M. M., & Nobre, J. S. (2017). 49 | Graphical Tools for Detecting Departures from Linear Mixed Model 50 | Assumptions and Some Remedial Measures. 51 | \emph{International Statistical Review}, \bold{85}, 290--324. 52 | 53 | Schabenberger, O. (2004) Mixed Model Influence Diagnostics, 54 | in \emph{Proceedings of the Twenty-Ninth SAS Users Group International Conference}, 55 | SAS Users Group International. 56 | } 57 | -------------------------------------------------------------------------------- /man/resid_marginal.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/residual_functions.R 3 | \name{resid_marginal.default} 4 | \alias{resid_marginal.default} 5 | \alias{resid_marginal.lmerMod} 6 | \alias{resid_marginal} 7 | \alias{resid_marginal.lme} 8 | \title{Marginal residuals} 9 | \usage{ 10 | \method{resid_marginal}{default}(object, type) 11 | 12 | \method{resid_marginal}{lmerMod}(object, type = c("raw", "pearson", "studentized", "cholesky")) 13 | 14 | \method{resid_marginal}{lme}(object, type = c("raw", "pearson", "studentized", "cholesky")) 15 | } 16 | \arguments{ 17 | \item{object}{an object of class \code{lmerMod} or \code{lme}.} 18 | 19 | \item{type}{a character string specifying what type of residuals should be calculated. 20 | It is set to \code{"raw"} (observed - fitted) by default. Other options include 21 | \code{"pearson"}, \code{"studentized"}, and \code{"cholesky"}. Partial matching of arguments is used, 22 | so only the first character needs to be provided.} 23 | } 24 | \value{ 25 | A vector of marginal residuals. 26 | } 27 | \description{ 28 | Calculates marginal residuals of \code{lmerMod} and \code{lme} model objects. 29 | } 30 | \details{ 31 | For a model of the form \eqn{Y = X \beta + Z b + \epsilon}, 32 | four types of marginal residuals can be calculated: 33 | 34 | \describe{ 35 | \item{\code{raw}}{\eqn{r = Y - X \hat{beta}}} 36 | \item{\code{pearson}}{\eqn{r / \sqrt{ diag(\hat{Var}(Y)})}} 37 | \item{\code{studentized}}{\eqn{r / \sqrt{ diag(\hat{Var}(r)})}} 38 | \item{\code{cholesky}}{\eqn{\hat{C}^{-1} r} where \eqn{\hat{C}\hat{C}^\prime = \hat{Var}(Y)}} 39 | } 40 | } 41 | \references{ 42 | Singer, J. M., Rocha, F. M. M., & Nobre, J. S. (2017). 43 | Graphical Tools for Detecting Departures from Linear Mixed Model 44 | Assumptions and Some Remedial Measures. 45 | \emph{International Statistical Review}, \bold{85}, 290--324. 46 | 47 | Schabenberger, O. (2004) Mixed Model Influence Diagnostics, 48 | in \emph{Proceedings of the Twenty-Ninth SAS Users Group International Conference}, 49 | SAS Users Group International. 50 | } 51 | -------------------------------------------------------------------------------- /man/resid_ranef.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/residual_functions.R 3 | \name{resid_ranef} 4 | \alias{resid_ranef} 5 | \title{Random effects residuals} 6 | \usage{ 7 | resid_ranef(object, level, which, standardize) 8 | } 9 | \arguments{ 10 | \item{object}{an object of class \code{lmerMod}.} 11 | 12 | \item{level}{DESCRIPTION} 13 | 14 | \item{which}{DESCRIPTION} 15 | 16 | \item{standardize}{DESCRIPTION} 17 | } 18 | \value{ 19 | A vector of conditional residuals. 20 | } 21 | \description{ 22 | Calculates Random effects residuals of \code{lmerMod} model objects. 23 | } 24 | -------------------------------------------------------------------------------- /man/rotate_ranef.mer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rotate_ranefs.R 3 | \name{rotate_ranef.default} 4 | \alias{rotate_ranef.default} 5 | \alias{rotate_ranef.mer} 6 | \alias{rotate_ranef} 7 | \alias{rotate_ranef.lmerMod} 8 | \alias{rotate_ranef.lme} 9 | \title{Calculate s-dimensional rotated random effects} 10 | \usage{ 11 | \method{rotate_ranef}{default}(.mod, ...) 12 | 13 | \method{rotate_ranef}{mer}(.mod, .L, s = NULL, .varimax = FALSE, ...) 14 | 15 | \method{rotate_ranef}{lmerMod}(.mod, .L, s = NULL, .varimax = FALSE, ...) 16 | 17 | \method{rotate_ranef}{lme}(.mod, .L, s = NULL, .varimax = FALSE, ...) 18 | } 19 | \arguments{ 20 | \item{.mod}{an object of class \code{mer} or \code{lmerMod}.} 21 | 22 | \item{...}{do not use} 23 | 24 | \item{.L}{a matrix defining which combination of random effects are of interest.} 25 | 26 | \item{s}{the dimension of the subspace of interest.} 27 | 28 | \item{.varimax}{if \code{.varimax = TRUE} than the raw varimax rotation 29 | will be applied to the resulting rotation.} 30 | } 31 | \description{ 32 | This function calculates reduced dimensional rotated random effects. 33 | The rotation reduces the influence of the residuals from other levels 34 | of the model so that distributional assessment of the resulting 35 | random effects is possible. 36 | } 37 | \references{ 38 | Loy, A. & Hofmann, H. (in press). Are you Normal? 39 | The Problem of Confounded Residual Structures in Hierarchical Linear Models. 40 | \emph{Journal of Computational and Graphical Statistics}. 41 | } 42 | \author{ 43 | Adam Loy \email{loyad01@gmail.com} 44 | } 45 | -------------------------------------------------------------------------------- /man/rvc.mer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/influence_functions.R 3 | \name{rvc.default} 4 | \alias{rvc.default} 5 | \alias{rvc.mer} 6 | \alias{rvc} 7 | \alias{rvc.lmerMod} 8 | \alias{rvc.lme} 9 | \title{Relative variance change for HLMs} 10 | \usage{ 11 | \method{rvc}{default}(model, ...) 12 | 13 | \method{rvc}{mer}(model, level = 1, delete = NULL, ...) 14 | 15 | \method{rvc}{lmerMod}(model, level = 1, delete = NULL, ...) 16 | 17 | \method{rvc}{lme}(model, level = 1, delete = NULL, ...) 18 | } 19 | \arguments{ 20 | \item{model}{fitted model object of class \code{mer} or \code{lmerMod}} 21 | 22 | \item{...}{do not use} 23 | 24 | \item{level}{variable used to define the group for which cases will be 25 | deleted. If \code{level = 1} (default), then individual cases will be deleted.} 26 | 27 | \item{delete}{index of individual cases to be deleted. To delete specific 28 | observations the row number must be specified. To delete higher level 29 | units the group ID and \code{group} parameter must be specified. 30 | If \code{delete = NULL} then all cases are iteratively deleted.} 31 | } 32 | \value{ 33 | If \code{delete = NULL} a matrix with columns corresponding to the variance 34 | components of the model and rows corresponding to the deleted 35 | observation/group is returned. 36 | 37 | If \code{delete} is specified then a named vector is returned. 38 | 39 | The residual variance is named \code{sigma2} and the other variance 40 | components are named \code{D**} where the trailing digits give the 41 | position in the covariance matrix of the random effects. 42 | } 43 | \description{ 44 | This function calculates the relative variance change (RVC) of 45 | hierarchical linear models fit via \code{lmer}. 46 | } 47 | \references{ 48 | Dillane, D. (2005) Deletion Diagnostics for the Linear Mixed Model. 49 | Ph.D. thesis, Trinity College Dublin 50 | } 51 | \seealso{ 52 | \code{\link{leverage.mer}}, 53 | \code{\link{cooks.distance.mer}}, \code{\link{mdffits.mer}}, 54 | \code{\link{covratio.mer}}, \code{\link{covtrace.mer}} 55 | } 56 | \author{ 57 | Adam Loy \email{loyad01@gmail.com} 58 | } 59 | \keyword{models} 60 | \keyword{regression} 61 | -------------------------------------------------------------------------------- /man/varcomp.mer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utility_functions.R 3 | \name{varcomp.mer} 4 | \alias{varcomp.mer} 5 | \title{Extracting variance components} 6 | \usage{ 7 | varcomp.mer(object) 8 | } 9 | \arguments{ 10 | \item{object}{a fitted model object of class \code{mer} or \code{lmerMod}.} 11 | } 12 | \value{ 13 | A named vector is returned. \code{sigma2} denotes the residual 14 | variance. The other variance components are names \code{D**} where the 15 | trailing digits specify the of that variance component in the covariance 16 | matrix of the random effects. 17 | } 18 | \description{ 19 | This function extracts the variance components from a mixed/hierarchical 20 | linear model fit using \code{lmer}. 21 | } 22 | \examples{ 23 | data(sleepstudy, package = "lme4") 24 | fm1 <- lme4::lmer(Reaction ~ Days + (Days|Subject), sleepstudy) 25 | varcomp.mer(fm1) 26 | } 27 | \author{ 28 | Adam Loy \email{loyad01@gmail.com} 29 | } 30 | \keyword{models} 31 | \keyword{regression} 32 | -------------------------------------------------------------------------------- /man/wages.Rd: -------------------------------------------------------------------------------- 1 | \docType{data} 2 | \name{wages} 3 | \alias{wages} 4 | \title{Wages for male high school dropouts} 5 | \format{A data frame with 6402 observations on the following 15 variables. 6 | \describe{ \item{id}{respondent id - a factor with 888 levels.} 7 | \item{lnw}{natural log of wages expressed in 1990 dollars.} 8 | \item{exper}{years of experience in the work force} \item{ged}{equals 1 if 9 | respondent has obtained a GED as of the time of survey, 0 otherwise} 10 | \item{postexp}{labor force participation since obtaining a GED (in years) - 11 | before a GED is earned postexp = 0, and on the day a GED is earned postexp = 12 | 0} \item{black}{factor - equals 1 if subject is black, 0 otherwise} 13 | \item{hispanic}{factor - equals 1 if subject is hispanic, 0 otherwise} 14 | \item{hgc}{highest grade completed - takes integers 6 through 12} 15 | \item{hgc.9}{hgc - 9, a centered version of hgc} \item{uerate}{local area 16 | unemployment rate for that year} \item{ue.7}{} \item{ue.centert1}{} 17 | \item{ue.mean}{} \item{ue.person.cen}{} \item{ue1}{} }} 18 | \source{ 19 | These data are originally from the 1979 National 20 | Longitudinal Survey on Youth (NLSY79). 21 | 22 | Singer and Willett (2003) used these data for examples in 23 | chapter (insert info. here) and the data sets used can be 24 | found on the UCLA Statistical Computing website: 25 | \url{https://stats.oarc.ucla.edu/other/examples/alda/} 26 | 27 | Additionally the data were discussed by Cook and Swayne 28 | (2003) and the data can be found on the GGobi website: 29 | \url{http://ggobi.org/book.html}. 30 | } 31 | \description{ 32 | Data on the labor-market experience of male high school 33 | dropouts. 34 | } 35 | \examples{ 36 | str(wages) 37 | summary(wages) 38 | 39 | \dontrun{ 40 | library(lme4) 41 | lmer(lnw ~ exper + (exper | id), data = wages) 42 | } 43 | } 44 | \references{ 45 | Singer, J. D. and Willett, J. B. (2003), \emph{Applied 46 | Longitudinal Data Analysis: Modeling Change and Event 47 | Occurrence}, New York: Oxford University Press. 48 | 49 | Cook, D. and Swayne, D. F. (2007), \emph{Interactive and 50 | Dynamic Graphics for Data Analysis with R and GGobi}, 51 | Springer. 52 | } 53 | \keyword{datasets} -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /revdep/.gitignore: -------------------------------------------------------------------------------- 1 | checks 2 | library 3 | checks.noindex 4 | library.noindex 5 | data.sqlite 6 | *.html 7 | -------------------------------------------------------------------------------- /revdep/README.md: -------------------------------------------------------------------------------- 1 | # Platform 2 | 3 | |field |value | 4 | |:--------|:-------------------------------------| 5 | |version |R version 4.5.0 (2025-04-11) | 6 | |os |macOS Sequoia 15.4.1 | 7 | |system |x86_64, darwin20 | 8 | |ui |RStudio | 9 | |language |(EN) | 10 | |collate |en_US.UTF-8 | 11 | |ctype |en_US.UTF-8 | 12 | |tz |America/Chicago | 13 | |date |2025-05-12 | 14 | |rstudio |2024.12.1+563 Kousa Dogwood (desktop) | 15 | |pandoc |3.3 @ /usr/local/bin/ (via rmarkdown) | 16 | |quarto |1.5.56 @ /usr/local/bin/quarto | 17 | 18 | # Dependencies 19 | 20 | |package |old |new |Δ | 21 | |:--------|:-----|:-----|:--| 22 | |HLMdiag |0.5.0 |0.5.1 |* | 23 | |generics |NA |0.1.4 |* | 24 | 25 | # Revdeps 26 | 27 | -------------------------------------------------------------------------------- /revdep/cran.md: -------------------------------------------------------------------------------- 1 | ## revdepcheck results 2 | 3 | We checked 4 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/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/problems.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | *.dll 4 | -------------------------------------------------------------------------------- /src/HLMdiag.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aloy/HLMdiag/07543e9e405652d7271f0ebb0b43ec117dd7f709/src/HLMdiag.dll -------------------------------------------------------------------------------- /src/HLMdiag_init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include // for NULL 4 | #include 5 | 6 | /* FIXME: 7 | Check these declarations against the C/Fortran source code. 8 | */ 9 | 10 | /* .Call calls */ 11 | extern SEXP cooksdObs(SEXP, SEXP, SEXP, SEXP, SEXP); 12 | extern SEXP cooksdSubset(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 13 | extern SEXP covratioCalc(SEXP, SEXP, SEXP, SEXP, SEXP); 14 | extern SEXP covtraceCalc(SEXP, SEXP, SEXP, SEXP, SEXP); 15 | extern SEXP cxxmatsub(SEXP, SEXP); 16 | extern SEXP mdffitsSubset(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); 17 | 18 | static const R_CallMethodDef CallEntries[] = { 19 | {"cooksdObs", (DL_FUNC) &cooksdObs, 5}, 20 | {"cooksdSubset", (DL_FUNC) &cooksdSubset, 6}, 21 | {"covratioCalc", (DL_FUNC) &covratioCalc, 5}, 22 | {"covtraceCalc", (DL_FUNC) &covtraceCalc, 5}, 23 | {"cxxmatsub", (DL_FUNC) &cxxmatsub, 2}, 24 | {"mdffitsSubset", (DL_FUNC) &mdffitsSubset, 6}, 25 | {NULL, NULL, 0} 26 | }; 27 | 28 | void R_init_HLMdiag(DllInfo *dll) 29 | { 30 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 31 | R_useDynamicSymbols(dll, FALSE); 32 | } 33 | -------------------------------------------------------------------------------- /src/Makevars: -------------------------------------------------------------------------------- 1 | 2 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_64BIT_WORD=1 3 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) 4 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | 2 | ## This assume that we can call Rscript to ask Rcpp about its locations 3 | ## Use the R_HOME indirection to support installations of multiple R version 4 | ## CXX_STD = CXX11 5 | PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DARMA_64BIT_WORD=1 6 | PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -------------------------------------------------------------------------------- /src/cooksd_obs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace Rcpp; 3 | 4 | // [[Rcpp::depends(RcppArmadillo)]] 5 | 6 | extern "C" SEXP cooksdObs(SEXP y_, SEXP X_, SEXP Vinv_, 7 | SEXP XVXinv_, SEXP beta_) { 8 | arma::colvec Y = Rcpp::as(y_); 9 | arma::mat X = Rcpp::as(X_); 10 | arma::mat Vinv = Rcpp::as(Vinv_); 11 | arma::mat XVXinv = Rcpp::as(XVXinv_); 12 | arma::colvec beta = Rcpp::as(beta_); 13 | 14 | int p = X.n_cols; 15 | int n = Vinv.n_rows; 16 | double sbb, hbb, ybb; 17 | arma::mat Xt = trans(X), XVX = inv(XVXinv); 18 | arma::colvec Vi, xbb, cdd; 19 | Rcpp::NumericVector cooksd ( n ); 20 | Rcpp::List beta_cdd( n ); 21 | int ii; 22 | 23 | for(ii=0; ii 2 | using namespace Rcpp; 3 | 4 | // [[Rcpp::depends(RcppArmadillo)]] 5 | 6 | extern "C" SEXP cooksdSubset(SEXP index, SEXP X_, SEXP P_, 7 | SEXP Vinv_, SEXP XVXinv_, SEXP e_) { 8 | Rcpp::List grpInd(index); 9 | arma::mat X = Rcpp::as(X_); 10 | arma::mat P = Rcpp::as(P_); 11 | arma::mat Vinv = Rcpp::as(Vinv_); 12 | arma::mat XVXinv = Rcpp::as(XVXinv_); 13 | arma::colvec e = Rcpp::as(e_); 14 | 15 | arma::mat Xt = trans(X), XVX = inv(XVXinv); 16 | 17 | int n = grpInd.size(), p = X.n_cols; 18 | int ii; 19 | arma::mat Pa; 20 | arma::colvec cdd; 21 | Rcpp::NumericVector cooksd ( n ); 22 | Rcpp::List beta_cdd ( n ); 23 | 24 | for(ii=0; ii 2 | using namespace Rcpp; 3 | 4 | // [[Rcpp::depends(RcppArmadillo)]] 5 | 6 | extern "C" SEXP covratioCalc(SEXP index, SEXP X_, SEXP P_, 7 | SEXP Vinv_, SEXP XVXinv_) { 8 | Rcpp::List grpInd(index); 9 | arma::mat X = Rcpp::as(X_); 10 | arma::mat P = Rcpp::as(P_); 11 | arma::mat Vinv = Rcpp::as(Vinv_); 12 | arma::mat XVXinv = Rcpp::as(XVXinv_); 13 | 14 | arma::mat Xt = trans(X); 15 | 16 | int n = grpInd.size(); 17 | int ii; 18 | arma::mat Pa, XNaXinv; 19 | Rcpp::NumericVector covratio ( n ); 20 | 21 | for(ii=0; ii 2 | using namespace Rcpp; 3 | 4 | // [[Rcpp::depends(RcppArmadillo)]] 5 | 6 | extern "C" SEXP covtraceCalc(SEXP index, SEXP X_, SEXP P_, 7 | SEXP Vinv_, SEXP XVXinv_) { 8 | Rcpp::List grpInd(index); 9 | arma::mat X = Rcpp::as(X_); 10 | arma::mat P = Rcpp::as(P_); 11 | arma::mat Vinv = Rcpp::as(Vinv_); 12 | arma::mat XVXinv = Rcpp::as(XVXinv_); 13 | 14 | arma::mat Xt = trans(X); 15 | arma::mat XVX = inv(XVXinv); 16 | 17 | int n = grpInd.size(), p = X.n_cols; 18 | int ii; 19 | arma::mat Pa, XNaXinv; 20 | Rcpp::NumericVector covtrace ( n ); 21 | 22 | for(ii=0; ii 2 | using namespace Rcpp; 3 | 4 | // [[Rcpp::depends(RcppArmadillo)]] 5 | 6 | extern "C" SEXP cxxmatsub(SEXP BB, SEXP CC) { 7 | arma::mat B = Rcpp::as(BB); 8 | arma::mat C = Rcpp::as(CC); 9 | return Rcpp::wrap(B - C); 10 | } -------------------------------------------------------------------------------- /src/mdffits_subset.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace Rcpp; 3 | 4 | // [[Rcpp::depends(RcppArmadillo)]] 5 | 6 | extern "C" SEXP mdffitsSubset(SEXP index, SEXP X_, SEXP P_, 7 | SEXP Vinv_, SEXP XVXinv_, SEXP e_) { 8 | Rcpp::List grpInd(index); 9 | arma::mat X = Rcpp::as(X_); 10 | arma::mat P = Rcpp::as(P_); 11 | arma::mat Vinv = Rcpp::as(Vinv_); 12 | arma::mat XVXinv = Rcpp::as(XVXinv_); 13 | arma::colvec e = Rcpp::as(e_); 14 | 15 | arma::mat Xt = trans(X); 16 | 17 | int n = grpInd.size(), p = X.n_cols; 18 | int ii; 19 | arma::mat Pa, Na, XNaXinv, XNaX; 20 | arma::colvec cdd; 21 | Rcpp::NumericVector mdffits ( n ); 22 | Rcpp::List beta_cdd ( n ); 23 | 24 | for(ii=0; ii 7 | %\VignetteIndexEntry{Updated JSS code} 8 | %\VignetteEncoding{UTF-8} 9 | %\VignetteEngine{knitr::rmarkdown_notangle} 10 | editor_options: 11 | chunk_output_type: console 12 | --- 13 | 14 | ```{r, include = FALSE} 15 | is_check <- ("CheckExEnv" %in% search()) || any(c("_R_CHECK_TIMINGS_", 16 | "_R_CHECK_LICENSE_") %in% names(Sys.getenv())) 17 | 18 | knitr::opts_chunk$set( 19 | collapse = TRUE, 20 | comment = "#>", 21 | fig.show = "hide", 22 | eval = !is_check 23 | ) 24 | ``` 25 | 26 | # Preliminaries 27 | 28 | ```{r} 29 | library(HLMdiag) 30 | library(ggplot2) 31 | library(lme4) 32 | ``` 33 | 34 | 35 | # Exam data 36 | 37 | ```{r} 38 | data("Exam", package = "mlmRev") 39 | head(Exam) 40 | ``` 41 | 42 | 43 | # Residual analysis 44 | 45 | ```{r} 46 | # Model fm1 on page 6 47 | (fm1 <- lmer(normexam ~ standLRT + (1 | school), Exam, REML = FALSE)) 48 | 49 | # Extract level-1 residuals 50 | # Residual plot from page 7 51 | resid_fm1 <- hlm_resid(fm1) 52 | head(resid_fm1) 53 | 54 | ggplot(resid_fm1, aes(x = standLRT, y = .ls.resid)) + 55 | geom_point() + 56 | geom_smooth() + 57 | labs(y = "LS level-1 residuals") 58 | ``` 59 | 60 | ```{r} 61 | # Model fm2 on page 7 62 | fm2 <- lmer(normexam ~ standLRT + I(standLRT^2) + I(standLRT^3) + 63 | (1 | school), Exam, REML = FALSE) 64 | 65 | 66 | resid_fm2 <- hlm_resid(fm2) 67 | 68 | 69 | # Figure 2 page 8 70 | ggplot(resid_fm2, aes(x = `I(standLRT^2)`, y = .ls.resid)) + 71 | geom_hline(yintercept = 0, color = "blue") + 72 | geom_point() + 73 | labs( y = "LS residuals", x = "standLRT2") 74 | ``` 75 | 76 | 77 | `ggplot_qqnorm()` function is now defunct, Q-Q plots are now much easier to create in **ggplot2** directly than when the package was first created. 78 | 79 | ```{r} 80 | ggplot(resid_fm2, aes(sample = .ls.resid)) + 81 | geom_qq() + 82 | geom_qq_line() + 83 | labs(x = "Theoretical Quantiles", y = "Sample Quantiles") 84 | ``` 85 | 86 | A better alternative if found in the **qqplotr** package 87 | ```{r} 88 | library(qqplotr) 89 | ggplot(resid_fm2, aes(sample = .ls.resid)) + 90 | stat_qq_band() + 91 | stat_qq_line() + 92 | stat_qq_point() + 93 | labs(x = "Theoretical Quantiles", y = "Sample Quantiles") 94 | ``` 95 | 96 | EB residuals are now called `.ranef.` residuals 97 | 98 | ```{r} 99 | # Model fm3, page 11 100 | fm3 <- lmer(normexam ~ standLRT + I(standLRT^2) + I(standLRT^3) + sex + 101 | (standLRT | school), Exam, REML = FALSE) 102 | 103 | ## Extract level-2 EB residuals 104 | resid_fm3 <- hlm_resid(fm3, level = "school") 105 | resid_fm3 106 | ``` 107 | 108 | ```{r message=FALSE} 109 | ## Construct school-level data set 110 | library(dplyr) 111 | SchoolExam <- Exam %>% 112 | group_by(school) %>% 113 | dplyr::summarize( 114 | size = length(school), 115 | schgend = unique(schgend), 116 | schavg = unique(schavg), 117 | type = unique(type), 118 | schLRT = mean(standLRT) 119 | ) 120 | 121 | SchoolExam <- SchoolExam %>% left_join(resid_fm3, by = "school") 122 | SchoolExam 123 | 124 | ## Left panel -- figure 5 125 | ggplot( 126 | SchoolExam, 127 | aes( 128 | x = reorder(schgend, .ranef.intercept, median), 129 | y = .ranef.intercept) 130 | ) + 131 | geom_boxplot() + 132 | labs(x = "school gender", y = "level-2 residual (Intercept)") 133 | 134 | ## Right panel -- figure 5 135 | ggplot(SchoolExam, aes(x = schavg, y = .ranef.intercept)) + 136 | geom_point() + 137 | geom_smooth() + 138 | labs(x = "average intake score", y = "level-2 residual (Intercept)") 139 | ``` 140 | 141 | ```{r} 142 | ## Model fm4, page 12 143 | fm4 <- lmer(normexam ~ standLRT + I(standLRT^2) + I(standLRT^3) + 144 | sex + schgend + schavg + (standLRT | school), 145 | data = Exam, REML = FALSE) 146 | 147 | resid_fm4 <- hlm_resid(fm4, level = "school", include.ls = FALSE) 148 | 149 | ## Figure 6, page 13 150 | ggplot(resid_fm4, aes(sample = .ranef.intercept)) + 151 | stat_qq_band() + 152 | stat_qq_line() + 153 | stat_qq_point() + 154 | labs(x = "Theoretical Quantiles", y = "Sample Quantiles") 155 | 156 | ggplot(resid_fm4, aes(sample = .ranef.stand_lrt)) + 157 | stat_qq_band() + 158 | stat_qq_line() + 159 | stat_qq_point() + 160 | labs(x = "Theoretical Quantiles", y = "Sample Quantiles") 161 | 162 | ``` 163 | 164 | 165 | # Influence analysis 166 | 167 | We can now use `hlm_influence` to pull off all of the case-deletion diagnostics for the fixed effects at the specified level: 168 | 169 | ```{r} 170 | # Calculating influence diagnostics for model fm4 171 | influence_fm4 <- hlm_influence(fm4, level = "school") 172 | influence_fm4 173 | 174 | dotplot_diag(influence_fm4$cooksd, cutoff = "internal", name = "cooks.distance") 175 | dotplot_diag(influence_fm4$cooksd, cutoff = "internal", name = "cooks.distance", modify = "dotplot") 176 | ``` 177 | 178 | ```{r} 179 | beta_cdd <- cooks.distance(fm4, level = "school", include.attr = TRUE) 180 | beta_cdd[25,] 181 | ``` 182 | 183 | 184 | ## Diagnostics for variance components 185 | 186 | To calculate the relative variance change, we use `hlm_influence()`, but `approx = FALSE` must be specified: 187 | 188 | ```{r eval=FALSE} 189 | hlm_influence(fm4, approx = FALSE) 190 | ``` 191 | 192 | --------------------------------------------------------------------------------