├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── rhub.yaml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── DESCRIPTION ├── NAMESPACE ├── NEWS ├── R ├── afex-package.R ├── afex_plot.R ├── afex_plot_plotting_functions.R ├── afex_plot_utils.R ├── aov_car.R ├── compare.2.vectors.R ├── deprecated.R ├── ems.R ├── fhch2010-data.R ├── helpers.R ├── ks2013.3-data.R ├── laptop_urry-data.R ├── lmerTest_utils.R ├── md_12.1-data.R ├── md_15.1-data.R ├── md_16.1-data.R ├── md_16.4-data.R ├── methods.afex_aov.R ├── mixed.R ├── nice.R ├── obk.long-data.R ├── predict.R ├── reexport.R ├── residuals.R ├── round_ps.R ├── set_contrasts.R ├── sk2011.1-data.R ├── sk2011.2-data.R ├── stroop-data.R ├── utils.R └── zzz.R ├── README.Rmd ├── README.md ├── afex.Rproj ├── data ├── fhch2010.rda ├── ks2013.3.rda ├── laptop_urry.rda ├── md_12.1.rda ├── md_15.1.rda ├── md_16.1.rda ├── md_16.4.rda ├── obk.long.rda ├── sk2011.1.rda ├── sk2011.2.rda └── stroop.rda ├── dev.R ├── development ├── GLMMtest.zip ├── afex_0.28-0.tar.gz ├── afex_0.28-1.tar.gz ├── afex_1.0-0.tar.gz ├── afex_1.0-1.tar.gz ├── afex_1.1-0.tar.gz ├── afex_1.1-1.tar.gz ├── afex_1.2-0.tar.gz ├── afex_1.2-1.tar.gz ├── afex_1.3-0.tar.gz ├── afex_1.3-1.tar.gz ├── afex_1.4-1.tar.gz ├── dataset.RDS ├── emmeans_ses.R ├── freeman_models.R ├── freeman_models.rda ├── potential_bug.R └── stroop_mixed.rda ├── doc ├── introduction-mixed-models.R └── introduction-mixed-models.pdf ├── examples ├── examples.afex_plot.R ├── examples.allFit.R ├── examples.aov_car.R ├── examples.compare.R ├── examples.ems.R ├── examples.fhch2010.R ├── examples.helpers.R ├── examples.ks2013.3.R ├── examples.mixed.R ├── examples.nice.R ├── examples.predict.R ├── examples.residuals.R └── examples.sk2011.2.R ├── inst └── extdata │ ├── output_afex_plot_mixed_vignette.rda │ ├── output_afex_plot_mixed_vignette_model.rda │ ├── output_mixed_vignette.rda │ ├── outputs_glmm_vignette.rda │ ├── plots_brms.rda │ ├── plots_rstanarm.rda │ └── tmb_example_fit.rda ├── man ├── afex-package.Rd ├── afex_aov-methods.Rd ├── afex_options.Rd ├── afex_plot.Rd ├── aov_car.Rd ├── compare.2.vectors.Rd ├── deprecated.Rd ├── ems.Rd ├── fhch2010.Rd ├── figures │ ├── README-unnamed-chunk-17-1.png │ ├── README-unnamed-chunk-18-1.png │ ├── README-unnamed-chunk-19-1.png │ ├── README-unnamed-chunk-6-1.png │ └── README-unnamed-chunk-7-1.png ├── ks2013.3.Rd ├── laptop_urry.Rd ├── md_12.1.Rd ├── md_15.1.Rd ├── md_16.1.Rd ├── md_16.4.Rd ├── mixed.Rd ├── nice.Rd ├── obk.long.Rd ├── predict.afex_aov.Rd ├── reexports.Rd ├── residuals.afex_aov.Rd ├── round_ps.Rd ├── set_sum_contrasts.Rd ├── sk2011.1.Rd ├── sk2011.2.Rd └── stroop.Rd ├── tests ├── testthat.R └── testthat │ ├── _snaps │ ├── afex_plot-basics │ │ ├── afex-plot-connecting-individual-points-works.svg │ │ ├── geoms-work-box-plot.svg │ │ ├── geoms-work-boxjitter-1.svg │ │ ├── geoms-work-boxjitter-2.svg │ │ ├── geoms-work-boxjitter-3.svg │ │ ├── geoms-work-geom-count.svg │ │ ├── geoms-work-ggbeeswarm-geom-beeswarm.svg │ │ ├── geoms-work-ggbeeswarm-geom-quasirandom.svg │ │ ├── geoms-work-jitterdodge.svg │ │ ├── geoms-work-violin-with-colour.svg │ │ ├── geoms-work-violin.svg │ │ ├── lme4-mermod-plot-1.svg │ │ ├── lme4-mermod-plot-2.svg │ │ ├── lme4-mermod-plot-3.svg │ │ ├── mixed-model-1.svg │ │ ├── mixed-model-2.svg │ │ ├── mixed-model-3.svg │ │ ├── mixed-model-4.svg │ │ ├── multiple-geoms-work-1.svg │ │ ├── multiple-geoms-work-2.svg │ │ ├── one-way-within.svg │ │ ├── plot-first-for-afex-plot-works-1.svg │ │ ├── plot-first-for-afex-plot-works-2.svg │ │ ├── plot-first-for-afex-plot-works-3.svg │ │ ├── plot-first-for-afex-plot-works-4.svg │ │ ├── two-way.svg │ │ └── x-trace-panel.svg │ ├── afex_plot-bugs │ │ ├── afex-plot-binomial-glm-with-factor-2.svg │ │ ├── afex-plot-binomial-glm-with-factor.svg │ │ ├── afex-plot-dv-y-works.svg │ │ ├── afex-plot-lmm-type-2.svg │ │ └── afex-plot-mermod-objects-with-missing-data.svg │ ├── afex_plot-default-support │ │ ├── afex-plots-binomial-glm-1.svg │ │ ├── afex-plots-binomial-glm-2.svg │ │ ├── afex-plots-lm-model-1.svg │ │ ├── afex-plots-lm-model-2.svg │ │ ├── afex-plots-nlme-1.svg │ │ ├── afex-plots-nlme-2.svg │ │ ├── afex-plots-nlme-3.svg │ │ ├── afex-plots-nlme-4.svg │ │ ├── afex-plots-nlme-5.svg │ │ ├── afex-plots-poisson-glm-1.svg │ │ └── afex-plots-poisson-glm-2.svg │ └── afex_plot-vignette │ │ ├── afex-plot-glmmtmb-1.svg │ │ ├── afex-plot-glmmtmb-2.svg │ │ └── afex-plot-glmmtmb-3.svg │ ├── afex_aov_16_1.rda │ ├── afex_plot-brms.rda │ ├── afex_plot-rstanarm.rda │ ├── anova_hf_error.rda │ ├── helper-vdiffr.R │ ├── lmm_old_object.rda │ ├── m_machines_lmerTest-pre3.0.rda │ ├── mixed_with_dot.rda │ ├── skf_issue.csv │ ├── test-afex_aov.R │ ├── test-afex_plot-basics.R │ ├── test-afex_plot-bugs.R │ ├── test-afex_plot-default-support.R │ ├── test-afex_plot-vignette.R │ ├── test-aov_car-basic.R │ ├── test-aov_car-bugs.R │ ├── test-aov_car-structural.R │ ├── test-compare_2_vectors.R │ ├── test-emmeans-interface.R │ ├── test-lmerTest-support.R │ ├── test-mixed-bugs.R │ ├── test-mixed-effects.R │ ├── test-mixed-mw.R │ ├── test-mixed-structure.R │ ├── test-predict.R │ └── test-residuals.R └── vignettes ├── .gitignore ├── afex_analysing_accuracy_data.Rmd ├── afex_anova_example.Rmd ├── afex_mixed_example.Rmd ├── afex_plot_introduction.Rmd ├── afex_plot_supported_models.Rmd ├── assumptions_of_ANOVAs.Rmd ├── introduction-mixed-models.pdf └── introduction-mixed-models.pdf.asis /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^Meta$ 2 | ^doc$ 3 | ^.*\.Rproj$ 4 | ^\.Rproj\.user$ 5 | afex-Ex.R 6 | examples 7 | dev.R 8 | ^CONDUCT\.md$ 9 | ^\.travis\.yml$ 10 | revdep 11 | Rplots.pdf 12 | ^development$ 13 | ^README\.Rmd$ 14 | ^CODE_OF_CONDUCT\.md$ 15 | ^\.github$ 16 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.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 | Meta 2 | # History files 3 | .Rhistory 4 | .Rapp.history 5 | 6 | # Example code in package build process 7 | *-Ex.R 8 | # RStudio files 9 | .Rproj.user/ 10 | Rplots.pdf 11 | # produced vignettes 12 | vignettes/*.html 13 | .Rproj.user 14 | # revdep folder 15 | revdep 16 | inst/doc 17 | /doc/ 18 | /Meta/ 19 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the overall 26 | community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards 42 | of acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies 54 | when an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail 56 | address, posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at [INSERT CONTACT 63 | METHOD]. All complaints will be reviewed and investigated promptly and fairly. 64 | 65 | All community leaders are obligated to respect the privacy and security of the 66 | reporter of any incident. 67 | 68 | ## Enforcement Guidelines 69 | 70 | Community leaders will follow these Community Impact Guidelines in determining 71 | the consequences for any action they deem in violation of this Code of Conduct: 72 | 73 | ### 1. Correction 74 | 75 | **Community Impact**: Use of inappropriate language or other behavior deemed 76 | unprofessional or unwelcome in the community. 77 | 78 | **Consequence**: A private, written warning from community leaders, providing 79 | clarity around the nature of the violation and an explanation of why the 80 | behavior was inappropriate. A public apology may be requested. 81 | 82 | ### 2. Warning 83 | 84 | **Community Impact**: A violation through a single incident or series of 85 | actions. 86 | 87 | **Consequence**: A warning with consequences for continued behavior. No 88 | interaction with the people involved, including unsolicited interaction with 89 | those enforcing the Code of Conduct, for a specified period of time. This 90 | includes avoiding interactions in community spaces as well as external channels 91 | like social media. Violating these terms may lead to a temporary or permanent 92 | ban. 93 | 94 | ### 3. Temporary Ban 95 | 96 | **Community Impact**: A serious violation of community standards, including 97 | sustained inappropriate behavior. 98 | 99 | **Consequence**: A temporary ban from any sort of interaction or public 100 | communication with the community for a specified period of time. No public or 101 | private interaction with the people involved, including unsolicited interaction 102 | with those enforcing the Code of Conduct, is allowed during this period. 103 | Violating these terms may lead to a permanent ban. 104 | 105 | ### 4. Permanent Ban 106 | 107 | **Community Impact**: Demonstrating a pattern of violation of community 108 | standards, including sustained inappropriate behavior, harassment of an 109 | individual, or aggression toward or disparagement of classes of individuals. 110 | 111 | **Consequence**: A permanent ban from any sort of public interaction within the 112 | community. 113 | 114 | ## Attribution 115 | 116 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 117 | version 2.0, 118 | available at https://www.contributor-covenant.org/version/2/0/ 119 | code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at https:// 128 | www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: afex 2 | Type: Package 3 | Title: Analysis of Factorial Experiments 4 | Depends: R (>= 3.5.0), lme4 (>= 1.1-8) 5 | Suggests: 6 | emmeans (>= 1.4), 7 | coin, 8 | xtable, 9 | parallel, 10 | plyr, 11 | optimx, 12 | nloptr, 13 | knitr, 14 | rmarkdown, 15 | R.rsp, 16 | lattice, 17 | latticeExtra, 18 | multcomp, 19 | testthat, 20 | mlmRev, 21 | dplyr, 22 | tidyr, 23 | dfoptim, 24 | Matrix, 25 | psychTools, 26 | ggplot2, 27 | MEMSS, 28 | effects, 29 | carData, 30 | ggbeeswarm, 31 | nlme, 32 | cowplot, 33 | jtools, 34 | ggpubr, 35 | ggpol, 36 | MASS, 37 | glmmTMB, 38 | brms, 39 | rstanarm, 40 | statmod, 41 | performance (>= 0.7.2), 42 | see (>= 0.6.4), 43 | ez, 44 | ggResidpanel, 45 | grid, 46 | vdiffr 47 | Imports: pbkrtest (>= 0.4-1), lmerTest (>= 3.0-0), car, reshape2, stats, methods, utils, reformulas 48 | Description: Convenience functions for analyzing factorial experiments using ANOVA or 49 | mixed models. aov_ez(), aov_car(), and aov_4() allow specification of 50 | between, within (i.e., repeated-measures), or mixed (i.e., split-plot) 51 | ANOVAs for data in long format (i.e., one observation per row), 52 | automatically aggregating multiple observations per individual and cell 53 | of the design. mixed() fits mixed models using lme4::lmer() and computes 54 | p-values for all fixed effects using either Kenward-Roger or Satterthwaite 55 | approximation for degrees of freedom (LMM only), parametric bootstrap 56 | (LMMs and GLMMs), or likelihood ratio tests (LMMs and GLMMs). 57 | afex_plot() provides a high-level interface for interaction or one-way 58 | plots using ggplot2, combining raw data and model estimates. afex uses 59 | type 3 sums of squares as default (imitating commercial statistical software). 60 | URL: https://afex.singmann.science/, https://github.com/singmann/afex 61 | BugReports: https://github.com/singmann/afex/issues 62 | License: GPL (>=2) 63 | Encoding: UTF-8 64 | VignetteBuilder: knitr, R.rsp 65 | Authors@R: c(person(given="Henrik", family="Singmann", role=c("aut", "cre"), 66 | email="singmann@gmail.com", comment=c(ORCID="0000-0002-4842-3657")), 67 | person(given="Ben", family="Bolker", role=c("aut")), 68 | person(given="Jake",family="Westfall", role=c("aut")), 69 | person(given="Frederik", family="Aust", role=c("aut"), 70 | comment = c(ORCID = "0000-0003-4900-788X")), 71 | person(given="Mattan S.",family="Ben-Shachar", role=c("aut")), 72 | person(given="Søren", family="Højsgaard", role=c("ctb")), 73 | person(given="John", family="Fox", role=c("ctb")), 74 | person(given="Michael A.", family="Lawrence", role=c("ctb")), 75 | person(given="Ulf", family="Mertens", role=c("ctb")), 76 | person(given="Jonathon", family="Love", role=c("ctb")), 77 | person(given="Russell", family="Lenth", role=c("ctb")), 78 | person(given="Rune", family="Haubo Bojesen Christensen", role=c("ctb"))) 79 | Version: 1.5-0 80 | RoxygenNote: 7.3.2 81 | LazyData: true 82 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(afex_plot,afex_aov) 4 | S3method(afex_plot,default) 5 | S3method(afex_plot,merMod) 6 | S3method(afex_plot,mixed) 7 | S3method(anova,afex_aov) 8 | S3method(anova,mixed) 9 | S3method(fitted,afex_aov) 10 | S3method(nice,afex_aov) 11 | S3method(nice,anova) 12 | S3method(nice,mixed) 13 | S3method(predict,afex_aov) 14 | S3method(print,afex_aov) 15 | S3method(print,mixed) 16 | S3method(print,nice_table) 17 | S3method(residuals,afex_aov) 18 | S3method(summary,afex_aov) 19 | S3method(summary,mixed) 20 | export(afex_options) 21 | export(afex_plot) 22 | export(aov_4) 23 | export(aov_car) 24 | export(aov_ez) 25 | export(compare.2.vectors) 26 | export(ems) 27 | export(interaction_plot) 28 | export(lmer) 29 | export(lmer_alt) 30 | export(mixed) 31 | export(nice) 32 | export(oneway_plot) 33 | export(round_ps) 34 | export(round_ps_apa) 35 | export(set_default_contrasts) 36 | export(set_deviation_contrasts) 37 | export(set_effects_contrasts) 38 | export(set_sum_contrasts) 39 | export(set_treatment_contrasts) 40 | export(test_levene) 41 | export(test_sphericity) 42 | importFrom(car,Anova) 43 | importFrom(lme4,getME) 44 | importFrom(lme4,glmer) 45 | importFrom(lme4,isREML) 46 | importFrom(lmerTest,lmer) 47 | importFrom(methods,as) 48 | importFrom(methods,is) 49 | importFrom(parallel,clusterApplyLB) 50 | importFrom(parallel,clusterCall) 51 | importFrom(parallel,clusterEvalQ) 52 | importFrom(parallel,clusterExport) 53 | importFrom(reformulas,findbars) 54 | importFrom(reformulas,nobars) 55 | importFrom(reshape2,dcast) 56 | importFrom(stats,"contrasts<-") 57 | importFrom(stats,aggregate) 58 | importFrom(stats,anova) 59 | importFrom(stats,as.formula) 60 | importFrom(stats,coef) 61 | importFrom(stats,fitted) 62 | importFrom(stats,formula) 63 | importFrom(stats,logLik) 64 | importFrom(stats,model.frame) 65 | importFrom(stats,model.matrix) 66 | importFrom(stats,p.adjust) 67 | importFrom(stats,predict) 68 | importFrom(stats,qt) 69 | importFrom(stats,reshape) 70 | importFrom(stats,residuals) 71 | importFrom(stats,sd) 72 | importFrom(stats,setNames) 73 | importFrom(stats,symnum) 74 | importFrom(stats,t.test) 75 | importFrom(stats,terms) 76 | importFrom(stats,wilcox.test) 77 | importFrom(stats,xtabs) 78 | importFrom(utils,head) 79 | importFrom(utils,packageVersion) 80 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Changes in afex Version 1.5-x (2025-05-xx) 2 | Significant User Visible Changes and New Features 3 | o 4 | 5 | Bugfixes 6 | o functions findbars() and nobars() are now imported from package reformulas instead of lme4 [GH issue #132] 7 | 8 | Changes in afex Version 1.4-x (2024-xx-xx) 9 | 10 | Significant User Visible Changes and New Features 11 | o Added plot_first argument to afex_plot(), which allows passing ggplot2 geom's which will be plotted first, before any other graphical elements. This allows plotting reference lines in the background of the plot, e.g. using geom_hline(). 12 | 13 | Bugfixes 14 | o Address #87 hopefully increasing speed of emmeans() for mixed objects significantly. 15 | 16 | Changes in afex Version 1.3-1 (2024-02-25) 17 | 18 | Bugfixes 19 | o prepared afex for ggplot2 version 3.5.0 20 | 21 | 22 | Changes in afex Version 1.3-x (2023-04-18) 23 | 24 | Significant User Visible Changes and New Features 25 | o Nicer warning if there is missing data for ANOVA models. 26 | o Removed all_fit() function. mixed(..., all_fit = TRUE) now uses lme4::allFit(). In case you have relied on all_fit() use lme4::allFit(). 27 | o Removed support for deprecated ANOVA functions aov.car, aov.ez, and aov4. Instead use aov_car(), aov_ez(), and aov_4(). 28 | 29 | Bugfixes 30 | o Updates to documentation in various places. 31 | o Using vdiffr for unit tests of afex_plot 32 | o Fixed broken link to www.talkstats.com (replaced with link in web.archive.org) 33 | 34 | Changes in afex Version 1.2-x (2022-10-30) 35 | 36 | Significant User Visible Changes and New Features 37 | o Multiple geoms for data in the background can now be passed to afex_plot() as a list. Likewise, for each geom, a separate list of additional arguments can be passed as a list of lists to data_arg. 38 | o afex_plot() gets a new argument, data_color with default "darkgrey". Like data_alpha for alpha, data_color sets the colour for the geom (or now geoms) used to plot the data in the background. 39 | o Both data_color and data_alpha can now be set to NULL, in which case they will not be set but should be set by the user through data_arg. 40 | 41 | Bugfixes 42 | o Data in mixed() output is shown nicer (#113) 43 | o afex_plot() should now work with factor_levels arguments even if corresponding variable is not a factor in the data. 44 | o Resaved plots for new version of ggbeeswarm (#117). 45 | 46 | Changes in afex Version 1.1-x (2022-03-30) 47 | 48 | Significant User Visible Changes and New Features 49 | o Fitting messages for mixed() are now only shown per default in interactive mode, thanks to Marius Barth (#111). 50 | o Nicer error message about missing variables for ANOVAs. 51 | o Removed check_contrasts() argument for ANOVAs, which did not work as described for designs with repeated-measures factors: https://github.com/singmann/afex/issues/109 52 | 53 | Bugfixes 54 | o Fixed overzealous data completeness check introduced in version 1.0 in aov_car() which prevented ANOVAs with additive factors and no cross over data from working. 55 | o mixed(..., method = "LRT") and similar nested methods should work with empty factor levels: https://github.com/singmann/afex/issues/96 56 | 57 | Changes in afex Version 1.0-x (2021-07-02) 58 | 59 | Significant User Visible Changes and New Features 60 | o ANOVA objects do not by default contain the aov slot any more 61 | o emmeans() for ANOVA now uses multivariate model as default 62 | o Default p-value method for mixed() is now Satterthwaite: method = "S" 63 | o New data set, Urry et al. (2021, Psych Science): laptop_urry 64 | 65 | The following changes are thanks to Mattan S. Ben-Shachar: 66 | o Added new vignette: "Testing the Assumptions of ANOVAs" 67 | o Added predict() method for afex_aov objects. 68 | o Deprecated functions test_levene() and test_sphercitiy(), which are now part of the performance package as performance::check_homogeneity() and performance::check_sphericity(), respectively. 69 | 70 | Bugfixes 71 | o All vignettes should run without suggested packages present. 72 | o Added ez to suggests, to avoid NOTE on CRAN solaris. 73 | -------------------------------------------------------------------------------- /R/afex-package.R: -------------------------------------------------------------------------------- 1 | #' \packageDescription{afex} 2 | #' 3 | #' The DESCRIPTION file: 4 | #' \packageDESCRIPTION{afex} 5 | #' 6 | #' @title 7 | #' \packageTitle{afex} 8 | #' 9 | "_PACKAGE" 10 | -------------------------------------------------------------------------------- /R/deprecated.R: -------------------------------------------------------------------------------- 1 | #' Deprecated functions 2 | #' 3 | #' These functions have been renamed or moved and deprecated in \pkg{afex}: 4 | #' \code{test_levene()} (use \code{\link[performance]{check_homogeneity}()}), 5 | #' \code{test_sphericity()} (use \code{\link[performance]{check_sphericity}()}). 6 | #' @rdname deprecated 7 | #' @keywords internal 8 | #' @aliases afex-deprecated 9 | #' @param ... arguments passed from the old functions of the style 10 | #' \code{foo.bar()} to the new functions \code{foo_bar()} 11 | #' @export 12 | test_levene <- function(...){ 13 | .Deprecated("check_homogeneity", "afex", "Functionality has moved to the 'performance' package.\nCalling 'performance::check_homogeneity()'.") 14 | performance::check_homogeneity(...) 15 | } 16 | 17 | #' @rdname deprecated 18 | #' @export 19 | test_sphericity<- function(...){ 20 | .Deprecated("check_sphericity", "afex", "Functionality has moved to the 'performance' package.\nCalling 'performance::check_sphericity()'.") 21 | performance::check_sphericity(...) 22 | } 23 | 24 | 25 | 26 | warn_deprecated_arg <- function(name, instead) { 27 | warning(gettextf("'%s' is deprecated; use '%s' instead", name, instead), 28 | call.=FALSE, domain=NA) 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /R/ems.R: -------------------------------------------------------------------------------- 1 | #' Expected values of mean squares for factorial designs 2 | #' 3 | #' Implements the Cornfield-Tukey algorithm for deriving the expected values of the mean squares for factorial designs. 4 | #' 5 | #' @param design A \code{formula} object specifying the factors in the design (except residual error, which is always implicitly included). The left hand side of the \code{~} is the symbol that will be used to denote the number of replications per lowest-level factor combination (I usually use "r" or "n"). The right hand side should include all fixed and random factors separated by \code{*}. Factor names should be single letters. 6 | #' @param nested A \code{character} vector, where each element is of the form \code{"A/B"}, indicating that the levels of factor B are nested under the levels of factor A. 7 | #' @param random A \code{character} string indicating, without spaces or any separating characters, which of the factors specified in the design are random. 8 | #' 9 | #' @return The returned value is a formatted table where the rows represent the mean squares, the columns represent the variance components that comprise the various mean squares, and the entries in each cell represent the terms that are multiplied and summed to form the expectation of the mean square for that row. Each term is either the lower-case version of one of the experimental factors, which indicates the number of levels for that factor, or a "1", which means the variance component for that column is contributes to the mean square but is not multiplied by anything else. 10 | #' 11 | #' @note Names for factors or parameters should only be of length 1 as they are simply concatenated in the returned table. 12 | #' 13 | #' @author Jake Westfall 14 | #' 15 | #' @seealso A detailed description with explanation of the example can be found \href{https://web.archive.org/web/20210805121242/http://www.talkstats.com/threads/share-your-functions-code.18603/page-9#post-82050}{elsewhere} (note that the \code{design} argument of the function described at the link behaves slightly different). 16 | #' 17 | #' Example applications of this function can be found here: \url{https://stats.stackexchange.com/a/122662/442}. 18 | #' 19 | #' 20 | #' @example examples/examples.ems.R 21 | #' @export 22 | 23 | 24 | ems <- function(design, nested=NULL, random=""){ 25 | # modify design formula based on nested factors specified 26 | if(!is.null(nested)){ 27 | terms <- attr(terms(design), "term.labels") 28 | # for each nested, get indices of all terms not involving their interaction 29 | keeps <- lapply(strsplit(nested, "/"), function(x){ 30 | which(apply(sapply(x, grepl, terms), 1, function(x) !all(x))) 31 | }) 32 | terms <- terms[Reduce(intersect, keeps)] 33 | formula <- paste(c(as.character(design)[2:1], paste(terms, collapse="+")), collapse="") 34 | design <- eval(parse(text=formula)) 35 | } 36 | 37 | # build two-way table 38 | mat <- t(attr(terms(design), "factors")) 39 | terms <- tolower(as.character(attr(terms(design), "variables"))[-1]) 40 | 41 | # resolve fixed/random dummies 42 | if (!is.null(random)){ 43 | random <- unlist(strsplit(random,split="")) 44 | mat[,which(colnames(mat) %in% random)][mat[, 45 | which(colnames(mat) %in% random)]==1] <- "" 46 | mat[,which(!colnames(mat) %in% random)][mat[, 47 | which(!colnames(mat) %in% random)]==1] <- "fix" 48 | } 49 | 50 | # insert 1 in nested rows 51 | subs <- strsplit(rownames(mat), split=":") 52 | if(!is.null(nested)){ 53 | nested <- strsplit(nested, split="/") 54 | for(term in nested){ 55 | rows <- unlist(lapply(subs, function(x) term[2] %in% x)) 56 | cols <- colnames(mat)==term[1] 57 | mat[rows,cols] <- "1" 58 | } 59 | } 60 | mat <- rbind(mat, e=rep("1", ncol(mat))) 61 | 62 | # insert numbers of levels for remaining cells 63 | for(row in seq(nrow(mat))){ 64 | mat[row,][mat[row,]=="0"] <- tolower(colnames(mat)[mat[row,]=="0"]) 65 | } 66 | 67 | # construct EMS table 68 | ems <- matrix(nrow=nrow(mat), ncol=nrow(mat), 69 | dimnames=list(Effect=rownames(mat), 70 | VarianceComponent=rev(rownames(mat)))) 71 | # add nesting information to subscripts 72 | if (!is.null(nested)){ 73 | subs <- lapply(subs, function(x){ 74 | new <- x 75 | for (nest in seq(length(nested))){ 76 | if (nested[[nest]][2] %in% x) new <- c(new, nested[[nest]][1]) 77 | } 78 | return(new) 79 | }) 80 | } 81 | subs[["e"]] <- colnames(mat)[-1] 82 | names(subs) <- rownames(mat) 83 | # rename #-of-reps variable to 'e' invisibly 84 | colnames(mat)[1] <- "e" 85 | # fill in EMS table 86 | for(effect in rownames(ems)){ 87 | for(varcomp in colnames(ems)){ 88 | effectVec <- unlist(strsplit(effect, ":")) 89 | ans <- mat[varcomp,-1*which(colnames(mat) %in% effectVec)] 90 | if ("fix" %in% ans) ans <- "" 91 | if (all(ans=="1")) ans <- "1" 92 | if (("1" %in% ans | "2" %in% ans) & !all(ans=="1")){ 93 | ans <- ans[!ans %in% c("1","2")] 94 | } 95 | varcompVec <- unlist(strsplit(varcomp, ":")) 96 | if (!all(effectVec %in% subs[[varcomp]])) ans <- "" 97 | if (effect=="e" & varcomp=="e") ans <- "1" 98 | ems[effect,varcomp] <- paste(ans, collapse="") 99 | } 100 | } 101 | attr(ems, "terms") <- terms 102 | return(noquote(ems)) 103 | } 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /R/fhch2010-data.R: -------------------------------------------------------------------------------- 1 | #' Data from Freeman, Heathcote, Chalmers, & Hockley (2010) 2 | #' 3 | #' Lexical decision and word naming latencies for 300 words and 300 nonwords presented in Freeman, Heathcote, Chalmers, and Hockley (2010). The study had one between-subjects factors, \code{"task"} with two levels (\code{"naming"} or \code{"lexdec"}), and four within-subjects factors: \code{"stimulus"} type with two levels (\code{"word"} or \code{"nonword"}), word \code{"density"} and word \code{"frequency"} each with two levels (\code{"low"} and \code{"high"}) and stimulus \code{"length"} with three levels (4, 5, and 6). 4 | #' 5 | #' In the lexical-decision condition (N = 25), subjects indicated whether each item was a word or a nonword, by pressing either the left (labeled word) or right (labeled nonword) outermost button on a 6-button response pad. The next study item appeared immediately after the lexical decision response was given. In the naming condition (N = 20), subjects were asked to name each item aloud, and items remained on screen for 3 s. Naming time was recorded by a voice key. 6 | #' 7 | #' Items consisted of 300 words, 75 in each set making up a factorial combination of high and low density and frequency, and 300 nonwords, with equal numbers of 4, 5, and 6 letter items in each set. 8 | #' 9 | #' 10 | #' @docType data 11 | #' @keywords dataset 12 | #' @name fhch2010 13 | #' @usage fhch2010 14 | #' @format A \code{data.frame} with 13,222 obs. of 9 variables: 15 | #' \describe{ 16 | #' \item{id}{participant id, \code{factor}} 17 | #' \item{task}{\code{factor} with two levels indicating which task was performed: \code{"naming"} or \code{"lexdec"}} 18 | #' \item{stimulus}{\code{factor} indicating whether the shown stimulus was a \code{"word"} or \code{"nonword"}} 19 | #' \item{density}{\code{factor} indicating the neighborhood density of presented items with two levels: \code{"low"} and \code{"high"}. Density is defined as the number of words that differ from a base word by one letter or phoneme.} 20 | #' \item{frequency}{\code{factor} indicating the word frequency of presented items with two levels: \code{"low"} (i.e., words that occur less often in natural language) and \code{"high"} (i.e., words that occur more often in natural language).} 21 | #' \item{length}{\code{factor} with 3 levels (4, 5, or 6) indicating the number of characters of presented stimuli.} 22 | #' \item{item}{\code{factor} with 600 levels: 300 words and 300 nonwords} 23 | #' \item{rt}{response time in seconds} 24 | #' \item{log_rt}{natural logarithm of response time in seconds} 25 | #' \item{correct}{boolean indicating whether or not the response in the lexical decision task was correct or incorrect (incorrect responses of the naming task are not part of the data).} 26 | #' } 27 | #' @source Freeman, E., Heathcote, A., Chalmers, K., & Hockley, W. (2010). Item effects in recognition memory for words. Journal of Memory and Language, 62(1), 1-18. http://doi.org/10.1016/j.jml.2009.09.004 28 | #' 29 | #' @encoding UTF-8 30 | #' 31 | #' @example examples/examples.fhch2010.R 32 | NULL 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /R/helpers.R: -------------------------------------------------------------------------------- 1 | #' Set/get global afex options 2 | #' 3 | #' Global afex options are used, for example, by \code{\link{aov_car}} (et al.) 4 | #' and \code{\link{mixed}}. But can be changed in each functions directly using 5 | #' an argument (which has precedence over the global options). 6 | #' 7 | #' @param ... One of four: (1) nothing, then returns all options as a list; (2) 8 | #' a name of an option element, then returns its' value; (3) a name-value pair 9 | #' which sets the corresponding option to the new value (and returns nothing), 10 | #' (4) a list with option-value pairs which sets all the corresponding 11 | #' arguments. The example show all possible cases. 12 | #' 13 | #' @details The following arguments are currently set: 14 | #' \itemize{ 15 | #' \item \code{check_contrasts} should contrasts be checked and changed to 16 | #' sum-to-zero contrasts? Default is \code{TRUE}. 17 | #' \item \code{type} type of sums-of-squares to be used for testing effects, 18 | #' default is 3 which reports Type 3 tests. 19 | #' \item \code{method_mixed}: Method used to obtain p-values in 20 | #' \code{\link{mixed}}, default is \code{"KR"} (which will change to 21 | #' \code{"LRT"} soon). (\code{mixed()} only) 22 | #' \item \code{es_aov}: Effect size reported for ANOVAs (see 23 | #' \code{\link{aov_car}}), default is \code{"ges"} (generalized eta-squared). 24 | #' \item \code{correction_aov}: Correction used for within-subjects factors with 25 | #' more than two levels for ANOVAs (see \code{\link{aov_car}} or 26 | #' \code{\link{nice}}), default is \code{"GG"} (Greenhouse-Geisser correction). 27 | #' (ANOVA functions only) 28 | #' \item \code{emmeans_model}: Which model should be used by \pkg{emmeans} for 29 | #' follow-up analysis of ANOVAs (i.e., objects pf class \code{"afex_aov"})? 30 | #' Default is \code{"univariate"} which uses the \code{aov} model object (if 31 | #' present). The other option is \code{"multivariate"} which uses the \code{lm} 32 | #' model object (which is an object of class \code{"mlm"} in case 33 | #' repeated-measures factors are present). 34 | #' \item \code{include_aov}: Should the \code{aov} model be included into ANOVA objects of class \code{"afex_aov"}? Setting this to \code{FALSE} can lead to considerable speed improvements. 35 | #' \item \code{factorize}: Should between subject factors be factorized (with 36 | #' note) before running the analysis? Default is \code{TRUE}. (ANOVA functions 37 | #' only) 38 | #' \item \code{sig_symbols}: Default significant symbols used for ANOVA and 39 | #' \code{mixed} printing. Default is\code{c(" +", " *", " **", " ***")}. 40 | #' \item \code{lmer_function}: Which \code{lmer} function should \code{mixed} or 41 | #' \code{lmer_alt} use. The default is \code{"lmerTest"} which uses 42 | #' \code{\link[lmerTest]{lmer}}, \code{"lme4"} is also possible which uses 43 | #' \code{\link[lme4]{lmer}}. Note that \code{mixed} methods \code{"KR"} and 44 | #' \code{"S"} only work with \code{"lmerTest"}. For the other methods, 45 | #' \code{"lme4"} could be minimally faster, but does not allow to use 46 | #' \code{lmerTest::anova()}. 47 | #' \item \code{return_aov}: Return value of the ANOVA functions (see 48 | #' \code{\link{aov_car}}), default is \code{"nice"}. 49 | #' } 50 | #' 51 | #' @note All options are saved in the global R \code{\link{options}} with prefix 52 | #' \code{afex.} 53 | #' 54 | #' @return depends on input, see above. 55 | #' 56 | #' @example examples/examples.helpers.R 57 | #' 58 | #' @export 59 | 60 | # afex_options <- function(...) 61 | # { 62 | # dots <- list(...) 63 | # if (length(dots) == 0) return(ls.str(envir = .afexEnv)) 64 | # else { 65 | # if (!is.null(names(dots))) { 66 | # if (length(dots) > 1) stop("afex_options can only return a single element.") 67 | # for (i in seq_along(dots)) { 68 | # assign(names(dots)[i], dots[[i]], envir = .afexEnv) 69 | # } 70 | # } else return(get(dots[[1]], envir = .afexEnv)) 71 | # } 72 | # } 73 | 74 | afex_options <- function(...) { 75 | dots <- list(...) 76 | #browser() 77 | if (length(dots) == 0) { # branch to get all afex options 78 | op <- options() 79 | afex_op <- op[grepl("^afex.", names(op))] 80 | names(afex_op) <- sub("^afex.", "", names(afex_op)) 81 | return(afex_op) 82 | } else if (is.list(dots[[1]])) { # set several afex options as a list: 83 | newop <- dots[[1]] 84 | names(newop) <- paste0("afex.", names(newop)) 85 | options(newop) 86 | } else if (!is.null(names(dots))) { 87 | newop <- dots 88 | names(newop) <- paste0("afex.", names(newop)) 89 | options(newop) 90 | } else if (is.null(names(dots))) { # get a single afex options 91 | if (length(dots) > 1) stop("afex_options() can only return the value of a single option.", call. = FALSE) 92 | return(getOption(paste0("afex.", unlist(dots)))) 93 | } else { 94 | warning("Unsopported command to afex_options(), nothing done.", call. = FALSE) 95 | } 96 | } 97 | 98 | -------------------------------------------------------------------------------- /R/ks2013.3-data.R: -------------------------------------------------------------------------------- 1 | #' Data from Klauer & Singmann (2013, Experiment 3) 2 | #' 3 | #' Klauer and Singmann (2013) attempted to replicate an hypothesis of Morsanyi and Handley (2012) according to which individuals have an intuitive sense of logicality. Specifically, Morsanyi and Handley apparently provided evidence that the logical status of syllogisms (i.e., valid or invalid) affects participants liking ratings of the conclusion of syllogisms. Conclusions from valid syllogisms (e.g., Some snakes are poisonous. No poisonous animals are obbs. Some snakes are not obbs.) received higher liking ratings than conclusions from invalid syllogisms (e.g., No ice creams are vons. Some vons are hot. Some ice creams are not hot.). It is important to noted that in the experiments participants were simply shown the premises and conclusion in succession, they were not asked whether or not the conclusion follows or to generate their own conclusion. Their task was simply to judge how much they liked the "final" statement (i.e., the conclusion). 4 | #' 5 | #' In their Experiment 3 Klauer and Singmann (2013) tested the idea that this finding was a consequence of the materials used and not an effect intuitive logic. More specifically, they observed that in the original study by Morsanyi and Handley (2012) a specific content always appeared with the same logical status. For example, the "ice-cream" content only ever appeared as an invalid syllogism as in the example above but never in a valid syllogism. In other words, content was perfectly confounded with logical status in the original study. To test this they compared a condition in which the logical status was confounded with the content (the "fixed" condition) with a condition in which the contents were randomly assigned to a logical status across participants (the "random" condition). For example, the ice-cream content was, across participants, equally like to appear in the invalid form as given above or in the following valid form: No hot things are vons. Some vons are ice creams. Conclusion Some ice creams are not hot. 6 | #' 7 | #' The data.frame contains the raw responses of all 60 participants (30 per condition) reported in Klauer & Singmann (2013). Each participants provided 24 responses, 12 to valid and 12 to invalid syllogisms. Furthermore, 8 syllogisms had a believable conclusion (e.g., Some ice creams are not hot.), 8 had an abstract conclusion (e.g., Some snakes are not obbs.), and 8 had an unbelievable conclusion (e.g., Some animals are not monkeys.). The number of the contents corresponds to the numbering given in Morsanyi and Handley (2012, p. 616). 8 | #' 9 | #' 10 | #' @docType data 11 | #' @keywords dataset 12 | #' @name ks2013.3 13 | #' @usage ks2013.3 14 | #' @format A data.frame with 1440 rows and 6 variables. 15 | #' @source Klauer, K. C., & Singmann, H. (2013). Does logic feel good? Testing for intuitive detection of logicality in syllogistic reasoning. Journal of Experimental Psychology: Learning, Memory, and Cognition, 39(4), 1265-1273. http://doi.org/10.1037/a0030530 16 | #' 17 | #' Morsanyi, K., & Handley, S. J. (2012). Logic feels so good-I like it! Evidence for intuitive detection of logicality in syllogistic reasoning. Journal of Experimental Psychology: Learning, Memory, and Cognition, 38(3), 596-616. http://doi.org/10.1037/a0026099 18 | #' 19 | #' 20 | #' 21 | #' 22 | #' @encoding UTF-8 23 | #' 24 | #' @example examples/examples.ks2013.3.R 25 | NULL 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /R/laptop_urry-data.R: -------------------------------------------------------------------------------- 1 | #' Replication of Laptop Note Taking Study (Urry et al. 2021, Psych. Science) 2 | #' 3 | #' Original abstract: 4 | #' In this direct replication of Mueller and Oppenheimer’s (2014) Study 1, 5 | #' participants watched a lecture while taking notes with a laptop (n = 74) or 6 | #' longhand (n = 68). After a brief distraction and without the opportunity to 7 | #' study, they took a quiz. As in the original study, laptop participants took 8 | #' notes containing more words spoken verbatim by the lecturer and more words 9 | #' overall than did longhand participants. However, laptop participants did not 10 | #' perform better than longhand participants on the quiz. 11 | #' 12 | #' Own description: 13 | #' 14 | #' Heather Urry and 87 of her undergraduate and graduate students (yes, all 87 15 | #' students are co-authors!) compared the effectiveness of taking notes on a 16 | #' laptop versus longhand (i.e., pen and paper) for learning from lectures. 142 17 | #' participants (which differed from the 88 authors) first viewed one of several 18 | #' 15 minutes lectures (TED talks) during which they were asked to take notes 19 | #' either on a laptop or with pen and paper. Participants were randomly assigned 20 | #' to either the laptop (N = 68) or longhand condition (N = 74). After a 30 21 | #' minutes delay, participants were quizzed on the content of the lecture. There 22 | #' were two types of questions, factual and conceptual questions. The answers 23 | #' from each participant were then independently rated from several raters 24 | #' (which agreed very strongly with each other) using a standardised scoring key 25 | #' producing one memory score per participant and questions type ranging from 0 26 | #' (= no memory) to 100 (= perfect memory). We also aggregated the two different 27 | #' scores into one overall memory score. 28 | #' 29 | #' 30 | #' @docType data 31 | #' @keywords dataset 32 | #' @name laptop_urry 33 | #' @usage laptop_urry 34 | #' @format A data frame with 142 rows and 6 variables: 35 | #' \describe{ 36 | #' \item{pid}{participant id, factor with 142 levels} 37 | #' \item{condition}{experimental condition (laptop, longhand), factor with 2 levels} 38 | #' \item{talk}{TED talk seen by participant, factor with 5 levels} 39 | #' \item{overall}{overall memory score ranging from 0 (= no memory) to 100 (= perfect memory).} 40 | #' \item{factual}{memory score on the factual questions ranging from 0 (= no memory) to 100 (= perfect memory).} 41 | #' \item{conceptual}{memory score on the conceptual questions ranging from 0 (= no memory) to 100 (= perfect memory).} 42 | #' } 43 | #' @source Urry, H. L., Crittle, C. S., Floerke, V. A., Leonard, M. Z., Perry, 44 | #' C. S., Akdilek, N., Albert, E. R., Block, A. J., Bollinger, C. A., Bowers, 45 | #' E. M., Brody, R. S., Burk, K. C., Burnstein, A., Chan, A. K., Chan, P. C., 46 | #' Chang, L. J., Chen, E., Chiarawongse, C. P., Chin, G., … Zarrow, J. E. 47 | #' (2021). Don’t Ditch the Laptop Just Yet: A Direct Replication of Mueller 48 | #' and Oppenheimer’s (2014) Study 1 Plus Mini Meta-Analyses Across Similar 49 | #' Studies. *Psychological Science*, 0956797620965541. 50 | #' \doi{10.1177/0956797620965541} 51 | #' 52 | #' @encoding UTF-8 53 | #' 54 | "laptop_urry" 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /R/lmerTest_utils.R: -------------------------------------------------------------------------------- 1 | 2 | #' @importFrom utils packageVersion 3 | #' @importFrom methods as 4 | #' @importFrom stats anova 5 | lmerTest_anova <- function(object, ...) { 6 | # Produce lmerTest-anova table for lmer-model fits (lme4 or lmerTest) with old 7 | # as well as new lmerTest package. 8 | # Standard method dispatch for all non-lmerMod objects. 9 | pkg_version <- "2.0-37.9005" 10 | if(!inherits(object, "lmerMod")) return(anova(object, ...)) # non-lmer objects 11 | if(requireNamespace("lmerTest", quietly=TRUE) && packageVersion("lmerTest") < pkg_version) { 12 | stop("Newer version of lmerTest is required.") 13 | } 14 | if(requireNamespace("lmerTest", quietly=TRUE) && packageVersion("lmerTest") >= pkg_version) { 15 | if(inherits(object, "lmerModLmerTest")) 16 | return(anova(object, ...)) else # lmerTest object 17 | return(anova(lmerTest::as_lmerModLmerTest(object), ...)) # lme4 object 18 | } 19 | return(anova(object, ...)) # *merModLmerTest objects and/or 'lmerTest' is not available 20 | } 21 | 22 | lmerTest_summary <- function(object, ...) { 23 | # Produce lmerTest-summary for lmer-model fits (lme4 or lmerTest) with old 24 | # as well as new lmerTest package. 25 | # Standard method dispatch for all non-lmerMod objects. 26 | pkg_version <- "2.0-37.9005" 27 | if(!inherits(object, "lmerMod")) return(summary(object, ...)) # non-lmer objects 28 | if(requireNamespace("lmerTest", quietly=TRUE) && packageVersion("lmerTest") < pkg_version) { 29 | stop("Newer version of lmerTest is required.") 30 | } 31 | if(requireNamespace("lmerTest", quietly=TRUE) && packageVersion("lmerTest") >= pkg_version) { 32 | if(inherits(object, "lmerModLmerTest")) 33 | return(summary(object, ...)) else # lmerTest object 34 | return(summary(lmerTest::as_lmerModLmerTest(object), ...)) # lme4 object 35 | } 36 | return(summary(object, ...)) # *merModLmerTest objects and/or 'lmerTest' is not available 37 | } 38 | 39 | is_lmerTest_class <- function(object) 40 | # Check if an object is of class merModLmerTest or lmerModLmerTest 41 | # Bridges across versions of lmerTest 42 | inherits(object, "merModLmerTest") || inherits(object, "lmerModLmerTest") 43 | 44 | 45 | # anova_lmerTest <- function(object, ...) { 46 | # # Dispatch the right anova method across lmerTest versions 47 | # if(is_lmerTest_class(object) && requireNamespace("lmerTest", quietly = TRUE)) { 48 | # if(packageVersion("lmerTest") < "2.0.37.90012") 49 | # return(lmerTest::anova(object, ...)) else return(anova(object, ...)) 50 | # } else if(inherits(object, "merMod") && requireNamespace("lmerTest", quietly = TRUE)) { 51 | # if(packageVersion("lmerTest") < "2.0.37.90012") 52 | # return(lmerTest::anova(as(object, "merModLmerTest"), ...)) else 53 | # return(anova(lmerTest::as_lmerModLmerTest(object), ...)) 54 | # } # Default: 55 | # anova(object, ...) 56 | # } 57 | # 58 | # summary_lmerTest <- function(object, ...) { 59 | # # Dispatch the right summary method across lmerTest versions 60 | # if(is_lmerTest_class(object) && requireNamespace("lmerTest", quietly = TRUE)) { 61 | # if(packageVersion("lmerTest") < "2.0.37.90012") 62 | # return(lmerTest::summary(object, ...)) else return(summary(object, ...)) 63 | # } else if(inherits(object, "merMod") && requireNamespace("lmerTest", quietly = TRUE)) { 64 | # if(packageVersion("lmerTest") < "2.0.37.90012") 65 | # return(lmerTest::summary(as(object, "merModLmerTest"), ...)) else 66 | # return(summary(lmerTest::as_lmerModLmerTest(object), ...)) 67 | # } # Default: 68 | # summary(object, ...) 69 | # } 70 | # 71 | -------------------------------------------------------------------------------- /R/md_12.1-data.R: -------------------------------------------------------------------------------- 1 | #' Data 12.1 from Maxwell & Delaney 2 | #' 3 | #' Hypothetical Reaction Time Data for 2 x 3 Perceptual Experiment: Example data for chapter 12 of Maaxwell and Delaney (2004, Table 12.1, p. 574) in long format. Has two within.subjects factors: angle and noise. 4 | #' 5 | #' Description from pp. 573: 6 | #' 7 | #' Suppose that a perceptual psychologist studying the visual system was interested in determining the 8 | #' extent to which interfering visual stimuli slow the ability to recognize letters. Subjects are 9 | #' brought into a laboratory and seated in front of a tachistoscope. Subjects are told that they will 10 | #' see either the letter T or the letter I displayed on the screen. In some trials, the letter appears 11 | #' by itself, but in other trials, the target letter is embedded in a group of other letters. This 12 | #' variation in the display constitutes the first factor, which is referred to as noise. The noise 13 | #' factor has two levels?absent and present. The other factor varied by the experimenter is where in 14 | #' the display the target letter appears. This factor, which is called angle, has three levels. The 15 | #' target letter is either shown at the center of the screen (i.e., 0° off-center, where the subject 16 | #' has been instructed to fixate), 4° off-center or 8° off-center (in each case, the deviation from the 17 | #' center varies randomly between left and right). Table 12.1 presents hypothetical data for 10 18 | #' subjects. As usual, the sample size is kept small to make the calculations easier to follow. The 19 | #' dependent measure is reaction time (latency), measured in milliseconds (ms), required by a subject 20 | #' to identify the correct target letter. Notice that each subject has six scores, one for each 21 | #' combination of the 2 x 3 design. In an actual perceptual experiment, each of these six scores would 22 | #' itself be the mean score for that subject across a number of trials in the particular condition. 23 | #' Although "trials" could be used as a third within-subjects factor in such a situation, more 24 | #' typically trials are simply averaged over to obtain a more stable measure of the individual's 25 | #' performance in each condition. 26 | #' 27 | #' @docType data 28 | #' @keywords dataset 29 | #' @name md_12.1 30 | #' @usage md_12.1 31 | #' @format A data.frame with 60 rows and 4 variables. 32 | #' @source Maxwell, S. E., & Delaney, H. D. (2004). Designing experiments and analyzing data: a model-comparisons perspective. Mahwah, N.J.: Lawrence Erlbaum Associates. p. 574 33 | 34 | #' 35 | #' @encoding UTF-8 36 | #' 37 | #' @examples 38 | #' data(md_12.1) 39 | #' 40 | #' # Table 12.5 (p. 578): 41 | #' aov_ez("id", "rt", md_12.1, within = c("angle", "noise"), 42 | #' args.return=list(correction = "none", es = "none")) 43 | #' 44 | #' 45 | NULL 46 | -------------------------------------------------------------------------------- /R/md_15.1-data.R: -------------------------------------------------------------------------------- 1 | #' Data 15.1 / 11.5 from Maxwell & Delaney 2 | #' 3 | #' Hypothetical IQ Data from 12 children at 4 time points: Example data for chapter 11/15 of Maxwell and Delaney (2004, Table 15.1, p. 766) in long format. Has two one within-subjects factor: time. 4 | #' 5 | #' Description from pp. 534: 6 | #' 7 | #' The data show that 12 subjects have been observed in each of 4 conditions. To make the example easier to discuss, let's suppose that the 12 subjects are children who have been observed at 30, 36, 42, and 48 months of age. In each case, the dependent variable is the child's age-normed general cognitive score on the McCarthy Scales of Children's Abilities. Although the test is normed so that the mean score is independent of age for the general population, our 12 children may come from a population in which cognitive abilities are either growing more rapidly or less rapidly than average. Indeed, this is the hypothesis our data allow us to address. In other words, although the sample means suggest that the children's cognitive abilities are growing, a significance test is needed if we want to rule out sampling error as a likely explanation for the observed differences. 8 | #' 9 | #' To replicate the results in chapter 15 several different contrasts need to be applied, see Examples. 10 | #' 11 | #' \code{time} is time in months (centered at 0) and \code{timecat} is the same as a categorical variable. 12 | #' 13 | #' @docType data 14 | #' @keywords dataset 15 | #' @name md_15.1 16 | #' @usage md_15.1 17 | #' @format A data.frame with 48 rows and 4 variables. 18 | #' @source Maxwell, S. E., & Delaney, H. D. (2004). Designing experiments and analyzing data: a model-comparisons perspective. Mahwah, N.J.: Lawrence Erlbaum Associates. p. 766 19 | #' @author R code for examples written by Ulf Mertens and Henrik Singmann 20 | #' 21 | #' @examples 22 | #' ### replicate results from Table 15.2 to 15.6 (Maxwell & Delaney, 2004, pp. 774) 23 | #' data(md_15.1) 24 | #' 25 | #' ### ANOVA results (Table 15.2) 26 | #' aov_4(iq ~ timecat + (timecat|id),data=md_15.1, anova_table=list(correction = "none")) 27 | #' 28 | #' ### Table 15.3 (random intercept only) 29 | #' # we need to set the base level on the last level: 30 | #' contrasts(md_15.1$timecat) <- contr.treatment(4, base = 4) 31 | #' # "Type 3 Tests of Fixed Effects" 32 | #' (t15.3 <- mixed(iq ~ timecat + (1|id),data=md_15.1, check.contrasts=FALSE)) 33 | #' # "Solution for Fixed Effects" and "Covariance Parameter Estimates" 34 | #' summary(t15.3$full.model) 35 | #' 36 | #' ### make Figure 15.2 37 | #' plot(NULL, NULL, ylim = c(80, 140), xlim = c(30, 48), ylab = "iq", xlab = "time") 38 | #' plyr::d_ply(md_15.1, plyr::.(id), function(x) lines(as.numeric(as.character(x$timecat)), x$iq)) 39 | #' 40 | #' ### Table 15.4, page 789 41 | #' # random intercept plus slope 42 | #' (t15.4 <- mixed(iq ~ timecat + (1+time|id),data=md_15.1, check.contrasts=FALSE)) 43 | #' summary(t15.4$full.model) 44 | #' 45 | #' ### Table 15.5, page 795 46 | #' # set up polynomial contrasts for timecat 47 | #' contrasts(md_15.1$timecat) <- contr.poly 48 | #' # fit all parameters separately 49 | #' (t15.5 <- mixed(iq ~ timecat + (1+time|id), data=md_15.1, check.contrasts=FALSE, 50 | #' per.parameter="timecat")) 51 | #' # quadratic trend is considerably off, conclusions stay the same. 52 | #' 53 | #' 54 | #' ### Table 15.6, page 797 55 | #' # growth curve model 56 | #' (t15.6 <- mixed(iq ~ time + (1+time|id),data=md_15.1)) 57 | #' summary(t15.6$full.model) 58 | #' 59 | #' @encoding UTF-8 60 | #' 61 | NULL 62 | -------------------------------------------------------------------------------- /R/md_16.1-data.R: -------------------------------------------------------------------------------- 1 | #' Data 16.1 / 10.9 from Maxwell & Delaney 2 | #' 3 | #' Hypothetical Reaction Time Data for 2 x 3 Perceptual Experiment: Example data for chapter 12 of Maaxwell and Delaney (2004, Table 12.1, p. 574) in long format. Has two within.subjects factors: angle and noise. 4 | #' 5 | #' Description from pp. 829: 6 | #' 7 | #' As brief background, the goal of the study here is to examine the extent to which female and male clinical psychology graduate student trainees may assign different severity ratings to clients at initial intake. Three female and 3 male graduate students are randomly selected to participate and each is randomly assigned four clients with whom to do an intake interview, after which each clinical trainee assigns a severity rating to each client, producing the data shown in Table 16.1. 8 | #' 9 | #' Note that I changed the labeling of the id slightly, so that they are now labeled from 1 to 6. Furthermore, I changed the contrasts of sex to \code{contr.treatment} to replicate the exact results of Table 16.3 (p. 837). 10 | #' 11 | #' @docType data 12 | #' @keywords dataset 13 | #' @name md_16.1 14 | #' @usage md_16.1 15 | #' @format A data.frame with 24 rows and 3 variables. 16 | #' @source Maxwell, S. E., & Delaney, H. D. (2004). Designing experiments and analyzing data: a model-comparisons perspective. Mahwah, N.J.: Lawrence Erlbaum Associates. p. 574 17 | 18 | #' 19 | #' @examples 20 | #' ### replicate results from Table 16.3 (Maxwell & Delaney, 2004, p. 837) 21 | #' data(md_16.1) 22 | #' 23 | #' # original results need treatment contrasts: 24 | #' (mixed1_orig <- mixed(severity ~ sex + (1|id), md_16.1, check.contrasts=FALSE)) 25 | #' summary(mixed1_orig$full.model) 26 | #' 27 | #' # p-values stay the same with afex default contrasts (contr.sum), 28 | #' # but estimates and t-values for the fixed effects parameters change. 29 | #' (mixed1 <- mixed(severity ~ sex + (1|id), md_16.1)) 30 | #' summary(mixed1$full.model) 31 | #' 32 | #' @encoding UTF-8 33 | #' 34 | NULL 35 | -------------------------------------------------------------------------------- /R/md_16.4-data.R: -------------------------------------------------------------------------------- 1 | #' Data 16.4 from Maxwell & Delaney 2 | #' 3 | #' Data from a hypothetical inductive reasoning study. 4 | #' 5 | #' 6 | #' Description from pp. 841: 7 | #' 8 | #' Suppose an educational psychologist has developed an intervention to teach inductive reasoning skills to school children. She decides to test the efficacy of her intervention by conducting a randomized design. Three classrooms of students are randomly assigned to the treatment condition, and 3 other classrooms are assigned to the control. 9 | #' 10 | #' Table 16.4 shows hypothetical data collected from 29 children who participated in the study assessing the effectiveness of the intervention to increase inductive reasoning skills. We want to call your attention to several aspects of the data. First, the 15 children with condition values of 0 received the control, whereas the 14 children with condition values of 1 received the treatment. Second, 4 of the children in the control condition were students in control Classroom 1, 6 of them were students in control Classroom 2, and 5 were students in control Classroom 3. Along similar lines, 3 of the children in the treatment condition were students in treatment Classroom 1, 5 were students in treatment Classroom 2, and 6 were students in treatment Classroom 3. It is essential to understand that there are a total of six classrooms here; we have coded classroom from 1 to 3 for control as well as treatment, because we will indicate to PROC MIXED that classroom is nested under treatment. Third, scores on the dependent variable appear in the rightmost column under the variable label "induct." 11 | #' 12 | #' Note that it would make a lot more sense to change the labeling of room from 1 to 3 nested within cond to 1 to 6. However, I keep this in line with the original. The random effects term in the call to mixed is therefore a little bit uncommon.#' 13 | #' 14 | #' @docType data 15 | #' @keywords dataset 16 | #' @name md_16.4 17 | #' @usage md_16.4 18 | #' @format A data.frame with 24 rows and 3 variables. 19 | #' @source Maxwell, S. E., & Delaney, H. D. (2004). Designing experiments and analyzing data: a model-comparisons perspective. Mahwah, N.J.: Lawrence Erlbaum Associates. p. 574 20 | #' 21 | #' @encoding UTF-8 22 | #' 23 | #' @examples 24 | #' # data for next examples (Maxwell & Delaney, Table 16.4) 25 | #' data(md_16.4) 26 | #' str(md_16.4) 27 | #' 28 | #' ### replicate results from Table 16.6 (Maxwell & Delaney, 2004, p. 845) 29 | #' # p-values (almost) hold: 30 | #' (mixed2 <- mixed(induct ~ cond + (1|room:cond), md_16.4)) 31 | #' # (1|room:cond) is needed because room is nested within cond. 32 | #' 33 | #' 34 | NULL 35 | -------------------------------------------------------------------------------- /R/obk.long-data.R: -------------------------------------------------------------------------------- 1 | #' O'Brien Kaiser's Repeated-Measures Dataset with Covariate 2 | #' 3 | #' This is the long version of the \code{OBrienKaiser} dataset from the \pkg{car} pakage adding a random covariate \code{age}. Originally the dataset ist taken from O'Brien and Kaiser (1985). The description from \code{\link[carData]{OBrienKaiser}} says: "These contrived repeated-measures data are taken from O'Brien and Kaiser (1985). The data are from an imaginary study in which 16 female and male subjects, who are divided into three treatments, are measured at a pretest, postest, and a follow-up session; during each session, they are measured at five occasions at intervals of one hour. The design, therefore, has two between-subject and two within-subject factors." 4 | #' 5 | #' @docType data 6 | #' @keywords dataset 7 | #' @name obk.long 8 | #' @usage obk.long 9 | #' @format A data frame with 240 rows and 7 variables. 10 | #' @source O'Brien, R. G., & Kaiser, M. K. (1985). MANOVA method for analyzing repeated measures designs: An extensive primer. \emph{Psychological Bulletin}, 97, 316-333. doi:10.1037/0033-2909.97.2.316 11 | #' 12 | #' @encoding UTF-8 13 | #' 14 | #' @examples 15 | #' # The dataset is constructed as follows: 16 | #' data("OBrienKaiser", package = "carData") 17 | #' set.seed(1) 18 | #' OBrienKaiser2 <- within(OBrienKaiser, { 19 | #' id <- factor(1:nrow(OBrienKaiser)) 20 | #' age <- scale(sample(18:35, nrow(OBrienKaiser), replace = TRUE), scale = FALSE)}) 21 | #' attributes(OBrienKaiser2$age) <- NULL # needed or resahpe2::melt throws an error. 22 | #' OBrienKaiser2$age <- as.numeric(OBrienKaiser2$age) 23 | #' obk.long <- reshape2::melt(OBrienKaiser2, id.vars = c("id", "treatment", "gender", "age")) 24 | #' obk.long[,c("phase", "hour")] <- lapply(as.data.frame(do.call(rbind, 25 | #' strsplit(as.character(obk.long$variable), "\\."),)), factor) 26 | #' obk.long <- obk.long[,c("id", "treatment", "gender", "age", "phase", "hour", "value")] 27 | #' obk.long <- obk.long[order(obk.long$id),] 28 | #' rownames(obk.long) <- NULL 29 | #' str(obk.long) 30 | #' ## 'data.frame': 240 obs. of 7 variables: 31 | #' ## $ id : Factor w/ 16 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ... 32 | #' ## $ treatment: Factor w/ 3 levels "control","A",..: 1 1 1 1 1 1 1 1 1 1 ... 33 | #' ## $ gender : Factor w/ 2 levels "F","M": 2 2 2 2 2 2 2 2 2 2 ... 34 | #' ## $ age : num -4.75 -4.75 -4.75 -4.75 -4.75 -4.75 -4.75 -4.75 -4.75 -4.75 ... 35 | #' ## $ phase : Factor w/ 3 levels "fup","post","pre": 3 3 3 3 3 2 2 2 2 2 ... 36 | #' ## $ hour : Factor w/ 5 levels "1","2","3","4",..: 1 2 3 4 5 1 2 3 4 5 ... 37 | #' ## $ value : num 1 2 4 2 1 3 2 5 3 2 ... 38 | #' head(obk.long) 39 | #' ## id treatment gender age phase hour value 40 | #' ## 1 1 control M -4.75 pre 1 1 41 | #' ## 2 1 control M -4.75 pre 2 2 42 | #' ## 3 1 control M -4.75 pre 3 4 43 | #' ## 4 1 control M -4.75 pre 4 2 44 | #' ## 5 1 control M -4.75 pre 5 1 45 | #' ## 6 1 control M -4.75 post 1 3 46 | NULL 47 | -------------------------------------------------------------------------------- /R/predict.R: -------------------------------------------------------------------------------- 1 | #' Predict method for \code{afex_aov} objects 2 | #' 3 | #' Predicted values based on \code{afex_aov} objects. 4 | #' 5 | #' @author Mattan S. Ben-Shachar 6 | #' 7 | #' @example examples/examples.predict.R 8 | #' 9 | #' @param newdata An optional data frame in which to look for variables with 10 | #' which to predict. If omitted, the fitted values are used. 11 | #' @param colname_predict Name of the appended column when \code{append = TRUE}. 12 | #' @inheritParams residuals.afex_aov 13 | #' @param ... Not used. 14 | #' 15 | #' @return A vector of predicted values corresponding to the data in 16 | #' \code{object$data$long} or to \code{newdata}, or if \code{append = TRUE} a 17 | #' data frame with an additional column of predicted values. 18 | #' 19 | #' @export 20 | #' @importFrom stats predict fitted setNames 21 | predict.afex_aov <- function(object, newdata, append = FALSE, colname_predict = ".predict", ...) { 22 | # if no newdata, get fitted 23 | if (missing(newdata)) { 24 | return(fitted(object, append = append, colname_predict = colname_predict)) 25 | } 26 | 27 | # soft factorize numeric data 28 | for (col in colnames(newdata)) { 29 | if (is.numeric(newdata[[col]])) { 30 | i <- which(colnames(object$data$long) == col) 31 | if (length(i) && !is.numeric(object$data$long[[i]])) { 32 | newdata[[col]] <- as.character(newdata[[col]]) 33 | } 34 | } 35 | } 36 | 37 | # get predicted values 38 | pred <- predict(object$lm, newdata = newdata) 39 | colnames(pred) <- colnames(fitted(object$lm)) 40 | 41 | # if any within, needs some clean up 42 | if (length(attr(object, "within")) > 0) { 43 | within <- attr(object, "within") 44 | 45 | # make long ~ 46 | pred <- sapply(seq_len(nrow(pred)), function(i) { 47 | temp_pred <- pred 48 | w_rm <- sapply(newdata[i, names(within)], make.names, unique = TRUE) 49 | w_rm <- paste0(w_rm, collapse = "_") 50 | temp_pred[i, w_rm] 51 | }) 52 | 53 | pred <- setNames(pred, rownames(newdata)) 54 | } 55 | 56 | if (append) { 57 | newdata[[colname_predict]] <- pred 58 | return(newdata) 59 | } else { 60 | return(pred) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /R/reexport.R: -------------------------------------------------------------------------------- 1 | ### lme4 2 | 3 | #' @importFrom lmerTest lmer 4 | 5 | #' @export 6 | lmerTest::lmer 7 | 8 | -------------------------------------------------------------------------------- /R/residuals.R: -------------------------------------------------------------------------------- 1 | #' Extract Residuals and Fitted Values from \code{afex_aov} objects 2 | #' 3 | #' Extract Residuals and Fitted Values from \code{afex_aov} objects. 4 | #' 5 | #' @author Mattan S. Ben-Shachar 6 | #' 7 | #' @example examples/examples.residuals.R 8 | #' 9 | #' @param object \code{afex_aov} object. 10 | #' @param append If set to \code{TRUE} returns the residuals/fitted values 11 | #' appended as an additional column to the long data. Recommended when data 12 | #' was aggregated across within conditions. 13 | #' @param colname_residuals,colname_fitted Name of the appended column when 14 | #' \code{append = TRUE}. 15 | #' @param ... Additional arguments passed to 16 | #' \code{residuals.lm}/\code{fitted.lm}. 17 | #' 18 | #' @return A vector of residuals/fitted values corresponding to the data in 19 | #' \code{object$data$long}, or if \code{append = TRUE} a data frame with an 20 | #' additional column of residuals/fitted values. 21 | #' 22 | #' @export 23 | #' @importFrom stats fitted reshape residuals 24 | residuals.afex_aov <- function(object, append = FALSE, colname_residuals = ".residuals", ...) { 25 | if (!append && attr(object, "data_changed")) { 26 | message("Data was changed during ANOVA calculation. ", 27 | "Thus, residuals cannot be added to original data.", 28 | "\nresiduals(..., append = TRUE) will return data and residuals.") 29 | } 30 | 31 | e <- residuals(object$lm, ...) 32 | .clean_model_values(object, model_values = e, values_colname = colname_residuals, append = append) 33 | } 34 | 35 | #' @export 36 | #' @rdname residuals.afex_aov 37 | fitted.afex_aov <- function(object, append = FALSE, colname_fitted = ".fitted", ...) { 38 | if (!append && attr(object, "data_changed")) { 39 | message("Data was changed during ANOVA calculation. ", 40 | "Thus, fitted values cannot be added to original data.", 41 | "\nfitted(..., append = TRUE) will return data and fitted values.") 42 | } 43 | 44 | e <- fitted(object$lm, ...) 45 | .clean_model_values(object, model_values = e, values_colname = colname_fitted, append = append) 46 | } 47 | 48 | 49 | #' @keywords internal 50 | .clean_model_values <- function(object, model_values, values_colname, append) { 51 | if (length(attr(object, "within")) > 0) { 52 | # In long format 53 | mv <- data.frame(model_values) 54 | varying <- colnames(mv) 55 | mv[attr(object, "id")] <- object$data$wide[attr(object, "id")] 56 | mv <- reshape( 57 | mv, 58 | direction = "long", 59 | varying = varying, 60 | v.names = values_colname, 61 | times = varying, 62 | timevar = ".time.", 63 | idvar = attr(object, "id") 64 | ) 65 | 66 | 67 | # add within data 68 | code <- data.frame(.time. = varying, 69 | .index. = seq_along(varying)) 70 | index <- object$data$idata 71 | index$.index. <- seq_len(nrow(index)) 72 | index <- merge(code, index, by = ".index.") 73 | 74 | mv <- merge(mv, index, by = ".time.") 75 | mv$.time. <- NULL 76 | mv$.index. <- NULL 77 | 78 | # add between data 79 | between_data <- object$data$long 80 | mv <- merge(between_data, mv, by = c(attr(object, "id"), names(attr(object, "within")))) 81 | } else { 82 | mv <- object$data$long 83 | mv[[values_colname]] <- model_values 84 | } 85 | 86 | if (append) { 87 | return(mv) 88 | } else { 89 | return(setNames(mv[[values_colname]],rownames(mv))) 90 | } 91 | } -------------------------------------------------------------------------------- /R/round_ps.R: -------------------------------------------------------------------------------- 1 | #' Helper functions for rounding p-values 2 | #' 3 | #' These functions return a character vector of p-values that are rounded as 4 | #' described below and without the leading zero before the decimal point. 5 | #' 6 | #' For \code{round_ps} p-values are rounded in a sane way: .99 - .01 to two 7 | #' digits, < .01 to three digits, < .001 to four digits. 8 | #' 9 | #' For \code{round_ps_apa} p-values are rounded following APA guidelines: .999 - 10 | #' .001 to three digits, and < .001 for values below this threshold. 11 | #' 12 | #' @param x a numeric vector 13 | #' 14 | #' @return A character vector with the same length as x. 15 | #' 16 | #' @note These functions are useful in \code{\link{nice}} and the default is set 17 | #' via \code{\link{afex_options}}. 18 | #' 19 | #' @author Henrik Singmann 20 | #' 21 | #' @encoding UTF-8 22 | #' 23 | #' @examples 24 | #' x <- runif(10) 25 | #' y <- runif(10, 0, .01) 26 | #' 27 | #' round_ps(x) 28 | #' round_ps_apa(x) 29 | #' 30 | #' round_ps(y) 31 | #' round_ps_apa(y) 32 | #' 33 | #' round_ps(0.0000000099) 34 | #' round_ps_apa(0.0000000099) 35 | #' 36 | #' @export 37 | round_ps <- function(x) { 38 | substr(as.character(ifelse(x < 0.0001, " <.0001", ifelse(x < 0.001, formatC(x, digits = 4, format = "f"), ifelse(x < 0.01, formatC(x, digits = 3, format = "f"), ifelse(round(x, 2) == 1, " >.99", formatC(x, digits = 2, format = "f")))))), 2, 7) 39 | } 40 | 41 | #' @rdname round_ps 42 | #' @export 43 | round_ps_apa <- function(x) { 44 | substr(as.character( 45 | ifelse(x < 0.001, " <.001", 46 | ifelse(round(x, 3) == 1, " >.999", 47 | formatC(x, digits = 3, format = "f")) 48 | ) 49 | ), 2, 7) 50 | } 51 | -------------------------------------------------------------------------------- /R/set_contrasts.R: -------------------------------------------------------------------------------- 1 | #' Set global contrasts 2 | #' 3 | #' These functions are simple wrappers to set contrasts globally via \code{options(contrasts = ...)}. 4 | #' 5 | #' @usage set_sum_contrasts() 6 | #' 7 | #' set_deviation_contrasts() 8 | #' 9 | #' set_effects_contrasts() 10 | #' 11 | #' set_default_contrasts() 12 | #' 13 | #' set_treatment_contrasts() 14 | #' 15 | #' 16 | #' @details \code{set_deviation_contrasts} and \code{set_effects_contrasts} are wrappers for \code{set_sum_contrasts}. Likewise, \code{set_default_contrasts} is a wrapper to \code{set_treatment_contrasts()}. 17 | #' 18 | #' @return nothing. These functions are called for their side effects to change the global options. 19 | #' 20 | #' @name set_sum_contrasts 21 | #' @aliases set_sum_contrasts set_deviation_contrasts set_effects_contrasts set_treatment_contrasts set_default_contrasts 22 | #' @export set_sum_contrasts set_deviation_contrasts set_effects_contrasts set_treatment_contrasts set_default_contrasts 23 | 24 | set_sum_contrasts <- function() { 25 | message("setting contr.sum globally: options(contrasts=c('contr.sum', 'contr.poly'))") 26 | options(contrasts=c('contr.sum', 'contr.poly')) 27 | } 28 | 29 | set_deviation_contrasts <- function() { 30 | set_sum_contrasts() 31 | } 32 | 33 | set_effects_contrasts <- function() { 34 | set_sum_contrasts() 35 | } 36 | 37 | set_treatment_contrasts <- function() { 38 | message("setting contr.treatment globally: options(contrasts=c('contr.treatment', 'contr.poly'))") 39 | options(contrasts=c('contr.treatment', 'contr.poly')) 40 | } 41 | 42 | set_default_contrasts <- function() { 43 | set_treatment_contrasts() 44 | } 45 | -------------------------------------------------------------------------------- /R/sk2011.1-data.R: -------------------------------------------------------------------------------- 1 | #' Data from Singmann & Klauer (2011, Experiment 1) 2 | #' 3 | #' Singmann and Klauer (2011) were interested in whether or not conditional reasoning can be explained by a single process or whether multiple processes are necessary to explain it. To provide evidence for multiple processes we aimed to establish a double dissociation of two variables: instruction type and problem type. Instruction type was manipulated between-subjects, one group of participants received deductive instructions (i.e., to treat the premises as given and only draw necessary conclusions) and a second group of participants received probabilistic instructions (i.e., to reason as in an everyday situation; we called this "inductive instruction" in the manuscript). Problem type consisted of two different orthogonally crossed variables that were manipulated within-subjects, validity of the problem (formally valid or formally invalid) and plausibility of the problem (inferences which were consisted with the background knowledge versus problems that were inconsistent with the background knowledge). The critical comparison across the two conditions was among problems which were valid and implausible with problems that were invalid and plausible. For example, the next problem was invalid and plausible: 4 | #' 5 | #' If a person is wet, then the person fell into a swimming pool. \cr 6 | #' A person fell into a swimming pool. \cr 7 | #' How valid is the conclusion/How likely is it that the person is wet? 8 | #' 9 | #' For those problems we predicted that under deductive instructions responses should be lower (as the conclusion does not necessarily follow from the premises) as under probabilistic instructions. For the valid but implausible problem, an example is presented next, we predicted the opposite pattern: 10 | #' 11 | #' If a person is wet, then the person fell into a swimming pool. \cr 12 | #' A person is wet. \cr 13 | #' How valid is the conclusion/How likely is it that the person fell into a swimming pool? 14 | #' 15 | #' Our study also included valid and plausible and invalid and implausible problems. 16 | #' 17 | #' Note that the factor `plausibility` is not present in the original manuscript, there it is a results of a combination of other factors. 18 | #' 19 | #' 20 | #' @docType data 21 | #' @keywords dataset 22 | #' @name sk2011.1 23 | #' @usage sk2011.1 24 | #' @format A data.frame with 640 rows and 9 variables. 25 | #' @source Singmann, H., & Klauer, K. C. (2011). Deductive and inductive conditional inferences: Two modes of reasoning. Thinking & Reasoning, 17(3), 247-281. doi:10.1080/13546783.2011.572718 26 | 27 | #' 28 | #' @encoding UTF-8 29 | #' 30 | #' @examples 31 | #' data(sk2011.1) 32 | #' 33 | #' # Table 1 (p. 264): 34 | #' aov_ez("id", "response", sk2011.1[ sk2011.1$what == "affirmation",], 35 | #' within = c("inference", "type"), between = "instruction", 36 | #' anova_table=(es = "pes")) 37 | #' aov_ez("id", "response", sk2011.1[ sk2011.1$what == "denial",], 38 | #' within = c("inference", "type"), between = "instruction", 39 | #' anova_table=(es = "pes")) 40 | #' 41 | #' 42 | NULL 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /R/sk2011.2-data.R: -------------------------------------------------------------------------------- 1 | #' Data from Singmann & Klauer (2011, Experiment 2) 2 | #' 3 | #' Singmann and Klauer (2011) were interested in whether or not conditional reasoning can be explained by a single process or whether multiple processes are necessary to explain it. To provide evidence for multiple processes we aimed to establish a double dissociation of two variables: instruction type and problem type. Instruction type was manipulated between-subjects, one group of participants received deductive instructions (i.e., to treat the premises as given and only draw necessary conclusions) and a second group of participants received probabilistic instructions (i.e., to reason as in an everyday situation; we called this "inductive instruction" in the manuscript). Problem type consisted of two different orthogonally crossed variables that were manipulated within-subjects, validity of the problem (formally valid or formally invalid) and type of the problem. Problem type consistent of three levels: prological problems (i.e., problems in which background knowledge suggested to accept valid but reject invalid conclusions), neutral problems (i.e., in which background knowledge suggested to reject all problems), and counterlogical problems (i.e., problems in which background knowledge suggested to reject valid but accept invalid conclusions). 4 | #' 5 | #' This data set contains 63 participants in contrast to the originally reported 56 participants. The additional participants were not included in the original studies as they did not meet the inclusion criteria (i.e., no students, prior education in logic, or participated in a similar experiment). The IDs of those additional participants are: 7, 8, 9, 12, 17, 24, 30. The excluded participant reported in the paper has ID 16. 6 | #' 7 | #' content has the following levels (C = content/conditional):\cr 8 | #' 1 = Wenn eine Person in ein Schwimmbecken gefallen ist, dann ist sie nass.\cr 9 | #' 2 = Wenn ein Hund Flöhe hat, dann kratzt er sich hin und wieder.\cr 10 | #' 3 = Wenn eine Seifenblase mit einer Nadel gestochen wurde, dann platzt sie.\cr 11 | #' 4 = Wenn ein Mädchen Geschlechtsverkehr vollzogen hat, dann ist es schwanger.\cr 12 | #' 5 = Wenn eine Pflanze ausreichend gegossen wird, dann bleibt sie grün.\cr 13 | #' 6 = Wenn sich eine Person die Zähne putzt, dann bekommt sie KEIN Karies.\cr 14 | #' 7 = Wenn eine Person viel Cola trinkt, dann nimmt sie an Gewicht zu.\cr 15 | #' 8 = Wenn eine Person die Klimaanlage angeschaltet hat, dann fröstelt sie.\cr 16 | #' 9 = Wenn eine Person viel lernt, dann wird sie in der Klausur eine gute Note erhalten. 17 | #' 18 | #' @docType data 19 | #' @keywords dataset 20 | #' @name sk2011.2 21 | #' @usage sk2011.2 22 | #' @format A data.frame with 2268 rows and 9 variables. 23 | #' @source Singmann, H., & Klauer, K. C. (2011). Deductive and inductive conditional inferences: Two modes of reasoning. Thinking & Reasoning, 17(3), 247-281. doi:10.1080/13546783.2011.572718 24 | 25 | #' 26 | #' @encoding UTF-8 27 | #' 28 | #' @example examples/examples.sk2011.2.R 29 | NULL 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /R/stroop-data.R: -------------------------------------------------------------------------------- 1 | #' Stroop data from Lin et al. (2020, Psych. Science) 2 | #' 3 | #' 4 | #' Lin, Saunders, Friese, Evans, and Inzlicht (2020) investigated ego depletion. 5 | #' An initial high-demand task was followed by a Stroop task. The data of the 6 | #' Stroop task from all 4 of their studies is included here. 7 | #' 8 | #' Their abstract: People feel tired or depleted after exerting mental effort. 9 | #' But even preregistered studies often fail to find effects of exerting effort 10 | #' on behavioral performance in the laboratory or elucidate the underlying 11 | #' psychology. We tested a new paradigm in four preregistered within-subjects 12 | #' studies (N = 686). An initial high-demand task reliably elicited very strong 13 | #' effort phenomenology compared with a low-demand task. Afterward, participants 14 | #' completed a Stroop task. We used drift-diffusion modeling to obtain the 15 | #' boundary (response caution) and drift-rate (information-processing speed) 16 | #' parameters. Bayesian analyses indicated that the high-demand manipulation 17 | #' reduced boundary but not drift rate. Increased effort sensations further 18 | #' predicted reduced boundary. However, our demand manipulation did not affect 19 | #' subsequent inhibition, as assessed with traditional Stroop behavioral 20 | #' measures and additional diffusion-model analyses for conflict tasks. Thus, 21 | #' effort exertion reduced response caution rather than inhibitory control, 22 | #' suggesting that after exerting effort, people disengage and become 23 | #' uninterested in exerting further effort. 24 | #' 25 | #' 26 | #' 27 | #' @docType data 28 | #' @keywords dataset 29 | #' @name stroop 30 | #' @usage stroop 31 | #' @format A data frame with 246600 rows and 7 variables: 32 | #' \describe{ 33 | #' \item{pno}{participant id (preceded by study id), factor with 685 levels} 34 | #' \item{condition}{experimental condition (control/low demand, deplete/high demand), factor with 2 levels} 35 | #' \item{study}{study number (1, 2, 3, 4), factor with 4 levels} 36 | #' \item{trialnum}{trial number} 37 | #' \item{congruency}{Stroop congruency (congruent, incongruent), factor with 2 levels} 38 | #' \item{acc}{accuracy (0: error, 1: correct)} 39 | #' \item{rt}{reaction time (seconds)} 40 | #' } 41 | #' @source Lin, H., Saunders, B., Friese, M., Evans, N. J., & Inzlicht, M. 42 | #' (2020). Strong Effort Manipulations Reduce Response Caution: A 43 | #' Preregistered Reinvention of the Ego-Depletion Paradigm. *Psychological 44 | #' Science*, \doi{10.1177/0956797620904990} 45 | #' 46 | #' @encoding UTF-8 47 | #' 48 | "stroop" 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | 2 | check_contrasts <- function(data, factors, 3 | check_contrasts, type, 4 | warn = TRUE) { 5 | if (check_contrasts) { 6 | data <- droplevels(data) 7 | resetted <- NULL 8 | for (i in factors) { 9 | if (is.character(data[,i])) { 10 | data[,i] <- factor(data[,i]) 11 | } 12 | if (is.factor(data[,i])) { 13 | if (is.null(attr(data[,i], "contrasts")) & 14 | (options("contrasts")[[1]][1] != "contr.sum")) { 15 | contrasts(data[,i]) <- "contr.sum" 16 | resetted <- c(resetted, i) 17 | } 18 | else if (!is.null(attr(data[,i], "contrasts")) && 19 | attr(data[,i], "contrasts") != "contr.sum") { 20 | contrasts(data[,i]) <- "contr.sum" 21 | resetted <- c(resetted, i) 22 | } 23 | } 24 | } 25 | if (!is.null(resetted)) 26 | message(paste0("Contrasts set to contr.sum for the following variables: ", 27 | paste0(resetted, collapse=", "))) 28 | } else if (warn) { 29 | non_sum_contrast <- c() 30 | for (i in factors) { 31 | if (is.factor(data[,i])) { 32 | if (is.null(attr(data[,i], "contrasts")) & 33 | (options("contrasts")[[1]][1] != "contr.sum")) { 34 | non_sum_contrast <- c(non_sum_contrast, i) 35 | } 36 | else if (!is.null(attr(data[,i], "contrasts")) && 37 | attr(data[,i], "contrasts") != "contr.sum") { 38 | non_sum_contrast <- c(non_sum_contrast, i) 39 | } 40 | } 41 | } 42 | if((type == 3 | type == "III") && (length(non_sum_contrast)>0)) 43 | warning( 44 | paste0("Calculating Type 3 sums with contrasts != 'contr.sum' for: ", 45 | paste0(non_sum_contrast, collapse=", "), 46 | "\n Results likely bogus or not interpretable!\n", 47 | "You probably want check_contrasts = TRUE or ", 48 | "options(contrasts=c('contr.sum','contr.poly'))"), 49 | call. = FALSE) 50 | } 51 | return(data) 52 | } 53 | 54 | ## paste function that can replace stringr::str_c and differs from the way 55 | # paste handles NULL arguments as last arguments. 56 | # It checks whether the first or last char of the string is equal to sep and 57 | # removes it in this case. 58 | mypaste <- function(..., sep) { 59 | tmp <- paste(..., sep = sep) 60 | if (substr(tmp, nchar(tmp), nchar(tmp)) == sep) { 61 | tmp <- substr(tmp, 1, nchar(tmp)-1) 62 | } 63 | if (substr(tmp, 1, 1) == sep) { 64 | tmp <- substr(tmp, 2, nchar(tmp)) 65 | } 66 | tmp 67 | } 68 | 69 | escape_vars <- function(names) { 70 | if (length(names) == 0) 71 | return(names) 72 | names <- vapply(names, function(name) { 73 | if (make.names(name) != name) { 74 | name <- gsub('\\', '\\\\', name, fixed=TRUE) 75 | name <- gsub('`', '\\`', name, fixed=TRUE) 76 | name <- paste0('`', name, '`') 77 | } 78 | name 79 | }, FUN.VALUE='', USE.NAMES=FALSE) 80 | names 81 | } 82 | 83 | # decompose functions from jmvcore 84 | 85 | decomposeTerm <- function(term) { 86 | 87 | chars <- strsplit(term, '')[[1]] 88 | components <- character() 89 | componentChars <- character() 90 | inQuote <- FALSE 91 | 92 | i <- 1 93 | n <- length(chars) 94 | 95 | while (i <= n) { 96 | char <- chars[i] 97 | if (char == '`') { 98 | inQuote <- ! inQuote 99 | } 100 | else if (char == '\\') { 101 | i <- i + 1 102 | char <- chars[i] 103 | componentChars <- c(componentChars, char) 104 | } 105 | else if (char == ':' && inQuote == FALSE) { 106 | component <- paste0(componentChars, collapse='') 107 | components <- c(components, component) 108 | componentChars <- character() 109 | } 110 | else { 111 | componentChars <- c(componentChars, char) 112 | } 113 | i <- i + 1 114 | } 115 | 116 | component <- paste0(componentChars, collapse='') 117 | components <- c(components, component) 118 | 119 | components 120 | } 121 | 122 | 123 | print_legend <- function(x) { 124 | sig_symbols <- as.character(attr(x, "sig_symbols")) 125 | if(length(sig_symbols) > 0 & !all(sig_symbols == rep("", 4))) { 126 | sleg <- attr(stats::symnum(0, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), 127 | symbols = rev(c(" " , trimws(sig_symbols)))), "legend") 128 | width <- getOption("width") 129 | 130 | if(width < nchar(sleg)) { 131 | sleg <- strwrap(sleg, width = width - 2, prefix = " ") 132 | } 133 | 134 | cat("---\nSignif. codes: ", sleg, sep = "", fill = getOption("width") + 4 + max(nchar(sleg, "bytes") - nchar(sleg))) 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## set default options for afex_options: 4 | .onLoad <- function(libname, pkgname) { 5 | op <- options() 6 | op.afex <- list( 7 | afex.type = 3, 8 | afex.set_data_arg = FALSE, 9 | afex.check_contrasts = TRUE, 10 | afex.method_mixed = "S", 11 | afex.return_aov = "afex_aov", 12 | afex.es_aov = "ges", 13 | afex.correction_aov = "GG", 14 | afex.factorize = TRUE, 15 | afex.lmer_function = "lmerTest", 16 | afex.sig_symbols = c(" +", " *", " **", " ***"), 17 | afex.emmeans_model = c("multivariate"), 18 | afex.include_aov = FALSE, 19 | afex.round_ps = round_ps_apa 20 | ) 21 | toset <- !(names(op.afex) %in% names(op)) 22 | if(any(toset)) options(op.afex[toset]) 23 | 24 | if (requireNamespace("emmeans", quietly = TRUE)) { 25 | emmeans::.emm_register(c("mixed", "afex_aov"), pkgname) 26 | } 27 | 28 | invisible() 29 | } 30 | 31 | .onAttach <- function(libname, pkgname) { 32 | #assign(".oldContrasts", options("contrasts"), envir = .GlobalEnv) 33 | packageStartupMessage("************\nWelcome to afex. For support visit: http://afex.singmann.science/") 34 | packageStartupMessage("- Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()\n- Methods for calculating p-values with mixed(): 'S', 'KR', 'LRT', and 'PB'\n- 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests\n- Get and set global package options with: afex_options()\n- Set sum-to-zero contrasts globally: set_sum_contrasts()\n- For example analyses see: browseVignettes(\"afex\")\n************") 35 | #if (options("contrasts")[[1]][1] != "contr.sum") { 36 | #packageStartupMessage("Setting contrasts to effects coding: options(contrasts=c('contr.sum', 'contr.poly'))\nThis affects all functions using contrasts (e.g., lmer, lm, aov, ...).\nTo reset default settings run: options(contrasts=c('contr.treatment', 'contr.poly')) (all afex functions should be unaffected by this)\n") 37 | # \nPrevious contrasts saved in '.oldContrasts'. 38 | #options(contrasts=c('contr.sum', 'contr.poly')) 39 | #} else packageStartupMessage("Contrasts already set to effects coding: options(contrasts=c('contr.sum', '...'))\n") 40 | #packageStartupMessage("afex loads the required packages (e.g., lme4, car, pbkrtest) in an order that should not lead to problems.\nLoading any of the packages (specifically lme4) beforehand can lead to problems (especially with older versions of either).\nLoading nlme in addition to afex (before or after loading it), may especially lead to problems.\n************") 41 | } 42 | 43 | -------------------------------------------------------------------------------- /afex.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: No 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageInstallArgs: --no-multiarch --with-keep.source 17 | PackageCheckArgs: --no-tests 18 | -------------------------------------------------------------------------------- /data/fhch2010.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/fhch2010.rda -------------------------------------------------------------------------------- /data/ks2013.3.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/ks2013.3.rda -------------------------------------------------------------------------------- /data/laptop_urry.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/laptop_urry.rda -------------------------------------------------------------------------------- /data/md_12.1.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/md_12.1.rda -------------------------------------------------------------------------------- /data/md_15.1.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/md_15.1.rda -------------------------------------------------------------------------------- /data/md_16.1.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/md_16.1.rda -------------------------------------------------------------------------------- /data/md_16.4.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/md_16.4.rda -------------------------------------------------------------------------------- /data/obk.long.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/obk.long.rda -------------------------------------------------------------------------------- /data/sk2011.1.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/sk2011.1.rda -------------------------------------------------------------------------------- /data/sk2011.2.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/sk2011.2.rda -------------------------------------------------------------------------------- /data/stroop.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/data/stroop.rda -------------------------------------------------------------------------------- /dev.R: -------------------------------------------------------------------------------- 1 | require(devtools) 2 | require(testthat) 3 | library("vdiffr") 4 | load_all() 5 | 6 | options(error = NULL) 7 | devtools::test() 8 | ## before building, consider recreating the glmmTMB object for the vignette 9 | devtools::build(args = "--compact-vignettes=both", 10 | manual = TRUE, 11 | path = "development/") # R CMD build afex --compact-vignettes="gs+qpdf" 12 | document() 13 | check() 14 | check_built(path = "development/afex_1.4-1.tar.gz") 15 | 16 | ## works better on windows: 17 | devtools::test(filter = "plot", invert = TRUE) 18 | devtools::test(filter = "plot") 19 | devtools::test(filter = "afex_plot-basics") 20 | devtools::test(filter = "afex_plot-vignette") 21 | 22 | 23 | test_package("afex", filter = "aov") 24 | test_package("afex", filter = "mixed") 25 | test_package("afex", filter = "mixed-structure") 26 | test_package("afex", filter = "mixed-bugs") 27 | test_package("afex", filter = "mixed-mw") 28 | test_package("afex", filter = "emmeans") 29 | 30 | 31 | options(error = recover) 32 | options(error = NULL) 33 | options(warn = 2) 34 | options(warn = 0) 35 | 36 | ##### 37 | 38 | rhub::rhub_setup() 39 | 40 | #### 41 | 42 | usethis::use_data(stroop, internal = FALSE, overwrite = TRUE) 43 | usethis::use_vignette("afex_analysing_accuracy_data") 44 | usethis::use_github_action_check_standard() 45 | 46 | ## check for non-ASCII characters in examples: 47 | for (f in list.files("examples/", full.names = TRUE)) { 48 | cat(f, "\n") 49 | tools::showNonASCIIfile(f) 50 | } 51 | 52 | ## check for non-ASCII characters in R files: 53 | for (f in list.files("R/", full.names = TRUE)) { 54 | cat(f, "\n") 55 | tools::showNonASCIIfile(f) 56 | } 57 | 58 | ## check for non-ASCII characters in Rd files: 59 | for (f in list.files("man/", full.names = TRUE)) { 60 | cat(f, "\n") 61 | tools::showNonASCIIfile(f) 62 | } 63 | 64 | ### add new data sets: 65 | usethis::use_data(laptop_urry2021) 66 | 67 | ## resave extdata: 68 | rda_files <- list.files("inst/extdata/", full.names = TRUE) 69 | for (i in rda_files) tools::resaveRdaFiles(i) 70 | 71 | #install.packages("afex", dependencies = TRUE) 72 | #devtools::build() 73 | devtools::build_vignettes() 74 | clean_vignettes(pkg = ".") 75 | 76 | devtools::build(args = "--compact-vignettes=both") 77 | 78 | ### add packages 79 | 80 | usethis::use_package("statmod", "Suggests") 81 | usethis::use_package("rstanarm", "Suggests") 82 | usethis::use_package("brms", "Suggests") 83 | usethis::use_package("cowplot", "Suggests") 84 | usethis::use_package("vdiffr", "Suggests") 85 | #usethis::use_package("GLMMadaptive", "Suggests") 86 | usethis::use_readme_rmd() 87 | usethis::use_cran_badge() 88 | usethis::use_code_of_conduct() 89 | 90 | ### check reverse dependencies: 91 | 92 | library(revdepcheck) # see https://github.com/r-lib/revdepcheck 93 | revdep_check(num_workers = 4) 94 | revdep_summary() 95 | revdep_details(revdep = "r2glmm") 96 | Sys.setenv(R_BIOC_VERSION = "3.18") 97 | -------------------------------------------------------------------------------- /development/GLMMtest.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/GLMMtest.zip -------------------------------------------------------------------------------- /development/afex_0.28-0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_0.28-0.tar.gz -------------------------------------------------------------------------------- /development/afex_0.28-1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_0.28-1.tar.gz -------------------------------------------------------------------------------- /development/afex_1.0-0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_1.0-0.tar.gz -------------------------------------------------------------------------------- /development/afex_1.0-1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_1.0-1.tar.gz -------------------------------------------------------------------------------- /development/afex_1.1-0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_1.1-0.tar.gz -------------------------------------------------------------------------------- /development/afex_1.1-1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_1.1-1.tar.gz -------------------------------------------------------------------------------- /development/afex_1.2-0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_1.2-0.tar.gz -------------------------------------------------------------------------------- /development/afex_1.2-1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_1.2-1.tar.gz -------------------------------------------------------------------------------- /development/afex_1.3-0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_1.3-0.tar.gz -------------------------------------------------------------------------------- /development/afex_1.3-1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_1.3-1.tar.gz -------------------------------------------------------------------------------- /development/afex_1.4-1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/afex_1.4-1.tar.gz -------------------------------------------------------------------------------- /development/dataset.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/dataset.RDS -------------------------------------------------------------------------------- /development/emmeans_ses.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | library("afex") 4 | library("emmeans") 5 | data(md_12.1) 6 | a1 <- aov_ez("id", "rt", md_12.1, within = c("angle", "noise")) 7 | 8 | emm1 <- emmeans(a1, "angle") 9 | pairs(emm1) 10 | # contrast estimate SE df t.ratio p.value 11 | # X0 - X4 -108 18.9 18 -5.724 0.0001 12 | # X0 - X8 -168 18.9 18 -8.904 <.0001 13 | # X4 - X8 -60 18.9 18 -3.180 0.0137 14 | # 15 | # Results are averaged over the levels of: noise 16 | # P value adjustment: tukey method for comparing a family of 3 estimates 17 | 18 | 19 | emm2 <- emmeans(a1, "angle", model = "multivariate") 20 | pairs(emm2) 21 | # contrast estimate SE df t.ratio p.value 22 | # X0 - X4 -108 17.4 9 -6.194 0.0004 23 | # X0 - X8 -168 20.6 9 -8.159 0.0001 24 | # X4 - X8 -60 18.4 9 -3.254 0.0244 25 | # 26 | # Results are averaged over the levels of: noise 27 | # P value adjustment: tukey method for comparing a family of 3 estimates 28 | 29 | sessionInfo() 30 | # R version 4.0.3 (2020-10-10) 31 | # Platform: x86_64-w64-mingw32/x64 (64-bit) 32 | # Running under: Windows 10 x64 (build 19042) 33 | # 34 | # Matrix products: default 35 | # 36 | # locale: 37 | # [1] LC_COLLATE=English_United Kingdom.1252 38 | # [2] LC_CTYPE=English_United Kingdom.1252 39 | # [3] LC_MONETARY=English_United Kingdom.1252 40 | # [4] LC_NUMERIC=C 41 | # [5] LC_TIME=English_United Kingdom.1252 42 | # 43 | # attached base packages: 44 | # [1] stats graphics grDevices utils datasets methods base 45 | # 46 | # other attached packages: 47 | # [1] emmeans_1.5.3 afex_0.28-0 lme4_1.1-26 Matrix_1.3-2 48 | # 49 | # loaded via a namespace (and not attached): 50 | # [1] readxl_1.3.1 backports_1.2.1 jtools_2.1.2 51 | # [4] plyr_1.8.6 igraph_1.2.6 splines_4.0.3 52 | # [7] crosstalk_1.1.0.1 usethis_2.0.0 ggplot2_3.3.3 53 | # [10] TH.data_1.0-10 rstantools_2.1.1 inline_0.3.17 54 | # [13] digest_0.6.27 htmltools_0.5.0 rsconnect_0.8.16 55 | # [16] lmerTest_3.1-3 fansi_0.4.1 magrittr_2.0.1 56 | # [19] memoise_1.1.0 openxlsx_4.2.3 remotes_2.2.0 57 | # [22] RcppParallel_5.0.2 matrixStats_0.57.0 xts_0.12.1 58 | # [25] sandwich_3.0-0 prettyunits_1.1.1 colorspace_2.0-0 59 | # [28] haven_2.3.1 xfun_0.20 dplyr_1.0.2 60 | # [31] callr_3.5.1 crayon_1.3.4 jsonlite_1.7.2 61 | # [34] survival_3.2-7 zoo_1.8-8 glue_1.4.2 62 | # [37] gtable_0.3.0 V8_3.4.0 car_3.0-10 63 | # [40] pkgbuild_1.2.0 rstan_2.21.2 abind_1.4-5 64 | # [43] scales_1.1.1 mvtnorm_1.1-1 rstatix_0.6.0 65 | # [46] miniUI_0.1.1.1 Rcpp_1.0.5 xtable_1.8-4 66 | # [49] foreign_0.8-81 stats4_4.0.3 StanHeaders_2.21.0-7 67 | # [52] DT_0.17 htmlwidgets_1.5.3 threejs_0.3.3 68 | # [55] ellipsis_0.3.1 pkgconfig_2.0.3 loo_2.4.1 69 | # [58] tidyselect_1.1.0 rlang_0.4.10 reshape2_1.4.4 70 | # [61] later_1.1.0.1 munsell_0.5.0 cellranger_1.1.0 71 | # [64] tools_4.0.3 cli_2.2.0 generics_0.1.0 72 | # [67] devtools_2.3.2 broom_0.7.3 ggridges_0.5.3 73 | # [70] evaluate_0.14 stringr_1.4.0 fastmap_1.0.1 74 | # [73] yaml_2.2.1 processx_3.4.5 knitr_1.30 75 | # [76] fs_1.5.0 zip_2.1.1 pander_0.6.3 76 | # [79] purrr_0.3.4 nlme_3.1-151 mime_0.9 77 | # [82] rstanarm_2.21.1 compiler_4.0.3 pbkrtest_0.5-0.1 78 | # [85] bayesplot_1.8.0 shinythemes_1.1.2 rstudioapi_0.13 79 | # [88] curl_4.3 testthat_3.0.1 ggsignif_0.6.0 80 | # [91] tibble_3.0.4 statmod_1.4.35 stringi_1.5.3 81 | # [94] ps_1.5.0 desc_1.2.0 forcats_0.5.0 82 | # [97] lattice_0.20-41 nloptr_1.2.2.2 markdown_1.1 83 | # [100] shinyjs_2.0.0 vctrs_0.3.6 pillar_1.4.7 84 | # [103] lifecycle_0.2.0 estimability_1.3 data.table_1.13.6 85 | # [106] httpuv_1.5.4 R6_2.5.0 promises_1.1.1 86 | # [109] gridExtra_2.3 rio_0.5.16 sessioninfo_1.1.1 87 | # [112] codetools_0.2-18 boot_1.3-25 colourpicker_1.1.0 88 | # [115] MASS_7.3-53 gtools_3.8.2 assertthat_0.2.1 89 | # [118] pkgload_1.1.0 rprojroot_2.0.2 withr_2.3.0 90 | # [121] shinystan_2.5.0 multcomp_1.4-15 parallel_4.0.3 91 | # [124] hms_0.5.3 grid_4.0.3 tidyr_1.1.2 92 | # [127] coda_0.19-4 minqa_1.2.4 rmarkdown_2.6 93 | # [130] carData_3.0-4 ggpubr_0.4.0 numDeriv_2016.8-1.1 94 | # [133] shiny_1.5.0 base64enc_0.1-3 dygraphs_1.1.1.6 95 | 96 | 97 | ################################################################# 98 | ## new emmeans ## 99 | ################################################################# 100 | 101 | library("afex") 102 | library("emmeans") 103 | data(md_12.1) 104 | a1 <- aov_ez("id", "rt", md_12.1, within = c("angle", "noise")) 105 | 106 | emm1 <- emmeans(a1, "angle") 107 | pairs(emm1) 108 | # contrast estimate SE df t.ratio p.value 109 | # X0 - X4 -108 18.9 18 -5.724 0.0001 110 | # X0 - X8 -168 18.9 18 -8.904 <.0001 111 | # X4 - X8 -60 18.9 18 -3.180 0.0137 112 | # 113 | # Results are averaged over the levels of: noise 114 | # P value adjustment: tukey method for comparing a family of 3 estimates 115 | 116 | 117 | emm2 <- emmeans(a1, "angle", model = "multivariate") 118 | pairs(emm2) 119 | # contrast estimate SE df t.ratio p.value 120 | # X0 - X4 -108 17.4 9 -6.194 0.0004 121 | # X0 - X8 -168 20.6 9 -8.159 0.0001 122 | # X4 - X8 -60 18.4 9 -3.254 0.0244 123 | # 124 | # Results are averaged over the levels of: noise 125 | # P value adjustment: tukey method for comparing a family of 3 estimates 126 | -------------------------------------------------------------------------------- /development/freeman_models.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/freeman_models.rda -------------------------------------------------------------------------------- /development/potential_bug.R: -------------------------------------------------------------------------------- 1 | dataset <- readRDS("development/dataset.RDS") 2 | model <- tryCatch(afex::mixed( 3 | formula = as.formula("JaspColumn_.3._Encoded~JaspColumn_.1._Encoded*JaspColumn_.10._Encoded+(JaspColumn_.1._Encoded*JaspColumn_.10._Encoded|JaspColumn_.12._Encoded)"), 4 | data = dataset, 5 | type = "3", 6 | method = "LRT", 7 | test_intercept = FALSE, 8 | args_test = list(nsim = 500), 9 | check_contrasts = TRUE, 10 | #start = start, 11 | family = eval(call("binomial","logit")) 12 | ), error = function(e)return(e)) 13 | 14 | str(dataset) 15 | 16 | p <- afex::afex_plot( 17 | model, 18 | #dv = "JaspColumn_.3._Encoded", 19 | x = "JaspColumn_.10._Encoded", 20 | id = "JaspColumn_.12._Encoded", 21 | data_geom = getFromNamespace("geom_violin", "ggplot2"), 22 | mapping = c("shape","linetype","fill" ), 23 | error = "model", 24 | error_level = .95, 25 | data_alpha = .7, 26 | data_arg = list(width = 1, color = "darkgrey"), 27 | error_arg = list(width = 0, size = .5 * 1), 28 | point_arg = list(size = 1.5 * 1), 29 | line_arg = list(size = .5 * 1), 30 | legend_title= "", 31 | dodge = .3 32 | ) 33 | p 34 | 35 | -------------------------------------------------------------------------------- /development/stroop_mixed.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/development/stroop_mixed.rda -------------------------------------------------------------------------------- /doc/introduction-mixed-models.R: -------------------------------------------------------------------------------- 1 | ### This is an R script tangled from 'introduction-mixed-models.pdf.asis' 2 | -------------------------------------------------------------------------------- /doc/introduction-mixed-models.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/doc/introduction-mixed-models.pdf -------------------------------------------------------------------------------- /examples/examples.allFit.R: -------------------------------------------------------------------------------- 1 | 2 | \dontrun{ 3 | 4 | # basic usage 5 | require(optimx) 6 | gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), 7 | data = cbpp, family = binomial) 8 | gm_all <- all_fit(gm1) 9 | t(sapply(gm_all,fixef)) ## extract fixed effects 10 | sapply(gm_all,logLik) ## log-likelihoods 11 | sapply(gm_all,getME,"theta") ## theta parameters 12 | !sapply(gm_all,inherits,"try-error") ## was fit OK? 13 | 14 | 15 | ## for GLMMs: 16 | require("mlmRev") # for data 17 | gm1 <- mixed(use ~ age*urban + (1 | district), family = binomial, 18 | data = Contraception, method = "LRT") 19 | gm_all <- all_fit(gm1$full_model) 20 | sapply(gm_all,logLik) 21 | 22 | ## use allFit in combination with expand.re = TRUE 23 | data("sk2011.2") # see example("mixed") 24 | sk2_aff <- droplevels(sk2011.2[sk2011.2$what == "affirmation",]) 25 | sk_m2 <- mixed(response ~ instruction*inference*type+(inference*type||id), sk2_aff, 26 | expand_re = TRUE) 27 | sk_m2 28 | sk_m2_allFit <- all_fit(sk_m2$full_model) 29 | sk_m2_allFit # all fits fail 30 | 31 | sk_m2_allFit <- all_fit(sk_m2$full_model, data = sk_m2$data) # works 32 | t(sapply(sk_m2_allFit,fixef)) 33 | sapply(sk_m2_allFit,logLik) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /examples/examples.compare.R: -------------------------------------------------------------------------------- 1 | 2 | with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2])) 3 | 4 | # gives: 5 | ## $parametric 6 | ## test test.statistic test.value test.df p 7 | ## 1 t t -1.861 18.00 0.07919 8 | ## 2 Welch t -1.861 17.78 0.07939 9 | ## 10 | ## $nonparametric 11 | ## test test.statistic test.value test.df p 12 | ## 1 stats::Wilcoxon W 25.500 NA 0.06933 13 | ## 2 permutation Z -1.751 NA 0.08154 14 | ## 3 coin::Wilcoxon Z -1.854 NA 0.06487 15 | ## 4 median Z -1.744 NA 0.17867 16 | 17 | # compare with: 18 | with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2], 19 | alternative = "less")) 20 | 21 | with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2], 22 | alternative = "greater")) 23 | 24 | # doesn't make much sense as the data is not paired, but whatever: 25 | with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2], 26 | paired = TRUE)) 27 | 28 | # from ?t.test: 29 | compare.2.vectors(1:10,y=c(7:20, 200)) 30 | 31 | -------------------------------------------------------------------------------- /examples/examples.ems.R: -------------------------------------------------------------------------------- 1 | # 2x2 mixed anova 2 | # A varies between-subjects, B varies within-subjects 3 | ems(r ~ A*B*S, nested="A/S", random="S") 4 | 5 | # Clark (1973) example 6 | # random Subjects, random Words, fixed Treatments 7 | ems(r ~ S*W*T, nested="T/W", random="SW") 8 | 9 | # EMSs for Clark design if Words are fixed 10 | ems(r ~ S*W*T, nested="T/W", random="S") 11 | 12 | -------------------------------------------------------------------------------- /examples/examples.fhch2010.R: -------------------------------------------------------------------------------- 1 | 2 | data("fhch2010") 3 | str(fhch2010) 4 | 5 | a1 <- aov_ez("id", "log_rt", fhch2010, between = "task", 6 | within = c("density", "frequency", "length", "stimulus")) 7 | nice(a1) 8 | 9 | if (requireNamespace("emmeans") && requireNamespace("ggplot2")) { 10 | afex_plot(a1, "length", "frequency", c("task", "stimulus"), error = "within") 11 | 12 | afex_plot(a1, "density", "frequency", c("task", "stimulus"), error = "within") 13 | } 14 | 15 | 16 | \dontrun{ 17 | a2 <- aov_ez("id", "rt", fhch2010, between = "task", 18 | within = c("density", "frequency", "length", "stimulus")) 19 | nice(a2) 20 | 21 | if (requireNamespace("emmeans") && requireNamespace("ggplot2")) { 22 | afex_plot(a2, "length", "frequency", c("task", "stimulus"), error = "within") 23 | 24 | afex_plot(a2, "density", "frequency", c("task", "stimulus"), error = "within") 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/examples.helpers.R: -------------------------------------------------------------------------------- 1 | afex_options() # see all options 2 | 3 | afex_options("return_aov") #get single option 4 | 5 | aop <- afex_options() # save current options 6 | 7 | \dontrun{ 8 | # change options 9 | afex_options(return_aov = "nice") 10 | afex_options("return_aov") #get single option 11 | afex_options(return_aov = "nice", method_mixed = "LRT") 12 | afex_options("method_mixed") #get single option 13 | # do something 14 | } 15 | afex_options(aop) # reset options 16 | 17 | -------------------------------------------------------------------------------- /examples/examples.ks2013.3.R: -------------------------------------------------------------------------------- 1 | data("ks2013.3") 2 | 3 | # replicate results reported in Klauer & Singmann (2013, p. 1270) 4 | 5 | aov_ez("id", "response", ks2013.3, between = "condition", 6 | within = c("believability", "validity")) 7 | 8 | aov_ez("id", "response", subset(ks2013.3, condition == "fixed"), 9 | within = c("believability", "validity")) 10 | 11 | aov_ez("id", "response", subset(ks2013.3, condition == "random"), 12 | within = c("believability", "validity")) 13 | -------------------------------------------------------------------------------- /examples/examples.nice.R: -------------------------------------------------------------------------------- 1 | 2 | ## example from Olejnik & Algina (2003) 3 | # "Repeated Measures Design" (pp. 439): 4 | data(md_12.1) 5 | # create object of class afex_aov: 6 | rmd <- aov_ez("id", "rt", md_12.1, within = c("angle", "noise")) 7 | rmd 8 | nice(rmd) 9 | str(nice(rmd)) 10 | # use different es: 11 | nice(rmd, es = "pes") # noise: .82 12 | nice(rmd, es = "ges") # noise: .39 13 | 14 | # same data other approach: 15 | rmd2 <- aov_ez("id", "rt", md_12.1, within = c("angle", "noise"), 16 | anova_table=list(correction = "none", es = "none")) 17 | nice(rmd2) 18 | nice(rmd2, correction = "GG") 19 | nice(rmd2, correction = "GG", es = "ges") 20 | 21 | # exampel using obk.long (see ?obk.long), a long version of the OBrienKaiser dataset from car. 22 | data(obk.long) 23 | # create object of class afex_aov: 24 | tmp.aov <- aov_car(value ~ treatment * gender + Error(id/phase*hour), data = obk.long) 25 | 26 | nice(tmp.aov, observed = "gender") 27 | 28 | nice(tmp.aov, observed = "gender", sig_symbols = rep("", 4)) 29 | 30 | \dontrun{ 31 | # use package ascii or xtable for formatting of tables ready for printing. 32 | 33 | full <- nice(tmp.aov, observed = "gender") 34 | 35 | require(ascii) 36 | print(ascii(full, include.rownames = FALSE, caption = "ANOVA 1"), type = "org") 37 | 38 | require(xtable) 39 | print.xtable(xtable(full, caption = "ANOVA 2"), include.rownames = FALSE) 40 | } 41 | -------------------------------------------------------------------------------- /examples/examples.predict.R: -------------------------------------------------------------------------------- 1 | 2 | data(obk.long, package = "afex") 3 | 4 | # estimate mixed ANOVA on the full design: 5 | fit <- aov_ez("id", "value", obk.long, between = c("treatment", "gender"), 6 | within = c("phase", "hour"), observed = "gender") 7 | 8 | new_data <- expand.grid( 9 | treatment = "A", 10 | gender = "F", 11 | phase = c("pre", "post"), 12 | hour = c(1, 5) 13 | ) 14 | 15 | predict(fit, newdata = new_data) 16 | predict(fit, newdata = new_data, append = TRUE) -------------------------------------------------------------------------------- /examples/examples.residuals.R: -------------------------------------------------------------------------------- 1 | ### Setup ANOVAs 2 | data(obk.long, package = "afex") 3 | between <- aov_car(value ~ treatment*gender + Error(id), data = obk.long) 4 | within <- aov_car(value ~ 1 + Error(id/(phase*hour)), data = obk.long) 5 | mixed <- aov_car(value ~ treatment * gender + Error(id/(phase*hour)), data = obk.long) 6 | 7 | # All residuals call produce the message that the data was changed during calculation. 8 | residuals(within) 9 | residuals(mixed) 10 | residuals(between) 11 | 12 | ## Get residuals plus data used for fitting: 13 | residuals(within, append = TRUE) 14 | residuals(mixed, append = TRUE) 15 | residuals(between, append = TRUE) 16 | 17 | ### in case data is correctly ordered before fitting, this message is not shown 18 | 19 | ## between data: 20 | obk2 <- aggregate(value ~ gender + treatment + id , data = obk.long, FUN = mean) 21 | between2 <- aov_car(value ~ treatment*gender + Error(id), data = obk2) 22 | 23 | residuals(between2) ## no message 24 | all.equal(obk2, between2$data$long[,colnames(obk2)]) ## TRUE 25 | 26 | # Therefore okay: 27 | obk2$residuals <- residuals(between2) 28 | 29 | ## within data 30 | obk3 <- obk.long[with(obk.long, order(id, phase, hour)), ] 31 | within2 <- aov_car(value ~ 1 + Error(id/(phase*hour)), data = obk3) 32 | residuals(within2) ## no message, because order is correct 33 | # Therefore okay: 34 | obk3$residuals <- residuals(within2) 35 | 36 | ## Same for fitted values: 37 | # (show message) 38 | fitted(within) 39 | fitted(mixed) 40 | fitted(between) 41 | 42 | ## Get fitted values plus data used for fitting: 43 | fitted(within, append = TRUE) 44 | fitted(mixed, append = TRUE) 45 | fitted(between, append = TRUE) 46 | 47 | ## No message: 48 | fitted(between2) 49 | fitted(within2) 50 | 51 | #### residuals() and fitted() methods can be used for plotting 52 | ### requires package ggResidpanel 53 | if (require("ggResidpanel")) { 54 | resid_auxpanel(residuals = residuals(mixed), predicted = fitted(mixed)) 55 | 56 | \dontrun{ 57 | ## suppress Messages: 58 | suppressMessages( 59 | resid_auxpanel(residuals = residuals(mixed), predicted = fitted(mixed)) 60 | ) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /examples/examples.sk2011.2.R: -------------------------------------------------------------------------------- 1 | data("sk2011.2") 2 | 3 | ## remove excluded participants: 4 | 5 | sk2_final <- droplevels(sk2011.2[!(sk2011.2$id %in% c(7, 8, 9, 12, 16, 17, 24, 30)),]) 6 | str(sk2_final) 7 | 8 | ## Table 2 (inference = problem): 9 | aov_ez("id", "response", sk2_final[sk2_final$what == "affirmation",], 10 | between = "instruction", within = c("inference", "type"), 11 | anova_table=list(es = "pes")) 12 | 13 | aov_ez("id", "response", sk2_final[sk2_final$what == "denial",], 14 | between = "instruction", within = c("inference", "type"), 15 | anova_table=list(es = "pes")) 16 | 17 | # Recreate Figure 4 (corrected version): 18 | 19 | sk2_aff <- droplevels(sk2_final[sk2_final$what == "affirmation",]) 20 | sk2_aff$type2 <- factor(sk2_aff$inference:sk2_aff$type, levels = c("MP:prological", 21 | "MP:neutral", "MP:counterlogical", "AC:counterlogical", 22 | "AC:neutral", "AC:prological")) 23 | a1_b <- aov_ez("id", "response", sk2_aff, 24 | between = "instruction", within = c("type2")) 25 | 26 | sk2_den <- droplevels(sk2_final[sk2_final$what == "denial",]) 27 | sk2_den$type2 <- factor(sk2_den$inference:sk2_den$type, levels = c("MT:prological", 28 | "MT:neutral", "MT:counterlogical", "DA:counterlogical", 29 | "DA:neutral","DA:prological")) 30 | a2_b <- aov_ez("id", "response", sk2_den, 31 | between = "instruction", within = c("type2")) 32 | 33 | if (requireNamespace("emmeans") && requireNamespace("ggplot2")) { 34 | afex_plot(a1_b,"type2", "instruction") + 35 | ggplot2::coord_cartesian(ylim = c(0, 100)) 36 | afex_plot(a2_b,"type2", "instruction") + 37 | ggplot2::coord_cartesian(ylim = c(0, 100)) 38 | } 39 | -------------------------------------------------------------------------------- /inst/extdata/output_afex_plot_mixed_vignette.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/inst/extdata/output_afex_plot_mixed_vignette.rda -------------------------------------------------------------------------------- /inst/extdata/output_afex_plot_mixed_vignette_model.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/inst/extdata/output_afex_plot_mixed_vignette_model.rda -------------------------------------------------------------------------------- /inst/extdata/output_mixed_vignette.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/inst/extdata/output_mixed_vignette.rda -------------------------------------------------------------------------------- /inst/extdata/outputs_glmm_vignette.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/inst/extdata/outputs_glmm_vignette.rda -------------------------------------------------------------------------------- /inst/extdata/plots_brms.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/inst/extdata/plots_brms.rda -------------------------------------------------------------------------------- /inst/extdata/plots_rstanarm.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/inst/extdata/plots_rstanarm.rda -------------------------------------------------------------------------------- /inst/extdata/tmb_example_fit.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/inst/extdata/tmb_example_fit.rda -------------------------------------------------------------------------------- /man/afex-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/afex-package.R 3 | \docType{package} 4 | \name{afex-package} 5 | \alias{afex} 6 | \alias{afex-package} 7 | \title{\packageTitle{afex}} 8 | \description{ 9 | \packageDescription{afex} 10 | } 11 | \details{ 12 | The DESCRIPTION file: 13 | \packageDESCRIPTION{afex} 14 | } 15 | \seealso{ 16 | Useful links: 17 | \itemize{ 18 | \item \url{https://afex.singmann.science/} 19 | \item \url{https://github.com/singmann/afex} 20 | \item Report bugs at \url{https://github.com/singmann/afex/issues} 21 | } 22 | 23 | } 24 | \author{ 25 | \strong{Maintainer}: Henrik Singmann \email{singmann@gmail.com} (\href{https://orcid.org/0000-0002-4842-3657}{ORCID}) 26 | 27 | Authors: 28 | \itemize{ 29 | \item Ben Bolker 30 | \item Jake Westfall 31 | \item Frederik Aust (\href{https://orcid.org/0000-0003-4900-788X}{ORCID}) 32 | \item Mattan S. Ben-Shachar 33 | } 34 | 35 | Other contributors: 36 | \itemize{ 37 | \item Søren Højsgaard [contributor] 38 | \item John Fox [contributor] 39 | \item Michael A. Lawrence [contributor] 40 | \item Ulf Mertens [contributor] 41 | \item Jonathon Love [contributor] 42 | \item Russell Lenth [contributor] 43 | \item Rune Haubo Bojesen Christensen [contributor] 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/afex_aov-methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/methods.afex_aov.R 3 | \name{afex_aov-methods} 4 | \alias{afex_aov-methods} 5 | \alias{anova.afex_aov} 6 | \alias{print.afex_aov} 7 | \alias{summary.afex_aov} 8 | \alias{recover_data.afex_aov} 9 | \alias{emm_basis.afex_aov} 10 | \title{Methods for afex_aov objects} 11 | \usage{ 12 | \method{anova}{afex_aov}( 13 | object, 14 | es = afex_options("es_aov"), 15 | observed = NULL, 16 | correction = afex_options("correction_aov"), 17 | MSE = TRUE, 18 | intercept = FALSE, 19 | p_adjust_method = NULL, 20 | sig_symbols = attr(object$anova_table, "sig_symbols"), 21 | ... 22 | ) 23 | 24 | \method{print}{afex_aov}(x, ...) 25 | 26 | \method{summary}{afex_aov}(object, ...) 27 | 28 | recover_data.afex_aov(object, ..., model = afex_options("emmeans_model")) 29 | 30 | emm_basis.afex_aov( 31 | object, 32 | trms, 33 | xlev, 34 | grid, 35 | ..., 36 | model = afex_options("emmeans_model") 37 | ) 38 | } 39 | \arguments{ 40 | \item{object, x}{object of class \code{afex_aov} as returned from 41 | \code{\link{aov_car}} and related functions.} 42 | 43 | \item{es}{Effect Size to be reported. The default is given by 44 | \code{afex_options("es_aov")}, which is initially set to \code{"ges"} 45 | (i.e., reporting generalized eta-squared, see details). Also supported is 46 | partial eta-squared (\code{"pes"}) or \code{"none"}.} 47 | 48 | \item{observed}{character vector referring to the observed (i.e., non 49 | manipulated) variables/effects in the design. Important for calculation of 50 | generalized eta-squared (ignored if \code{es} is not \code{"ges"}), see 51 | details.} 52 | 53 | \item{correction}{Character. Which sphericity correction of the degrees of 54 | freedom should be reported for the within-subject factors. The default is 55 | given by \code{afex_options("correction_aov")}, which is initially set to 56 | \code{"GG"} corresponding to the Greenhouse-Geisser correction. Possible 57 | values are \code{"GG"}, \code{"HF"} (i.e., Hyunh-Feldt correction), and 58 | \code{"none"} (i.e., no correction).} 59 | 60 | \item{MSE}{logical. Should the column containing the Mean Sqaured Error (MSE) 61 | be displayed? Default is \code{TRUE}.} 62 | 63 | \item{intercept}{logical. Should intercept (if present) be included in the 64 | ANOVA table? Default is \code{FALSE} which hides the intercept.} 65 | 66 | \item{p_adjust_method}{\code{character} indicating if p-values for individual 67 | effects should be adjusted for multiple comparisons (see 68 | \link[stats]{p.adjust} and details).} 69 | 70 | \item{sig_symbols}{Character. What should be the symbols designating 71 | significance? When entering an vector with \code{length(sig.symbol) < 4} 72 | only those elements of the default (\code{c(" +", " *", " **", " ***")}) 73 | will be replaced. \code{sig_symbols = ""} will display the stars but not 74 | the \code{+}, \code{sig_symbols = rep("", 4)} will display no symbols. The 75 | default is given by \code{afex_options("sig_symbols")}.} 76 | 77 | \item{...}{further arguments passed through, see description of return value 78 | for details.} 79 | 80 | \item{model}{argument for \code{\link[emmeans]{emmeans}()} and related 81 | functions that allows to choose on which model the follow-up tests for 82 | ANOVAs with repeated-measures factors are based. \code{"multivariate"} (the 83 | default) uses the \code{lm} model and \code{"univariate"} uses the 84 | \code{aov} model. Default given by \code{afex_options("emmeans_mode")}. 85 | Multivariate tests likely work better for unbalanced data and provide a 86 | better correction for violations of sphericity.} 87 | 88 | \item{trms, xlev, grid}{same as for \code{\link[emmeans]{emm_basis}}.} 89 | } 90 | \value{ 91 | \describe{ 92 | \item{\code{anova}}{Returns an ANOVA table of class \code{c("anova", 93 | "data.frame")}. Information such as effect size (\code{es}) or 94 | df-correction are calculated each time this method is called.} 95 | \item{\code{summary}}{For ANOVAs containing within-subject factors it 96 | returns the full output of the within-subject tests: the uncorrected 97 | results, results containing Greenhousse-Geisser and Hyunh-Feldt correction, 98 | and the results of the Mauchly test of sphericity (all achieved via 99 | \code{summary.Anova.mlm}). For other ANOVAs, the \code{anova} table is 100 | simply returned.} 101 | \item{\code{print}}{Prints (and invisibly returns) the ANOVA table as 102 | constructed from \code{\link{nice}} (i.e., as strings rounded nicely). 103 | Arguments in \code{...} are passed to \code{nice} allowing to pass 104 | arguments such as \code{es} and \code{correction}.} 105 | \item{\code{recover_data} and \code{emm_basis}}{Provide the backbone for 106 | using \code{\link[emmeans]{emmeans}} and related functions from 107 | \pkg{emmeans} directly on \code{afex_aov} objects by returning a 108 | \code{\link[emmeans]{emmGrid-class}} object. Should not be called directly 109 | but through the functionality provided by \pkg{emmeans}.} 110 | } 111 | } 112 | \description{ 113 | Methods defined for objects returned from the ANOVA functions 114 | \code{\link{aov_car}} et al. of class \code{afex_aov} containing both the 115 | ANOVA fitted via \code{car::Anova} and base R's \code{aov}. 116 | } 117 | \details{ 118 | Exploratory ANOVA, for which no detailed hypotheses have been specified a 119 | priori, harbor a multiple comparison problem (Cramer et al., 2015). To avoid 120 | an inflation of familywise Type I error rate, results need to be corrected 121 | for multiple comparisons using \code{p_adjust_method}. \code{p_adjust_method} 122 | defaults to the method specified in the call to \code{\link{aov_car}} in 123 | \code{anova_table}. If no method was specified and \code{p_adjust_method = 124 | NULL} p-values are not adjusted. 125 | } 126 | \references{ 127 | Cramer, A. O. J., van Ravenzwaaij, D., Matzke, D., Steingroever, H., Wetzels, 128 | R., Grasman, R. P. P. P., ... Wagenmakers, E.-J. (2015). Hidden multiplicity 129 | in exploratory multiway ANOVA: Prevalence and remedies. \emph{Psychonomic 130 | Bulletin & Review}, 1-8. \doi{10.3758/s13423-015-0913-5} 131 | } 132 | \seealso{ 133 | \code{residuals} and \code{fitted} methods also exists for 134 | \code{afex_aov} objects, see: \code{\link{residuals.afex_aov}}. 135 | } 136 | -------------------------------------------------------------------------------- /man/afex_options.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/helpers.R 3 | \name{afex_options} 4 | \alias{afex_options} 5 | \title{Set/get global afex options} 6 | \usage{ 7 | afex_options(...) 8 | } 9 | \arguments{ 10 | \item{...}{One of four: (1) nothing, then returns all options as a list; (2) 11 | a name of an option element, then returns its' value; (3) a name-value pair 12 | which sets the corresponding option to the new value (and returns nothing), 13 | (4) a list with option-value pairs which sets all the corresponding 14 | arguments. The example show all possible cases.} 15 | } 16 | \value{ 17 | depends on input, see above. 18 | } 19 | \description{ 20 | Global afex options are used, for example, by \code{\link{aov_car}} (et al.) 21 | and \code{\link{mixed}}. But can be changed in each functions directly using 22 | an argument (which has precedence over the global options). 23 | } 24 | \details{ 25 | The following arguments are currently set: 26 | \itemize{ 27 | \item \code{check_contrasts} should contrasts be checked and changed to 28 | sum-to-zero contrasts? Default is \code{TRUE}. 29 | \item \code{type} type of sums-of-squares to be used for testing effects, 30 | default is 3 which reports Type 3 tests. 31 | \item \code{method_mixed}: Method used to obtain p-values in 32 | \code{\link{mixed}}, default is \code{"KR"} (which will change to 33 | \code{"LRT"} soon). (\code{mixed()} only) 34 | \item \code{es_aov}: Effect size reported for ANOVAs (see 35 | \code{\link{aov_car}}), default is \code{"ges"} (generalized eta-squared). 36 | \item \code{correction_aov}: Correction used for within-subjects factors with 37 | more than two levels for ANOVAs (see \code{\link{aov_car}} or 38 | \code{\link{nice}}), default is \code{"GG"} (Greenhouse-Geisser correction). 39 | (ANOVA functions only) 40 | \item \code{emmeans_model}: Which model should be used by \pkg{emmeans} for 41 | follow-up analysis of ANOVAs (i.e., objects pf class \code{"afex_aov"})? 42 | Default is \code{"univariate"} which uses the \code{aov} model object (if 43 | present). The other option is \code{"multivariate"} which uses the \code{lm} 44 | model object (which is an object of class \code{"mlm"} in case 45 | repeated-measures factors are present). 46 | \item \code{include_aov}: Should the \code{aov} model be included into ANOVA objects of class \code{"afex_aov"}? Setting this to \code{FALSE} can lead to considerable speed improvements. 47 | \item \code{factorize}: Should between subject factors be factorized (with 48 | note) before running the analysis? Default is \code{TRUE}. (ANOVA functions 49 | only) 50 | \item \code{sig_symbols}: Default significant symbols used for ANOVA and 51 | \code{mixed} printing. Default is\code{c(" +", " *", " **", " ***")}. 52 | \item \code{lmer_function}: Which \code{lmer} function should \code{mixed} or 53 | \code{lmer_alt} use. The default is \code{"lmerTest"} which uses 54 | \code{\link[lmerTest]{lmer}}, \code{"lme4"} is also possible which uses 55 | \code{\link[lme4]{lmer}}. Note that \code{mixed} methods \code{"KR"} and 56 | \code{"S"} only work with \code{"lmerTest"}. For the other methods, 57 | \code{"lme4"} could be minimally faster, but does not allow to use 58 | \code{lmerTest::anova()}. 59 | \item \code{return_aov}: Return value of the ANOVA functions (see 60 | \code{\link{aov_car}}), default is \code{"nice"}. 61 | } 62 | } 63 | \note{ 64 | All options are saved in the global R \code{\link{options}} with prefix 65 | \code{afex.} 66 | } 67 | \examples{ 68 | afex_options() # see all options 69 | 70 | afex_options("return_aov") #get single option 71 | 72 | aop <- afex_options() # save current options 73 | 74 | \dontrun{ 75 | # change options 76 | afex_options(return_aov = "nice") 77 | afex_options("return_aov") #get single option 78 | afex_options(return_aov = "nice", method_mixed = "LRT") 79 | afex_options("method_mixed") #get single option 80 | # do something 81 | } 82 | afex_options(aop) # reset options 83 | 84 | } 85 | -------------------------------------------------------------------------------- /man/compare.2.vectors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compare.2.vectors.R 3 | \encoding{UTF-8} 4 | \name{compare.2.vectors} 5 | \alias{compare.2.vectors} 6 | \title{Compare two vectors using various tests.} 7 | \usage{ 8 | compare.2.vectors(x, y, paired = FALSE, na.rm = FALSE, 9 | tests = c("parametric", "nonparametric"), coin = TRUE, 10 | alternative = "two.sided", 11 | perm.distribution, 12 | wilcox.exact = NULL, wilcox.correct = TRUE) 13 | } 14 | \arguments{ 15 | \item{x}{a (non-empty) numeric vector of data values.} 16 | 17 | \item{y}{a (non-empty) numeric vector of data values.} 18 | 19 | \item{paired}{a logical whether the data is paired. Default is \code{FALSE}.} 20 | 21 | \item{na.rm}{logical. Should \code{NA} be removed? Default is \code{FALSE}.} 22 | 23 | \item{tests}{Which tests to report, parametric or nonparamteric? The default \code{c("parametric", "nonparametric")} reports both. See details. (Arguments may be abbreviated).} 24 | 25 | \item{coin}{logical or character. Should (permutation) tests from the \pkg{coin} package be reported? Default is \code{TRUE} corresponding to all implemented tests. \code{FALSE} calculates no tests from \pkg{coin}. A character vector may include any of the following (potentially abbreviated) implemented tests (see also Details): \code{c("permutation", "Wilcoxon", "median")}} 26 | 27 | \item{alternative}{a character, the alternative hypothesis must be one of \code{"two.sided"} (default), \code{"greater"} or \code{"less"}. You can specify just the initial letter, will be passed to all functions.} 28 | 29 | \item{perm.distribution}{\code{distribution} argument to \pkg{coin}, see \code{\link[coin]{NullDistribution}} or , \code{\link[coin]{IndependenceTest}}. If missing, defaults to \code{coin::approximate(100000)} indicating an approximation of the excat conditional distribution with 100.000 Monte Carlo samples. One can use \code{"exact"} for small samples and if \code{paired = FALSE}.} 30 | 31 | \item{wilcox.exact}{\code{exact} argument to \code{\link{wilcox.test}}.} 32 | 33 | \item{wilcox.correct}{\code{correct} argument to \code{\link{wilcox.test}}.} 34 | } 35 | \value{ 36 | a list with up to two elements (i.e., \code{paramteric} and/or \code{nonparamteric}) each containing a \code{data.frame} with the following columns: \code{test}, \code{test.statistic}, \code{test.value}, \code{test.df}, \code{p}. 37 | } 38 | \description{ 39 | Compares two vectors \code{x} and \code{y} using t-test, Welch-test (also known as Satterthwaite), Wilcoxon-test, and a permutation test implemented in \pkg{coin}. 40 | } 41 | \details{ 42 | The \code{parametric} tests (currently) only contain the \emph{t}-test and Welch/Statterwaithe/Smith/unequal variance \emph{t}-test implemented in \code{\link{t.test}}. The latter one is only displayed if \code{paired = FALSE}. 43 | 44 | The \code{nonparametric} tests (currently) contain the Wilcoxon test implemented in \code{\link{wilcox.test}} (\code{stats::Wilcoxon}) and (if \code{coin = TRUE}) the following tests implemented in \pkg{coin}: 45 | 46 | \itemize{ 47 | \item a \code{permutation} test \code{\link[coin]{oneway_test}} (the only test in this selction not using a rank transformation), 48 | \item the \code{Wilcoxon} test \code{\link[coin]{wilcox_test}} (\code{coin::Wilcoxon}), and 49 | \item the \code{median} test \code{\link[coin]{median_test}}. 50 | } 51 | Note that the two implementations of the Wilcoxon test probably differ. This is due to differences in the calculation of the Null distributions. 52 | } 53 | \examples{ 54 | 55 | with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2])) 56 | 57 | # gives: 58 | ## $parametric 59 | ## test test.statistic test.value test.df p 60 | ## 1 t t -1.861 18.00 0.07919 61 | ## 2 Welch t -1.861 17.78 0.07939 62 | ## 63 | ## $nonparametric 64 | ## test test.statistic test.value test.df p 65 | ## 1 stats::Wilcoxon W 25.500 NA 0.06933 66 | ## 2 permutation Z -1.751 NA 0.08154 67 | ## 3 coin::Wilcoxon Z -1.854 NA 0.06487 68 | ## 4 median Z -1.744 NA 0.17867 69 | 70 | # compare with: 71 | with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2], 72 | alternative = "less")) 73 | 74 | with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2], 75 | alternative = "greater")) 76 | 77 | # doesn't make much sense as the data is not paired, but whatever: 78 | with(sleep, compare.2.vectors(extra[group == 1], extra[group == 2], 79 | paired = TRUE)) 80 | 81 | # from ?t.test: 82 | compare.2.vectors(1:10,y=c(7:20, 200)) 83 | 84 | } 85 | -------------------------------------------------------------------------------- /man/deprecated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated.R 3 | \name{test_levene} 4 | \alias{test_levene} 5 | \alias{afex-deprecated} 6 | \alias{test_sphericity} 7 | \title{Deprecated functions} 8 | \usage{ 9 | test_levene(...) 10 | 11 | test_sphericity(...) 12 | } 13 | \arguments{ 14 | \item{...}{arguments passed from the old functions of the style 15 | \code{foo.bar()} to the new functions \code{foo_bar()}} 16 | } 17 | \description{ 18 | These functions have been renamed or moved and deprecated in \pkg{afex}: 19 | \code{test_levene()} (use \code{\link[performance]{check_homogeneity}()}), 20 | \code{test_sphericity()} (use \code{\link[performance]{check_sphericity}()}). 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/ems.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ems.R 3 | \name{ems} 4 | \alias{ems} 5 | \title{Expected values of mean squares for factorial designs 6 | 7 | Implements the Cornfield-Tukey algorithm for deriving the expected values of the mean squares for factorial designs.} 8 | \usage{ 9 | ems(design, nested = NULL, random = "") 10 | } 11 | \arguments{ 12 | \item{design}{A \code{formula} object specifying the factors in the design (except residual error, which is always implicitly included). The left hand side of the \code{~} is the symbol that will be used to denote the number of replications per lowest-level factor combination (I usually use "r" or "n"). The right hand side should include all fixed and random factors separated by \code{*}. Factor names should be single letters.} 13 | 14 | \item{nested}{A \code{character} vector, where each element is of the form \code{"A/B"}, indicating that the levels of factor B are nested under the levels of factor A.} 15 | 16 | \item{random}{A \code{character} string indicating, without spaces or any separating characters, which of the factors specified in the design are random.} 17 | } 18 | \value{ 19 | The returned value is a formatted table where the rows represent the mean squares, the columns represent the variance components that comprise the various mean squares, and the entries in each cell represent the terms that are multiplied and summed to form the expectation of the mean square for that row. Each term is either the lower-case version of one of the experimental factors, which indicates the number of levels for that factor, or a "1", which means the variance component for that column is contributes to the mean square but is not multiplied by anything else. 20 | } 21 | \description{ 22 | Expected values of mean squares for factorial designs 23 | 24 | Implements the Cornfield-Tukey algorithm for deriving the expected values of the mean squares for factorial designs. 25 | } 26 | \note{ 27 | Names for factors or parameters should only be of length 1 as they are simply concatenated in the returned table. 28 | } 29 | \examples{ 30 | # 2x2 mixed anova 31 | # A varies between-subjects, B varies within-subjects 32 | ems(r ~ A*B*S, nested="A/S", random="S") 33 | 34 | # Clark (1973) example 35 | # random Subjects, random Words, fixed Treatments 36 | ems(r ~ S*W*T, nested="T/W", random="SW") 37 | 38 | # EMSs for Clark design if Words are fixed 39 | ems(r ~ S*W*T, nested="T/W", random="S") 40 | 41 | } 42 | \seealso{ 43 | A detailed description with explanation of the example can be found \href{https://web.archive.org/web/20210805121242/http://www.talkstats.com/threads/share-your-functions-code.18603/page-9#post-82050}{elsewhere} (note that the \code{design} argument of the function described at the link behaves slightly different). 44 | 45 | Example applications of this function can be found here: \url{https://stats.stackexchange.com/a/122662/442}. 46 | } 47 | \author{ 48 | Jake Westfall 49 | } 50 | -------------------------------------------------------------------------------- /man/fhch2010.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fhch2010-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{fhch2010} 6 | \alias{fhch2010} 7 | \title{Data from Freeman, Heathcote, Chalmers, & Hockley (2010)} 8 | \format{ 9 | A \code{data.frame} with 13,222 obs. of 9 variables: 10 | \describe{ 11 | \item{id}{participant id, \code{factor}} 12 | \item{task}{\code{factor} with two levels indicating which task was performed: \code{"naming"} or \code{"lexdec"}} 13 | \item{stimulus}{\code{factor} indicating whether the shown stimulus was a \code{"word"} or \code{"nonword"}} 14 | \item{density}{\code{factor} indicating the neighborhood density of presented items with two levels: \code{"low"} and \code{"high"}. Density is defined as the number of words that differ from a base word by one letter or phoneme.} 15 | \item{frequency}{\code{factor} indicating the word frequency of presented items with two levels: \code{"low"} (i.e., words that occur less often in natural language) and \code{"high"} (i.e., words that occur more often in natural language).} 16 | \item{length}{\code{factor} with 3 levels (4, 5, or 6) indicating the number of characters of presented stimuli.} 17 | \item{item}{\code{factor} with 600 levels: 300 words and 300 nonwords} 18 | \item{rt}{response time in seconds} 19 | \item{log_rt}{natural logarithm of response time in seconds} 20 | \item{correct}{boolean indicating whether or not the response in the lexical decision task was correct or incorrect (incorrect responses of the naming task are not part of the data).} 21 | } 22 | } 23 | \source{ 24 | Freeman, E., Heathcote, A., Chalmers, K., & Hockley, W. (2010). Item effects in recognition memory for words. Journal of Memory and Language, 62(1), 1-18. http://doi.org/10.1016/j.jml.2009.09.004 25 | } 26 | \usage{ 27 | fhch2010 28 | } 29 | \description{ 30 | Lexical decision and word naming latencies for 300 words and 300 nonwords presented in Freeman, Heathcote, Chalmers, and Hockley (2010). The study had one between-subjects factors, \code{"task"} with two levels (\code{"naming"} or \code{"lexdec"}), and four within-subjects factors: \code{"stimulus"} type with two levels (\code{"word"} or \code{"nonword"}), word \code{"density"} and word \code{"frequency"} each with two levels (\code{"low"} and \code{"high"}) and stimulus \code{"length"} with three levels (4, 5, and 6). 31 | } 32 | \details{ 33 | In the lexical-decision condition (N = 25), subjects indicated whether each item was a word or a nonword, by pressing either the left (labeled word) or right (labeled nonword) outermost button on a 6-button response pad. The next study item appeared immediately after the lexical decision response was given. In the naming condition (N = 20), subjects were asked to name each item aloud, and items remained on screen for 3 s. Naming time was recorded by a voice key. 34 | 35 | Items consisted of 300 words, 75 in each set making up a factorial combination of high and low density and frequency, and 300 nonwords, with equal numbers of 4, 5, and 6 letter items in each set. 36 | } 37 | \examples{ 38 | 39 | data("fhch2010") 40 | str(fhch2010) 41 | 42 | a1 <- aov_ez("id", "log_rt", fhch2010, between = "task", 43 | within = c("density", "frequency", "length", "stimulus")) 44 | nice(a1) 45 | 46 | if (requireNamespace("emmeans") && requireNamespace("ggplot2")) { 47 | afex_plot(a1, "length", "frequency", c("task", "stimulus"), error = "within") 48 | 49 | afex_plot(a1, "density", "frequency", c("task", "stimulus"), error = "within") 50 | } 51 | 52 | 53 | \dontrun{ 54 | a2 <- aov_ez("id", "rt", fhch2010, between = "task", 55 | within = c("density", "frequency", "length", "stimulus")) 56 | nice(a2) 57 | 58 | if (requireNamespace("emmeans") && requireNamespace("ggplot2")) { 59 | afex_plot(a2, "length", "frequency", c("task", "stimulus"), error = "within") 60 | 61 | afex_plot(a2, "density", "frequency", c("task", "stimulus"), error = "within") 62 | } 63 | } 64 | } 65 | \keyword{dataset} 66 | -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/man/figures/README-unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/man/figures/README-unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/man/figures/README-unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/man/figures/README-unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/man/figures/README-unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /man/ks2013.3.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ks2013.3-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{ks2013.3} 6 | \alias{ks2013.3} 7 | \title{Data from Klauer & Singmann (2013, Experiment 3)} 8 | \format{ 9 | A data.frame with 1440 rows and 6 variables. 10 | } 11 | \source{ 12 | Klauer, K. C., & Singmann, H. (2013). Does logic feel good? Testing for intuitive detection of logicality in syllogistic reasoning. Journal of Experimental Psychology: Learning, Memory, and Cognition, 39(4), 1265-1273. http://doi.org/10.1037/a0030530 13 | 14 | Morsanyi, K., & Handley, S. J. (2012). Logic feels so good-I like it! Evidence for intuitive detection of logicality in syllogistic reasoning. Journal of Experimental Psychology: Learning, Memory, and Cognition, 38(3), 596-616. http://doi.org/10.1037/a0026099 15 | } 16 | \usage{ 17 | ks2013.3 18 | } 19 | \description{ 20 | Klauer and Singmann (2013) attempted to replicate an hypothesis of Morsanyi and Handley (2012) according to which individuals have an intuitive sense of logicality. Specifically, Morsanyi and Handley apparently provided evidence that the logical status of syllogisms (i.e., valid or invalid) affects participants liking ratings of the conclusion of syllogisms. Conclusions from valid syllogisms (e.g., Some snakes are poisonous. No poisonous animals are obbs. Some snakes are not obbs.) received higher liking ratings than conclusions from invalid syllogisms (e.g., No ice creams are vons. Some vons are hot. Some ice creams are not hot.). It is important to noted that in the experiments participants were simply shown the premises and conclusion in succession, they were not asked whether or not the conclusion follows or to generate their own conclusion. Their task was simply to judge how much they liked the "final" statement (i.e., the conclusion). 21 | } 22 | \details{ 23 | In their Experiment 3 Klauer and Singmann (2013) tested the idea that this finding was a consequence of the materials used and not an effect intuitive logic. More specifically, they observed that in the original study by Morsanyi and Handley (2012) a specific content always appeared with the same logical status. For example, the "ice-cream" content only ever appeared as an invalid syllogism as in the example above but never in a valid syllogism. In other words, content was perfectly confounded with logical status in the original study. To test this they compared a condition in which the logical status was confounded with the content (the "fixed" condition) with a condition in which the contents were randomly assigned to a logical status across participants (the "random" condition). For example, the ice-cream content was, across participants, equally like to appear in the invalid form as given above or in the following valid form: No hot things are vons. Some vons are ice creams. Conclusion Some ice creams are not hot. 24 | 25 | The data.frame contains the raw responses of all 60 participants (30 per condition) reported in Klauer & Singmann (2013). Each participants provided 24 responses, 12 to valid and 12 to invalid syllogisms. Furthermore, 8 syllogisms had a believable conclusion (e.g., Some ice creams are not hot.), 8 had an abstract conclusion (e.g., Some snakes are not obbs.), and 8 had an unbelievable conclusion (e.g., Some animals are not monkeys.). The number of the contents corresponds to the numbering given in Morsanyi and Handley (2012, p. 616). 26 | } 27 | \examples{ 28 | data("ks2013.3") 29 | 30 | # replicate results reported in Klauer & Singmann (2013, p. 1270) 31 | 32 | aov_ez("id", "response", ks2013.3, between = "condition", 33 | within = c("believability", "validity")) 34 | 35 | aov_ez("id", "response", subset(ks2013.3, condition == "fixed"), 36 | within = c("believability", "validity")) 37 | 38 | aov_ez("id", "response", subset(ks2013.3, condition == "random"), 39 | within = c("believability", "validity")) 40 | } 41 | \keyword{dataset} 42 | -------------------------------------------------------------------------------- /man/laptop_urry.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/laptop_urry-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{laptop_urry} 6 | \alias{laptop_urry} 7 | \title{Replication of Laptop Note Taking Study (Urry et al. 2021, Psych. Science)} 8 | \format{ 9 | A data frame with 142 rows and 6 variables: 10 | \describe{ 11 | \item{pid}{participant id, factor with 142 levels} 12 | \item{condition}{experimental condition (laptop, longhand), factor with 2 levels} 13 | \item{talk}{TED talk seen by participant, factor with 5 levels} 14 | \item{overall}{overall memory score ranging from 0 (= no memory) to 100 (= perfect memory).} 15 | \item{factual}{memory score on the factual questions ranging from 0 (= no memory) to 100 (= perfect memory).} 16 | \item{conceptual}{memory score on the conceptual questions ranging from 0 (= no memory) to 100 (= perfect memory).} 17 | } 18 | } 19 | \source{ 20 | Urry, H. L., Crittle, C. S., Floerke, V. A., Leonard, M. Z., Perry, 21 | C. S., Akdilek, N., Albert, E. R., Block, A. J., Bollinger, C. A., Bowers, 22 | E. M., Brody, R. S., Burk, K. C., Burnstein, A., Chan, A. K., Chan, P. C., 23 | Chang, L. J., Chen, E., Chiarawongse, C. P., Chin, G., … Zarrow, J. E. 24 | (2021). Don’t Ditch the Laptop Just Yet: A Direct Replication of Mueller 25 | and Oppenheimer’s (2014) Study 1 Plus Mini Meta-Analyses Across Similar 26 | Studies. *Psychological Science*, 0956797620965541. 27 | \doi{10.1177/0956797620965541} 28 | } 29 | \usage{ 30 | laptop_urry 31 | } 32 | \description{ 33 | Original abstract: 34 | In this direct replication of Mueller and Oppenheimer’s (2014) Study 1, 35 | participants watched a lecture while taking notes with a laptop (n = 74) or 36 | longhand (n = 68). After a brief distraction and without the opportunity to 37 | study, they took a quiz. As in the original study, laptop participants took 38 | notes containing more words spoken verbatim by the lecturer and more words 39 | overall than did longhand participants. However, laptop participants did not 40 | perform better than longhand participants on the quiz. 41 | } 42 | \details{ 43 | Own description: 44 | 45 | Heather Urry and 87 of her undergraduate and graduate students (yes, all 87 46 | students are co-authors!) compared the effectiveness of taking notes on a 47 | laptop versus longhand (i.e., pen and paper) for learning from lectures. 142 48 | participants (which differed from the 88 authors) first viewed one of several 49 | 15 minutes lectures (TED talks) during which they were asked to take notes 50 | either on a laptop or with pen and paper. Participants were randomly assigned 51 | to either the laptop (N = 68) or longhand condition (N = 74). After a 30 52 | minutes delay, participants were quizzed on the content of the lecture. There 53 | were two types of questions, factual and conceptual questions. The answers 54 | from each participant were then independently rated from several raters 55 | (which agreed very strongly with each other) using a standardised scoring key 56 | producing one memory score per participant and questions type ranging from 0 57 | (= no memory) to 100 (= perfect memory). We also aggregated the two different 58 | scores into one overall memory score. 59 | } 60 | \keyword{dataset} 61 | -------------------------------------------------------------------------------- /man/md_12.1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/md_12.1-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{md_12.1} 6 | \alias{md_12.1} 7 | \title{Data 12.1 from Maxwell & Delaney} 8 | \format{ 9 | A data.frame with 60 rows and 4 variables. 10 | } 11 | \source{ 12 | Maxwell, S. E., & Delaney, H. D. (2004). Designing experiments and analyzing data: a model-comparisons perspective. Mahwah, N.J.: Lawrence Erlbaum Associates. p. 574 13 | } 14 | \usage{ 15 | md_12.1 16 | } 17 | \description{ 18 | Hypothetical Reaction Time Data for 2 x 3 Perceptual Experiment: Example data for chapter 12 of Maaxwell and Delaney (2004, Table 12.1, p. 574) in long format. Has two within.subjects factors: angle and noise. 19 | } 20 | \details{ 21 | Description from pp. 573: 22 | 23 | Suppose that a perceptual psychologist studying the visual system was interested in determining the 24 | extent to which interfering visual stimuli slow the ability to recognize letters. Subjects are 25 | brought into a laboratory and seated in front of a tachistoscope. Subjects are told that they will 26 | see either the letter T or the letter I displayed on the screen. In some trials, the letter appears 27 | by itself, but in other trials, the target letter is embedded in a group of other letters. This 28 | variation in the display constitutes the first factor, which is referred to as noise. The noise 29 | factor has two levels?absent and present. The other factor varied by the experimenter is where in 30 | the display the target letter appears. This factor, which is called angle, has three levels. The 31 | target letter is either shown at the center of the screen (i.e., 0° off-center, where the subject 32 | has been instructed to fixate), 4° off-center or 8° off-center (in each case, the deviation from the 33 | center varies randomly between left and right). Table 12.1 presents hypothetical data for 10 34 | subjects. As usual, the sample size is kept small to make the calculations easier to follow. The 35 | dependent measure is reaction time (latency), measured in milliseconds (ms), required by a subject 36 | to identify the correct target letter. Notice that each subject has six scores, one for each 37 | combination of the 2 x 3 design. In an actual perceptual experiment, each of these six scores would 38 | itself be the mean score for that subject across a number of trials in the particular condition. 39 | Although "trials" could be used as a third within-subjects factor in such a situation, more 40 | typically trials are simply averaged over to obtain a more stable measure of the individual's 41 | performance in each condition. 42 | } 43 | \examples{ 44 | data(md_12.1) 45 | 46 | # Table 12.5 (p. 578): 47 | aov_ez("id", "rt", md_12.1, within = c("angle", "noise"), 48 | args.return=list(correction = "none", es = "none")) 49 | 50 | 51 | } 52 | \keyword{dataset} 53 | -------------------------------------------------------------------------------- /man/md_15.1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/md_15.1-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{md_15.1} 6 | \alias{md_15.1} 7 | \title{Data 15.1 / 11.5 from Maxwell & Delaney} 8 | \format{ 9 | A data.frame with 48 rows and 4 variables. 10 | } 11 | \source{ 12 | Maxwell, S. E., & Delaney, H. D. (2004). Designing experiments and analyzing data: a model-comparisons perspective. Mahwah, N.J.: Lawrence Erlbaum Associates. p. 766 13 | } 14 | \usage{ 15 | md_15.1 16 | } 17 | \description{ 18 | Hypothetical IQ Data from 12 children at 4 time points: Example data for chapter 11/15 of Maxwell and Delaney (2004, Table 15.1, p. 766) in long format. Has two one within-subjects factor: time. 19 | } 20 | \details{ 21 | Description from pp. 534: 22 | 23 | The data show that 12 subjects have been observed in each of 4 conditions. To make the example easier to discuss, let's suppose that the 12 subjects are children who have been observed at 30, 36, 42, and 48 months of age. In each case, the dependent variable is the child's age-normed general cognitive score on the McCarthy Scales of Children's Abilities. Although the test is normed so that the mean score is independent of age for the general population, our 12 children may come from a population in which cognitive abilities are either growing more rapidly or less rapidly than average. Indeed, this is the hypothesis our data allow us to address. In other words, although the sample means suggest that the children's cognitive abilities are growing, a significance test is needed if we want to rule out sampling error as a likely explanation for the observed differences. 24 | 25 | To replicate the results in chapter 15 several different contrasts need to be applied, see Examples. 26 | 27 | \code{time} is time in months (centered at 0) and \code{timecat} is the same as a categorical variable. 28 | } 29 | \examples{ 30 | ### replicate results from Table 15.2 to 15.6 (Maxwell & Delaney, 2004, pp. 774) 31 | data(md_15.1) 32 | 33 | ### ANOVA results (Table 15.2) 34 | aov_4(iq ~ timecat + (timecat|id),data=md_15.1, anova_table=list(correction = "none")) 35 | 36 | ### Table 15.3 (random intercept only) 37 | # we need to set the base level on the last level: 38 | contrasts(md_15.1$timecat) <- contr.treatment(4, base = 4) 39 | # "Type 3 Tests of Fixed Effects" 40 | (t15.3 <- mixed(iq ~ timecat + (1|id),data=md_15.1, check.contrasts=FALSE)) 41 | # "Solution for Fixed Effects" and "Covariance Parameter Estimates" 42 | summary(t15.3$full.model) 43 | 44 | ### make Figure 15.2 45 | plot(NULL, NULL, ylim = c(80, 140), xlim = c(30, 48), ylab = "iq", xlab = "time") 46 | plyr::d_ply(md_15.1, plyr::.(id), function(x) lines(as.numeric(as.character(x$timecat)), x$iq)) 47 | 48 | ### Table 15.4, page 789 49 | # random intercept plus slope 50 | (t15.4 <- mixed(iq ~ timecat + (1+time|id),data=md_15.1, check.contrasts=FALSE)) 51 | summary(t15.4$full.model) 52 | 53 | ### Table 15.5, page 795 54 | # set up polynomial contrasts for timecat 55 | contrasts(md_15.1$timecat) <- contr.poly 56 | # fit all parameters separately 57 | (t15.5 <- mixed(iq ~ timecat + (1+time|id), data=md_15.1, check.contrasts=FALSE, 58 | per.parameter="timecat")) 59 | # quadratic trend is considerably off, conclusions stay the same. 60 | 61 | 62 | ### Table 15.6, page 797 63 | # growth curve model 64 | (t15.6 <- mixed(iq ~ time + (1+time|id),data=md_15.1)) 65 | summary(t15.6$full.model) 66 | 67 | } 68 | \author{ 69 | R code for examples written by Ulf Mertens and Henrik Singmann 70 | } 71 | \keyword{dataset} 72 | -------------------------------------------------------------------------------- /man/md_16.1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/md_16.1-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{md_16.1} 6 | \alias{md_16.1} 7 | \title{Data 16.1 / 10.9 from Maxwell & Delaney} 8 | \format{ 9 | A data.frame with 24 rows and 3 variables. 10 | } 11 | \source{ 12 | Maxwell, S. E., & Delaney, H. D. (2004). Designing experiments and analyzing data: a model-comparisons perspective. Mahwah, N.J.: Lawrence Erlbaum Associates. p. 574 13 | } 14 | \usage{ 15 | md_16.1 16 | } 17 | \description{ 18 | Hypothetical Reaction Time Data for 2 x 3 Perceptual Experiment: Example data for chapter 12 of Maaxwell and Delaney (2004, Table 12.1, p. 574) in long format. Has two within.subjects factors: angle and noise. 19 | } 20 | \details{ 21 | Description from pp. 829: 22 | 23 | As brief background, the goal of the study here is to examine the extent to which female and male clinical psychology graduate student trainees may assign different severity ratings to clients at initial intake. Three female and 3 male graduate students are randomly selected to participate and each is randomly assigned four clients with whom to do an intake interview, after which each clinical trainee assigns a severity rating to each client, producing the data shown in Table 16.1. 24 | 25 | Note that I changed the labeling of the id slightly, so that they are now labeled from 1 to 6. Furthermore, I changed the contrasts of sex to \code{contr.treatment} to replicate the exact results of Table 16.3 (p. 837). 26 | } 27 | \examples{ 28 | ### replicate results from Table 16.3 (Maxwell & Delaney, 2004, p. 837) 29 | data(md_16.1) 30 | 31 | # original results need treatment contrasts: 32 | (mixed1_orig <- mixed(severity ~ sex + (1|id), md_16.1, check.contrasts=FALSE)) 33 | summary(mixed1_orig$full.model) 34 | 35 | # p-values stay the same with afex default contrasts (contr.sum), 36 | # but estimates and t-values for the fixed effects parameters change. 37 | (mixed1 <- mixed(severity ~ sex + (1|id), md_16.1)) 38 | summary(mixed1$full.model) 39 | 40 | } 41 | \keyword{dataset} 42 | -------------------------------------------------------------------------------- /man/md_16.4.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/md_16.4-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{md_16.4} 6 | \alias{md_16.4} 7 | \title{Data 16.4 from Maxwell & Delaney} 8 | \format{ 9 | A data.frame with 24 rows and 3 variables. 10 | } 11 | \source{ 12 | Maxwell, S. E., & Delaney, H. D. (2004). Designing experiments and analyzing data: a model-comparisons perspective. Mahwah, N.J.: Lawrence Erlbaum Associates. p. 574 13 | } 14 | \usage{ 15 | md_16.4 16 | } 17 | \description{ 18 | Data from a hypothetical inductive reasoning study. 19 | } 20 | \details{ 21 | Description from pp. 841: 22 | 23 | Suppose an educational psychologist has developed an intervention to teach inductive reasoning skills to school children. She decides to test the efficacy of her intervention by conducting a randomized design. Three classrooms of students are randomly assigned to the treatment condition, and 3 other classrooms are assigned to the control. 24 | 25 | Table 16.4 shows hypothetical data collected from 29 children who participated in the study assessing the effectiveness of the intervention to increase inductive reasoning skills. We want to call your attention to several aspects of the data. First, the 15 children with condition values of 0 received the control, whereas the 14 children with condition values of 1 received the treatment. Second, 4 of the children in the control condition were students in control Classroom 1, 6 of them were students in control Classroom 2, and 5 were students in control Classroom 3. Along similar lines, 3 of the children in the treatment condition were students in treatment Classroom 1, 5 were students in treatment Classroom 2, and 6 were students in treatment Classroom 3. It is essential to understand that there are a total of six classrooms here; we have coded classroom from 1 to 3 for control as well as treatment, because we will indicate to PROC MIXED that classroom is nested under treatment. Third, scores on the dependent variable appear in the rightmost column under the variable label "induct." 26 | 27 | Note that it would make a lot more sense to change the labeling of room from 1 to 3 nested within cond to 1 to 6. However, I keep this in line with the original. The random effects term in the call to mixed is therefore a little bit uncommon.#' 28 | } 29 | \examples{ 30 | # data for next examples (Maxwell & Delaney, Table 16.4) 31 | data(md_16.4) 32 | str(md_16.4) 33 | 34 | ### replicate results from Table 16.6 (Maxwell & Delaney, 2004, p. 845) 35 | # p-values (almost) hold: 36 | (mixed2 <- mixed(induct ~ cond + (1|room:cond), md_16.4)) 37 | # (1|room:cond) is needed because room is nested within cond. 38 | 39 | 40 | } 41 | \keyword{dataset} 42 | -------------------------------------------------------------------------------- /man/obk.long.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/obk.long-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{obk.long} 6 | \alias{obk.long} 7 | \title{O'Brien Kaiser's Repeated-Measures Dataset with Covariate} 8 | \format{ 9 | A data frame with 240 rows and 7 variables. 10 | } 11 | \source{ 12 | O'Brien, R. G., & Kaiser, M. K. (1985). MANOVA method for analyzing repeated measures designs: An extensive primer. \emph{Psychological Bulletin}, 97, 316-333. doi:10.1037/0033-2909.97.2.316 13 | } 14 | \usage{ 15 | obk.long 16 | } 17 | \description{ 18 | This is the long version of the \code{OBrienKaiser} dataset from the \pkg{car} pakage adding a random covariate \code{age}. Originally the dataset ist taken from O'Brien and Kaiser (1985). The description from \code{\link[carData]{OBrienKaiser}} says: "These contrived repeated-measures data are taken from O'Brien and Kaiser (1985). The data are from an imaginary study in which 16 female and male subjects, who are divided into three treatments, are measured at a pretest, postest, and a follow-up session; during each session, they are measured at five occasions at intervals of one hour. The design, therefore, has two between-subject and two within-subject factors." 19 | } 20 | \examples{ 21 | # The dataset is constructed as follows: 22 | data("OBrienKaiser", package = "carData") 23 | set.seed(1) 24 | OBrienKaiser2 <- within(OBrienKaiser, { 25 | id <- factor(1:nrow(OBrienKaiser)) 26 | age <- scale(sample(18:35, nrow(OBrienKaiser), replace = TRUE), scale = FALSE)}) 27 | attributes(OBrienKaiser2$age) <- NULL # needed or resahpe2::melt throws an error. 28 | OBrienKaiser2$age <- as.numeric(OBrienKaiser2$age) 29 | obk.long <- reshape2::melt(OBrienKaiser2, id.vars = c("id", "treatment", "gender", "age")) 30 | obk.long[,c("phase", "hour")] <- lapply(as.data.frame(do.call(rbind, 31 | strsplit(as.character(obk.long$variable), "\\\\."),)), factor) 32 | obk.long <- obk.long[,c("id", "treatment", "gender", "age", "phase", "hour", "value")] 33 | obk.long <- obk.long[order(obk.long$id),] 34 | rownames(obk.long) <- NULL 35 | str(obk.long) 36 | ## 'data.frame': 240 obs. of 7 variables: 37 | ## $ id : Factor w/ 16 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ... 38 | ## $ treatment: Factor w/ 3 levels "control","A",..: 1 1 1 1 1 1 1 1 1 1 ... 39 | ## $ gender : Factor w/ 2 levels "F","M": 2 2 2 2 2 2 2 2 2 2 ... 40 | ## $ age : num -4.75 -4.75 -4.75 -4.75 -4.75 -4.75 -4.75 -4.75 -4.75 -4.75 ... 41 | ## $ phase : Factor w/ 3 levels "fup","post","pre": 3 3 3 3 3 2 2 2 2 2 ... 42 | ## $ hour : Factor w/ 5 levels "1","2","3","4",..: 1 2 3 4 5 1 2 3 4 5 ... 43 | ## $ value : num 1 2 4 2 1 3 2 5 3 2 ... 44 | head(obk.long) 45 | ## id treatment gender age phase hour value 46 | ## 1 1 control M -4.75 pre 1 1 47 | ## 2 1 control M -4.75 pre 2 2 48 | ## 3 1 control M -4.75 pre 3 4 49 | ## 4 1 control M -4.75 pre 4 2 50 | ## 5 1 control M -4.75 pre 5 1 51 | ## 6 1 control M -4.75 post 1 3 52 | } 53 | \keyword{dataset} 54 | -------------------------------------------------------------------------------- /man/predict.afex_aov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/predict.R 3 | \name{predict.afex_aov} 4 | \alias{predict.afex_aov} 5 | \title{Predict method for \code{afex_aov} objects} 6 | \usage{ 7 | \method{predict}{afex_aov}(object, newdata, append = FALSE, colname_predict = ".predict", ...) 8 | } 9 | \arguments{ 10 | \item{object}{\code{afex_aov} object.} 11 | 12 | \item{newdata}{An optional data frame in which to look for variables with 13 | which to predict. If omitted, the fitted values are used.} 14 | 15 | \item{append}{If set to \code{TRUE} returns the residuals/fitted values 16 | appended as an additional column to the long data. Recommended when data 17 | was aggregated across within conditions.} 18 | 19 | \item{colname_predict}{Name of the appended column when \code{append = TRUE}.} 20 | 21 | \item{...}{Not used.} 22 | } 23 | \value{ 24 | A vector of predicted values corresponding to the data in 25 | \code{object$data$long} or to \code{newdata}, or if \code{append = TRUE} a 26 | data frame with an additional column of predicted values. 27 | } 28 | \description{ 29 | Predicted values based on \code{afex_aov} objects. 30 | } 31 | \examples{ 32 | 33 | data(obk.long, package = "afex") 34 | 35 | # estimate mixed ANOVA on the full design: 36 | fit <- aov_ez("id", "value", obk.long, between = c("treatment", "gender"), 37 | within = c("phase", "hour"), observed = "gender") 38 | 39 | new_data <- expand.grid( 40 | treatment = "A", 41 | gender = "F", 42 | phase = c("pre", "post"), 43 | hour = c(1, 5) 44 | ) 45 | 46 | predict(fit, newdata = new_data) 47 | predict(fit, newdata = new_data, append = TRUE) 48 | } 49 | \author{ 50 | Mattan S. Ben-Shachar 51 | } 52 | -------------------------------------------------------------------------------- /man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reexport.R 3 | \docType{import} 4 | \name{reexports} 5 | \alias{reexports} 6 | \alias{lmer} 7 | \title{Objects exported from other packages} 8 | \keyword{internal} 9 | \description{ 10 | These objects are imported from other packages. Follow the links 11 | below to see their documentation. 12 | 13 | \describe{ 14 | \item{lmerTest}{\code{\link[lmerTest]{lmer}}} 15 | }} 16 | 17 | -------------------------------------------------------------------------------- /man/residuals.afex_aov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/residuals.R 3 | \name{residuals.afex_aov} 4 | \alias{residuals.afex_aov} 5 | \alias{fitted.afex_aov} 6 | \title{Extract Residuals and Fitted Values from \code{afex_aov} objects} 7 | \usage{ 8 | \method{residuals}{afex_aov}(object, append = FALSE, colname_residuals = ".residuals", ...) 9 | 10 | \method{fitted}{afex_aov}(object, append = FALSE, colname_fitted = ".fitted", ...) 11 | } 12 | \arguments{ 13 | \item{object}{\code{afex_aov} object.} 14 | 15 | \item{append}{If set to \code{TRUE} returns the residuals/fitted values 16 | appended as an additional column to the long data. Recommended when data 17 | was aggregated across within conditions.} 18 | 19 | \item{colname_residuals, colname_fitted}{Name of the appended column when 20 | \code{append = TRUE}.} 21 | 22 | \item{...}{Additional arguments passed to 23 | \code{residuals.lm}/\code{fitted.lm}.} 24 | } 25 | \value{ 26 | A vector of residuals/fitted values corresponding to the data in 27 | \code{object$data$long}, or if \code{append = TRUE} a data frame with an 28 | additional column of residuals/fitted values. 29 | } 30 | \description{ 31 | Extract Residuals and Fitted Values from \code{afex_aov} objects. 32 | } 33 | \examples{ 34 | ### Setup ANOVAs 35 | data(obk.long, package = "afex") 36 | between <- aov_car(value ~ treatment*gender + Error(id), data = obk.long) 37 | within <- aov_car(value ~ 1 + Error(id/(phase*hour)), data = obk.long) 38 | mixed <- aov_car(value ~ treatment * gender + Error(id/(phase*hour)), data = obk.long) 39 | 40 | # All residuals call produce the message that the data was changed during calculation. 41 | residuals(within) 42 | residuals(mixed) 43 | residuals(between) 44 | 45 | ## Get residuals plus data used for fitting: 46 | residuals(within, append = TRUE) 47 | residuals(mixed, append = TRUE) 48 | residuals(between, append = TRUE) 49 | 50 | ### in case data is correctly ordered before fitting, this message is not shown 51 | 52 | ## between data: 53 | obk2 <- aggregate(value ~ gender + treatment + id , data = obk.long, FUN = mean) 54 | between2 <- aov_car(value ~ treatment*gender + Error(id), data = obk2) 55 | 56 | residuals(between2) ## no message 57 | all.equal(obk2, between2$data$long[,colnames(obk2)]) ## TRUE 58 | 59 | # Therefore okay: 60 | obk2$residuals <- residuals(between2) 61 | 62 | ## within data 63 | obk3 <- obk.long[with(obk.long, order(id, phase, hour)), ] 64 | within2 <- aov_car(value ~ 1 + Error(id/(phase*hour)), data = obk3) 65 | residuals(within2) ## no message, because order is correct 66 | # Therefore okay: 67 | obk3$residuals <- residuals(within2) 68 | 69 | ## Same for fitted values: 70 | # (show message) 71 | fitted(within) 72 | fitted(mixed) 73 | fitted(between) 74 | 75 | ## Get fitted values plus data used for fitting: 76 | fitted(within, append = TRUE) 77 | fitted(mixed, append = TRUE) 78 | fitted(between, append = TRUE) 79 | 80 | ## No message: 81 | fitted(between2) 82 | fitted(within2) 83 | 84 | #### residuals() and fitted() methods can be used for plotting 85 | ### requires package ggResidpanel 86 | if (require("ggResidpanel")) { 87 | resid_auxpanel(residuals = residuals(mixed), predicted = fitted(mixed)) 88 | 89 | \dontrun{ 90 | ## suppress Messages: 91 | suppressMessages( 92 | resid_auxpanel(residuals = residuals(mixed), predicted = fitted(mixed)) 93 | ) 94 | } 95 | } 96 | } 97 | \author{ 98 | Mattan S. Ben-Shachar 99 | } 100 | -------------------------------------------------------------------------------- /man/round_ps.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/round_ps.R 3 | \encoding{UTF-8} 4 | \name{round_ps} 5 | \alias{round_ps} 6 | \alias{round_ps_apa} 7 | \title{Helper functions for rounding p-values} 8 | \usage{ 9 | round_ps(x) 10 | 11 | round_ps_apa(x) 12 | } 13 | \arguments{ 14 | \item{x}{a numeric vector} 15 | } 16 | \value{ 17 | A character vector with the same length as x. 18 | } 19 | \description{ 20 | These functions return a character vector of p-values that are rounded as 21 | described below and without the leading zero before the decimal point. 22 | } 23 | \details{ 24 | For \code{round_ps} p-values are rounded in a sane way: .99 - .01 to two 25 | digits, < .01 to three digits, < .001 to four digits. 26 | 27 | For \code{round_ps_apa} p-values are rounded following APA guidelines: .999 - 28 | .001 to three digits, and < .001 for values below this threshold. 29 | } 30 | \note{ 31 | These functions are useful in \code{\link{nice}} and the default is set 32 | via \code{\link{afex_options}}. 33 | } 34 | \examples{ 35 | x <- runif(10) 36 | y <- runif(10, 0, .01) 37 | 38 | round_ps(x) 39 | round_ps_apa(x) 40 | 41 | round_ps(y) 42 | round_ps_apa(y) 43 | 44 | round_ps(0.0000000099) 45 | round_ps_apa(0.0000000099) 46 | 47 | } 48 | \author{ 49 | Henrik Singmann 50 | } 51 | -------------------------------------------------------------------------------- /man/set_sum_contrasts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/set_contrasts.R 3 | \name{set_sum_contrasts} 4 | \alias{set_sum_contrasts} 5 | \alias{set_deviation_contrasts} 6 | \alias{set_effects_contrasts} 7 | \alias{set_treatment_contrasts} 8 | \alias{set_default_contrasts} 9 | \title{Set global contrasts} 10 | \usage{ 11 | set_sum_contrasts() 12 | 13 | set_deviation_contrasts() 14 | 15 | set_effects_contrasts() 16 | 17 | set_default_contrasts() 18 | 19 | set_treatment_contrasts() 20 | } 21 | \value{ 22 | nothing. These functions are called for their side effects to change the global options. 23 | } 24 | \description{ 25 | These functions are simple wrappers to set contrasts globally via \code{options(contrasts = ...)}. 26 | } 27 | \details{ 28 | \code{set_deviation_contrasts} and \code{set_effects_contrasts} are wrappers for \code{set_sum_contrasts}. Likewise, \code{set_default_contrasts} is a wrapper to \code{set_treatment_contrasts()}. 29 | } 30 | -------------------------------------------------------------------------------- /man/sk2011.1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sk2011.1-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{sk2011.1} 6 | \alias{sk2011.1} 7 | \title{Data from Singmann & Klauer (2011, Experiment 1)} 8 | \format{ 9 | A data.frame with 640 rows and 9 variables. 10 | } 11 | \source{ 12 | Singmann, H., & Klauer, K. C. (2011). Deductive and inductive conditional inferences: Two modes of reasoning. Thinking & Reasoning, 17(3), 247-281. doi:10.1080/13546783.2011.572718 13 | } 14 | \usage{ 15 | sk2011.1 16 | } 17 | \description{ 18 | Singmann and Klauer (2011) were interested in whether or not conditional reasoning can be explained by a single process or whether multiple processes are necessary to explain it. To provide evidence for multiple processes we aimed to establish a double dissociation of two variables: instruction type and problem type. Instruction type was manipulated between-subjects, one group of participants received deductive instructions (i.e., to treat the premises as given and only draw necessary conclusions) and a second group of participants received probabilistic instructions (i.e., to reason as in an everyday situation; we called this "inductive instruction" in the manuscript). Problem type consisted of two different orthogonally crossed variables that were manipulated within-subjects, validity of the problem (formally valid or formally invalid) and plausibility of the problem (inferences which were consisted with the background knowledge versus problems that were inconsistent with the background knowledge). The critical comparison across the two conditions was among problems which were valid and implausible with problems that were invalid and plausible. For example, the next problem was invalid and plausible: 19 | } 20 | \details{ 21 | If a person is wet, then the person fell into a swimming pool. \cr 22 | A person fell into a swimming pool. \cr 23 | How valid is the conclusion/How likely is it that the person is wet? 24 | 25 | For those problems we predicted that under deductive instructions responses should be lower (as the conclusion does not necessarily follow from the premises) as under probabilistic instructions. For the valid but implausible problem, an example is presented next, we predicted the opposite pattern: 26 | 27 | If a person is wet, then the person fell into a swimming pool. \cr 28 | A person is wet. \cr 29 | How valid is the conclusion/How likely is it that the person fell into a swimming pool? 30 | 31 | Our study also included valid and plausible and invalid and implausible problems. 32 | 33 | Note that the factor `plausibility` is not present in the original manuscript, there it is a results of a combination of other factors. 34 | } 35 | \examples{ 36 | data(sk2011.1) 37 | 38 | # Table 1 (p. 264): 39 | aov_ez("id", "response", sk2011.1[ sk2011.1$what == "affirmation",], 40 | within = c("inference", "type"), between = "instruction", 41 | anova_table=(es = "pes")) 42 | aov_ez("id", "response", sk2011.1[ sk2011.1$what == "denial",], 43 | within = c("inference", "type"), between = "instruction", 44 | anova_table=(es = "pes")) 45 | 46 | 47 | } 48 | \keyword{dataset} 49 | -------------------------------------------------------------------------------- /man/sk2011.2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sk2011.2-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{sk2011.2} 6 | \alias{sk2011.2} 7 | \title{Data from Singmann & Klauer (2011, Experiment 2)} 8 | \format{ 9 | A data.frame with 2268 rows and 9 variables. 10 | } 11 | \source{ 12 | Singmann, H., & Klauer, K. C. (2011). Deductive and inductive conditional inferences: Two modes of reasoning. Thinking & Reasoning, 17(3), 247-281. doi:10.1080/13546783.2011.572718 13 | } 14 | \usage{ 15 | sk2011.2 16 | } 17 | \description{ 18 | Singmann and Klauer (2011) were interested in whether or not conditional reasoning can be explained by a single process or whether multiple processes are necessary to explain it. To provide evidence for multiple processes we aimed to establish a double dissociation of two variables: instruction type and problem type. Instruction type was manipulated between-subjects, one group of participants received deductive instructions (i.e., to treat the premises as given and only draw necessary conclusions) and a second group of participants received probabilistic instructions (i.e., to reason as in an everyday situation; we called this "inductive instruction" in the manuscript). Problem type consisted of two different orthogonally crossed variables that were manipulated within-subjects, validity of the problem (formally valid or formally invalid) and type of the problem. Problem type consistent of three levels: prological problems (i.e., problems in which background knowledge suggested to accept valid but reject invalid conclusions), neutral problems (i.e., in which background knowledge suggested to reject all problems), and counterlogical problems (i.e., problems in which background knowledge suggested to reject valid but accept invalid conclusions). 19 | } 20 | \details{ 21 | This data set contains 63 participants in contrast to the originally reported 56 participants. The additional participants were not included in the original studies as they did not meet the inclusion criteria (i.e., no students, prior education in logic, or participated in a similar experiment). The IDs of those additional participants are: 7, 8, 9, 12, 17, 24, 30. The excluded participant reported in the paper has ID 16. 22 | 23 | content has the following levels (C = content/conditional):\cr 24 | 1 = Wenn eine Person in ein Schwimmbecken gefallen ist, dann ist sie nass.\cr 25 | 2 = Wenn ein Hund Flöhe hat, dann kratzt er sich hin und wieder.\cr 26 | 3 = Wenn eine Seifenblase mit einer Nadel gestochen wurde, dann platzt sie.\cr 27 | 4 = Wenn ein Mädchen Geschlechtsverkehr vollzogen hat, dann ist es schwanger.\cr 28 | 5 = Wenn eine Pflanze ausreichend gegossen wird, dann bleibt sie grün.\cr 29 | 6 = Wenn sich eine Person die Zähne putzt, dann bekommt sie KEIN Karies.\cr 30 | 7 = Wenn eine Person viel Cola trinkt, dann nimmt sie an Gewicht zu.\cr 31 | 8 = Wenn eine Person die Klimaanlage angeschaltet hat, dann fröstelt sie.\cr 32 | 9 = Wenn eine Person viel lernt, dann wird sie in der Klausur eine gute Note erhalten. 33 | } 34 | \examples{ 35 | data("sk2011.2") 36 | 37 | ## remove excluded participants: 38 | 39 | sk2_final <- droplevels(sk2011.2[!(sk2011.2$id \%in\% c(7, 8, 9, 12, 16, 17, 24, 30)),]) 40 | str(sk2_final) 41 | 42 | ## Table 2 (inference = problem): 43 | aov_ez("id", "response", sk2_final[sk2_final$what == "affirmation",], 44 | between = "instruction", within = c("inference", "type"), 45 | anova_table=list(es = "pes")) 46 | 47 | aov_ez("id", "response", sk2_final[sk2_final$what == "denial",], 48 | between = "instruction", within = c("inference", "type"), 49 | anova_table=list(es = "pes")) 50 | 51 | # Recreate Figure 4 (corrected version): 52 | 53 | sk2_aff <- droplevels(sk2_final[sk2_final$what == "affirmation",]) 54 | sk2_aff$type2 <- factor(sk2_aff$inference:sk2_aff$type, levels = c("MP:prological", 55 | "MP:neutral", "MP:counterlogical", "AC:counterlogical", 56 | "AC:neutral", "AC:prological")) 57 | a1_b <- aov_ez("id", "response", sk2_aff, 58 | between = "instruction", within = c("type2")) 59 | 60 | sk2_den <- droplevels(sk2_final[sk2_final$what == "denial",]) 61 | sk2_den$type2 <- factor(sk2_den$inference:sk2_den$type, levels = c("MT:prological", 62 | "MT:neutral", "MT:counterlogical", "DA:counterlogical", 63 | "DA:neutral","DA:prological")) 64 | a2_b <- aov_ez("id", "response", sk2_den, 65 | between = "instruction", within = c("type2")) 66 | 67 | if (requireNamespace("emmeans") && requireNamespace("ggplot2")) { 68 | afex_plot(a1_b,"type2", "instruction") + 69 | ggplot2::coord_cartesian(ylim = c(0, 100)) 70 | afex_plot(a2_b,"type2", "instruction") + 71 | ggplot2::coord_cartesian(ylim = c(0, 100)) 72 | } 73 | } 74 | \keyword{dataset} 75 | -------------------------------------------------------------------------------- /man/stroop.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/stroop-data.R 3 | \docType{data} 4 | \encoding{UTF-8} 5 | \name{stroop} 6 | \alias{stroop} 7 | \title{Stroop data from Lin et al. (2020, Psych. Science)} 8 | \format{ 9 | A data frame with 246600 rows and 7 variables: 10 | \describe{ 11 | \item{pno}{participant id (preceded by study id), factor with 685 levels} 12 | \item{condition}{experimental condition (control/low demand, deplete/high demand), factor with 2 levels} 13 | \item{study}{study number (1, 2, 3, 4), factor with 4 levels} 14 | \item{trialnum}{trial number} 15 | \item{congruency}{Stroop congruency (congruent, incongruent), factor with 2 levels} 16 | \item{acc}{accuracy (0: error, 1: correct)} 17 | \item{rt}{reaction time (seconds)} 18 | } 19 | } 20 | \source{ 21 | Lin, H., Saunders, B., Friese, M., Evans, N. J., & Inzlicht, M. 22 | (2020). Strong Effort Manipulations Reduce Response Caution: A 23 | Preregistered Reinvention of the Ego-Depletion Paradigm. *Psychological 24 | Science*, \doi{10.1177/0956797620904990} 25 | } 26 | \usage{ 27 | stroop 28 | } 29 | \description{ 30 | Lin, Saunders, Friese, Evans, and Inzlicht (2020) investigated ego depletion. 31 | An initial high-demand task was followed by a Stroop task. The data of the 32 | Stroop task from all 4 of their studies is included here. 33 | } 34 | \details{ 35 | Their abstract: People feel tired or depleted after exerting mental effort. 36 | But even preregistered studies often fail to find effects of exerting effort 37 | on behavioral performance in the laboratory or elucidate the underlying 38 | psychology. We tested a new paradigm in four preregistered within-subjects 39 | studies (N = 686). An initial high-demand task reliably elicited very strong 40 | effort phenomenology compared with a low-demand task. Afterward, participants 41 | completed a Stroop task. We used drift-diffusion modeling to obtain the 42 | boundary (response caution) and drift-rate (information-processing speed) 43 | parameters. Bayesian analyses indicated that the high-demand manipulation 44 | reduced boundary but not drift rate. Increased effort sensations further 45 | predicted reduced boundary. However, our demand manipulation did not affect 46 | subsequent inhibition, as assessed with traditional Stroop behavioral 47 | measures and additional diffusion-model analyses for conflict tasks. Thus, 48 | effort exertion reduced response caution rather than inhibitory control, 49 | suggesting that after exerting effort, people disengage and become 50 | uninterested in exerting further effort. 51 | } 52 | \keyword{dataset} 53 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(afex) 3 | 4 | test_check("afex") 5 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/afex_plot-default-support/afex-plots-poisson-glm-1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 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 | 0 52 | 25 53 | 50 54 | 75 55 | 100 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | S 65 | M 66 | L 67 | size 68 | claims 69 | afex_plots: poisson glm 1 70 | 71 | 72 | -------------------------------------------------------------------------------- /tests/testthat/afex_aov_16_1.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/tests/testthat/afex_aov_16_1.rda -------------------------------------------------------------------------------- /tests/testthat/afex_plot-brms.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/tests/testthat/afex_plot-brms.rda -------------------------------------------------------------------------------- /tests/testthat/afex_plot-rstanarm.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/tests/testthat/afex_plot-rstanarm.rda -------------------------------------------------------------------------------- /tests/testthat/anova_hf_error.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/tests/testthat/anova_hf_error.rda -------------------------------------------------------------------------------- /tests/testthat/helper-vdiffr.R: -------------------------------------------------------------------------------- 1 | # By default, if vdiffr is not installed, all visual tests are skipped unless 2 | # VDIFFR_RUN_TESTS is explicitly set to "true", which should be the case only on 3 | # a GitHub Actions CI runner with stable version of R. 4 | 5 | if (requireNamespace("vdiffr", quietly = TRUE) && utils::packageVersion('testthat') >= '3.0.3') { 6 | expect_doppelganger <- vdiffr::expect_doppelganger 7 | } else { 8 | # If vdiffr is not available and visual tests are explicitly required, raise error. 9 | if (identical(Sys.getenv("VDIFFR_RUN_TESTS"), "true")) { 10 | abort("vdiffr is not installed") 11 | } 12 | 13 | # Otherwise, assign a dummy function 14 | expect_doppelganger <- function(...) skip("vdiffr is not installed.") 15 | } 16 | -------------------------------------------------------------------------------- /tests/testthat/lmm_old_object.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/tests/testthat/lmm_old_object.rda -------------------------------------------------------------------------------- /tests/testthat/m_machines_lmerTest-pre3.0.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/tests/testthat/m_machines_lmerTest-pre3.0.rda -------------------------------------------------------------------------------- /tests/testthat/mixed_with_dot.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/tests/testthat/mixed_with_dot.rda -------------------------------------------------------------------------------- /tests/testthat/skf_issue.csv: -------------------------------------------------------------------------------- 1 | A,B,C,D,E,F,G,Y 2 | -1,-1,-1,1,1,1,-1,56.32283 3 | 1,-1,-1,-1,-1,1,1,53.1016 4 | -1,1,-1,-1,1,-1,1,50.47768 5 | 1,1,-1,1,-1,-1,-1,50.98613 6 | -1,-1,1,1,-1,-1,1,52.33799 7 | 1,-1,1,-1,1,-1,-1,53.2511 8 | -1,1,1,-1,-1,1,-1,59.61223 9 | 1,1,1,1,1,1,1,49.68686 10 | -1,-1,-1,1,1,1,-1,48.25756 11 | 1,-1,-1,-1,-1,1,1,49.06478 12 | -1,1,-1,-1,1,-1,1,46.6765 13 | 1,1,-1,1,-1,-1,-1,47.352 14 | -1,-1,1,1,-1,-1,1,47.59933 15 | 1,-1,1,-1,1,-1,-1,53.98404 16 | -1,1,1,-1,-1,1,-1,49.51856 17 | 1,1,1,1,1,1,1,45.22571 18 | -------------------------------------------------------------------------------- /tests/testthat/test-afex_aov.R: -------------------------------------------------------------------------------- 1 | 2 | context("ANOVAs: check that afex_aov return value works") 3 | 4 | test_that("split-plot produces an afex_aov object without error", { 5 | data(obk.long, package = "afex") 6 | split_plot1 <- aov_car(value ~ treatment * gender + Error(id/(phase*hour)), 7 | data = obk.long, observed = "gender", 8 | return = "afex_aov") 9 | split_plot2 <- aov_4(value ~ treatment * gender + (phase*hour|id), 10 | data = obk.long, observed = "gender", 11 | return = "afex_aov") 12 | split_plot3 <- aov_ez("id", "value", obk.long, 13 | between = c("treatment", "gender"), 14 | within = c("phase", "hour"), observed = "gender", 15 | return = "afex_aov") 16 | 17 | expect_that(split_plot1, is_equivalent_to(split_plot2)) 18 | expect_that(split_plot1, is_equivalent_to(split_plot3)) 19 | expect_that(split_plot1, is_a("afex_aov")) 20 | 21 | ## is same with numeric factor: 22 | obk.long$hour <- as.numeric(as.character(obk.long$hour)) 23 | split_plot4 <- aov_car(value ~ treatment * gender + Error(id/phase*hour), 24 | data = obk.long,observed = c("gender"), 25 | return = "afex_aov") 26 | expect_that(split_plot1, is_equivalent_to(split_plot4)) 27 | }) 28 | 29 | test_that("purely-between produces afex_aov objects without error", { 30 | data(obk.long, package = "afex") 31 | out1 <- aov_car(value ~ treatment * gender + Error(id), data = obk.long, 32 | observed = "gender", return = "afex_aov", 33 | fun_aggregate = mean) 34 | out2 <- aov_4(value ~ treatment * gender + (1|id), data = obk.long, 35 | observed = "gender", return = "afex_aov", fun_aggregate = mean) 36 | out3 <- aov_ez("id", "value", obk.long, 37 | between = c("treatment", "gender"), observed = "gender", 38 | return = "afex_aov", fun_aggregate = mean) 39 | 40 | expect_that(out1, is_equivalent_to(out2)) 41 | expect_that(out1, is_equivalent_to(out3)) 42 | expect_that(out1, is_a("afex_aov")) 43 | }) 44 | 45 | test_that("purely-within produces afex_aov objects without error", { 46 | data(obk.long, package = "afex") 47 | out1 <- aov_car(value ~ Error(id/(phase*hour)), data = obk.long, 48 | return = "afex_aov") 49 | out2 <- aov_4(value ~ 1 + (phase*hour|id), data = obk.long, 50 | return = "afex_aov") 51 | out3 <- aov_ez("id", "value", obk.long, within = c("phase", "hour"), 52 | return = "afex_aov") 53 | 54 | expect_that(out1, is_equivalent_to(out2)) 55 | expect_that(out1, is_equivalent_to(out3)) 56 | expect_that(out1, is_a("afex_aov")) 57 | }) 58 | 59 | test_that("within plus covariate produces afex_aov objects without error", { 60 | data(obk.long, package = "afex") 61 | out1 <- aov_car(value ~ gender + Error(id/(phase*hour)), data = obk.long, 62 | return = "afex_aov") 63 | out2 <- aov_4(value ~ gender + (phase*hour|id), data = obk.long, 64 | return = "afex_aov") 65 | out3 <- aov_ez("id", "value", obk.long, within = c("phase", "hour"), 66 | covariate = "gender", return = "afex_aov") 67 | 68 | expect_that(out1, is_equivalent_to(out2)) 69 | expect_that(out1, is_equivalent_to(out3)) 70 | expect_that(out1, is_a("afex_aov")) 71 | }) 72 | 73 | 74 | test_that("afex_aov object contains the right things", { 75 | data(obk.long, package = "afex") 76 | out1 <- aov_car(value ~ treatment * gender + Error(id/(phase*hour)), 77 | data = obk.long, observed = "gender", return = "afex_aov", 78 | include_aov = TRUE) 79 | 80 | expect_that(out1[["anova_table"]], is_a(c("anova", "data.frame"))) 81 | expect_that(out1[["aov"]], is_a(c("aovlist", "listof"))) 82 | expect_that(out1[["Anova"]], is_a(c("Anova.mlm"))) 83 | expect_that(out1[["lm"]], is_a(c("mlm", "lm"))) 84 | expect_that(out1[["data"]], is_a(c("list"))) 85 | expect_that(attr(out1, "dv"), is_a(c("character"))) 86 | }) 87 | 88 | test_that("afex_aov objects works without aov object", { 89 | data(obk.long, package = "afex") 90 | aop <- afex_options() 91 | afex_options(emmeans_model = "univariate") 92 | afex_options(include_aov = TRUE) 93 | 94 | a1 <- aov_car(value ~ treatment * gender + Error(id/(phase*hour)), 95 | data = obk.long, observed = "gender", include_aov = FALSE) 96 | a2 <- aov_4(value ~ treatment * gender + (phase*hour|id), 97 | data = obk.long, observed = "gender", include_aov = FALSE) 98 | a3 <- aov_ez("id", "value", obk.long, between = c("treatment", "gender"), 99 | within = c("phase", "hour"), observed = "gender", 100 | include_aov = FALSE) 101 | expect_equal(a1, a2) 102 | expect_equal(a1, a3) 103 | expect_null(a1$aov) 104 | 105 | skip_if_not_installed("emmeans") 106 | expect_message(em1 <- emmeans::emmeans(a1, "treatment"), "multivariate") 107 | 108 | expect_message(em2 <- emmeans::emmeans(a1, c("phase", "hour")), "multivariate") 109 | 110 | expect_identical(as.data.frame(summary(em1))$df[1], 111 | as.data.frame(summary(em2))$df[2]) 112 | 113 | ad <- aov_car(value ~ treatment * gender + Error(id/(phase*hour)), 114 | data = obk.long, observed = "gender") 115 | afex_options(include_aov = FALSE) 116 | an <- aov_car(value ~ treatment * gender + Error(id/(phase*hour)), 117 | data = obk.long, observed = "gender") 118 | expect_null(an$aov) 119 | expect_is(ad$aov, "aovlist") 120 | em3 <- emmeans::emmeans(ad, c("phase", "hour")) 121 | expect_message(em4 <- emmeans::emmeans(a1, c("phase", "hour")), "multivariate") 122 | expect_false(any(as.data.frame(summary(em3))$df == as.data.frame(summary(em4))$df)) 123 | afex_options(aop) # reset options 124 | }) 125 | 126 | test_that("better error message in case of all data having NAs", { 127 | data("stroop") 128 | # stroop_e1 <- stroop %>% 129 | # filter(!is.na(acc)) %>% 130 | # filter(study == "1") %>% 131 | # droplevels() 132 | stroop_e1_na <- stroop[ stroop$study == "1", ] 133 | 134 | suppressWarnings(expect_error(aov_ez( 135 | id = "pno", 136 | dv = "acc", 137 | data = stroop_e1_na, 138 | within = c("congruency", "condition") 139 | ), "Try adding to ANOVA call: na.rm = TRUE")) 140 | 141 | expect_is(aov_ez( 142 | id = "pno", 143 | dv = "acc", 144 | data = stroop_e1_na, 145 | within = c("congruency", "condition"), 146 | na.rm = TRUE, 147 | include_aov = FALSE, 148 | fun_aggregate = mean 149 | ), "afex_aov") 150 | }) 151 | -------------------------------------------------------------------------------- /tests/testthat/test-afex_plot-bugs.R: -------------------------------------------------------------------------------- 1 | 2 | test_that("mixed models with Type = 2 work", { 3 | testthat::skip_if_not_installed("ggplot2") 4 | testthat::skip_if_not_installed("emmeans") 5 | testthat::skip_if_not_installed("MEMSS") 6 | testthat::skip_on_cran() 7 | data("Machines", package = "MEMSS") 8 | 9 | # simple model with random-slopes for repeated-measures factor 10 | m1 <- mixed(score ~ Machine + (1|Worker), 11 | data=Machines, type = 2, method = "LRT", 12 | progress = FALSE) 13 | expect_doppelganger("afex_plot lmm, type = 2", afex_plot(m1, "Machine")) 14 | }) 15 | 16 | test_that("response variable y works", { 17 | 18 | testthat::skip_if_not_installed("ggplot2") 19 | testthat::skip_if_not_installed("emmeans") 20 | testthat::skip_if_not_installed("MEMSS") 21 | testthat::skip_on_cran() 22 | 23 | data("Machines", package = "MEMSS") 24 | 25 | Machines$y <- rnorm(nrow(Machines), mean = -100) 26 | ## was a problem if it came before the DV column 27 | Machines <- Machines[, c("y", "Worker", "Machine", "score")] 28 | 29 | # simple model with random-slopes for repeated-measures factor 30 | m1 <- mixed(score ~ Machine + (1|Worker), data=Machines, progress = FALSE) 31 | m1 32 | 33 | pp <- afex_plot(m1, "Machine") 34 | 35 | expect_doppelganger("afex_plot dv = y works", pp) 36 | }) 37 | 38 | test_that("merMod objects with missing data can be plotted", { 39 | 40 | testthat::skip_if_not_installed("ggplot2") 41 | testthat::skip_if_not_installed("emmeans") 42 | testthat::skip_if_not_installed("MEMSS") 43 | testthat::skip_on_cran() 44 | 45 | data("Machines", package = "MEMSS") 46 | 47 | Machines[1, "score"] <- NA 48 | 49 | m1 <- lme4::lmer(score ~ Machine + (1|Worker), data=Machines) 50 | pp <- afex_plot(m1, "Machine") 51 | 52 | expect_is(pp, "ggplot") 53 | 54 | m2 <- mixed(score ~ Machine + (1|Worker), data=Machines, 55 | progress = FALSE) 56 | pp2 <- afex_plot(m2, "Machine") 57 | 58 | expect_doppelganger("afex_plot merMod objects with missing data", pp2) 59 | }) 60 | 61 | 62 | test_that("binomial models plot data correctly with factor DVs", { 63 | testthat::skip_if_not_installed("ggplot2") 64 | testthat::skip_if_not_installed("emmeans") 65 | set.seed(898765) 66 | ## long format binomial GLM (https://stats.stackexchange.com/q/322038/442): 67 | drc4 <- function(x, b =1.0, c = 0, d = 1, e = 0){ 68 | (d - c)/ (1 + exp(-b * (log(x) - log(e)))) 69 | } 70 | # simulate long form of dataset 71 | nReps = 30 72 | dfLong <- data.frame(dose = factor(rep(letters[1:3], each = nReps))) 73 | dfLong$mortality <-rbinom(n = dim(dfLong)[1], size = 1, 74 | prob = drc4(as.numeric(dfLong$dose), b = 2, e = 5)) 75 | 76 | fitLong <- glm( mortality ~ dose, data = dfLong, 77 | family = "binomial") 78 | p1 <- afex_plot(fitLong, "dose") 79 | expect_doppelganger("afex_plot binomial glm with factor", p1) 80 | dfLong$mortality <- factor(dfLong$mortality) 81 | fitLong2 <- glm( mortality ~ dose, data = dfLong, 82 | family = "binomial") 83 | p2 <- afex_plot(fitLong2, "dose") 84 | expect_doppelganger("afex_plot binomial glm with factor 2", p2) 85 | expect_equivalent(p1, p2, check.environment=FALSE) 86 | }) 87 | 88 | test_that("non-factor IVs work with factor_levels argument", { 89 | testthat::skip_if_not_installed("ggplot2") 90 | testthat::skip_if_not_installed("emmeans") 91 | testthat::skip_if_not_installed("MEMSS") 92 | data("Machines", package = "MEMSS") 93 | 94 | ## transform Machine to character and disable check_contrasts 95 | Machines$Machine <- as.character(Machines$Machine) 96 | m2 <- mixed(score ~ Machine + (Machine||Worker), data=Machines, expand_re = TRUE, 97 | check_contrasts = FALSE, progress = FALSE) 98 | 99 | df_out <- afex_plot(m2, "Machine", 100 | factor_levels = list(Machine = list("B" = "beta", "A" = "a", "C" = "c")), 101 | return = "data") 102 | expect_s3_class(df_out$data$Machine, "factor") 103 | expect_s3_class(df_out$means$Machine, "factor") 104 | }) 105 | -------------------------------------------------------------------------------- /tests/testthat/test-afex_plot-default-support.R: -------------------------------------------------------------------------------- 1 | context("afex_plot: default method supported models") 2 | 3 | test_that("lm works", { 4 | testthat::skip_if_not_installed("emmeans") 5 | testthat::skip_if_not_installed("ggplot2") 6 | warp.lm <- lm(breaks ~ wool * tension, data = warpbreaks) 7 | p1 <- afex_plot(warp.lm, "tension") 8 | d1 <- afex_plot(warp.lm, "tension", return = "data") 9 | p2 <- afex_plot(warp.lm, "tension", "wool") 10 | d2 <- afex_plot(warp.lm, "tension", "wool", return = "data") 11 | expect_doppelganger("afex_plots: lm model 1", p1) 12 | expect_doppelganger("afex_plots: lm model 2", p2) 13 | expect_equal(nrow(d2$data), nrow(warpbreaks)) 14 | expect_equal(nrow(d1$data), nrow(warpbreaks)) 15 | }) 16 | 17 | test_that("poisson glm works", { 18 | testthat::skip_if_not_installed("emmeans") 19 | testthat::skip_if_not_installed("ggplot2") 20 | testthat::skip_on_cran() ## uses only expect_doppelganger 21 | 22 | ins <- data.frame( 23 | n = c(500, 1200, 100, 400, 500, 300), 24 | size = factor(rep(1:3,2), labels = c("S","M","L")), 25 | age = factor(rep(1:2, each = 3)), 26 | claims = c(42, 37, 1, 101, 73, 14)) 27 | ins.glm <- glm(claims ~ size + age + offset(log(n)), 28 | data = ins, family = "poisson") 29 | p1 <- afex_plot(ins.glm, "size") 30 | p2 <- afex_plot(ins.glm, "size", "age") 31 | expect_doppelganger("afex_plots: poisson glm 1", p1) 32 | expect_doppelganger("afex_plots: poisson glm 2", p2) 33 | }) 34 | 35 | test_that("binomial glm works", { 36 | testthat::skip_if_not_installed("emmeans") 37 | testthat::skip_if_not_installed("ggplot2") 38 | testthat::skip_on_cran() ## uses only expect_doppelganger 39 | 40 | ldose <- factor(rep(0:5, 2)) 41 | numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16) 42 | sex <- factor(rep(c("M", "F"), c(6, 6))) 43 | SF <- numdead/20 ## dv should be a vector, no matrix 44 | budworm.lg <- glm(SF ~ sex*ldose, family = binomial, 45 | weights = rep(20, length(numdead))) 46 | p1 <- afex_plot(budworm.lg, "ldose") 47 | p2 <- afex_plot(budworm.lg, "ldose", "sex") ## data point is hidden behind mean! 48 | expect_doppelganger("afex_plots: binomial glm 1", p1) 49 | expect_doppelganger("afex_plots: binomial glm 2", p2) 50 | }) 51 | 52 | test_that("nlme works", { 53 | testthat::skip_if_not_installed("emmeans") 54 | testthat::skip_if_not_installed("ggplot2") 55 | skip_if_not_installed("nlme") 56 | data(Oats, package = "nlme") 57 | Oats$nitro <- factor(Oats$nitro) 58 | oats.1 <- nlme::lme(yield ~ nitro * Variety, 59 | random = ~ 1 | Block / Variety, 60 | data = Oats) 61 | p1 <- afex_plot(oats.1, "nitro", "Variety", data = Oats) 62 | p2 <- afex_plot(oats.1, "nitro", "Variety", data = Oats, id = "Block") 63 | p3 <- afex_plot(oats.1, "nitro", data = Oats) 64 | p4 <- afex_plot(oats.1, "nitro", data = Oats, id = c("Block", "Variety")) 65 | p5 <- afex_plot(oats.1, "nitro", data = Oats, id = "Block") 66 | expect_doppelganger("afex_plots: nlme 1", p1) 67 | expect_doppelganger("afex_plots: nlme 2", p2) 68 | expect_doppelganger("afex_plots: nlme 3", p3) 69 | expect_doppelganger("afex_plots: nlme 4", p4) 70 | expect_doppelganger("afex_plots: nlme 5", p5) 71 | 72 | d3 <- afex_plot(oats.1, "nitro", data = Oats, return = "data") 73 | d4 <- afex_plot(oats.1, "nitro", data = Oats, 74 | id = c("Block", "Variety"), return = "data") 75 | d5 <- afex_plot(oats.1, "nitro", data = Oats, id = "Block", 76 | return = "data") 77 | expect_equal(nrow(d3$data), nrow(Oats)) 78 | expect_equal(nrow(d4$data), nrow(Oats)) 79 | expect_true(nrow(d5$data) < nrow(Oats)) 80 | }) 81 | 82 | -------------------------------------------------------------------------------- /tests/testthat/test-afex_plot-vignette.R: -------------------------------------------------------------------------------- 1 | test_that("glmmTMB object", { 2 | testthat::skip_if_not_installed("emmeans") 3 | testthat::skip_if_not_installed("ggplot2") 4 | skip_on_cran() 5 | skip_if_not_installed("glmmTMB") 6 | library("glmmTMB") 7 | set_sum_contrasts() 8 | tmb2 <- glmmTMB(count~spp * mined + (1|site), 9 | ziformula = ~spp * mined, 10 | family=nbinom2, Salamanders) 11 | # tmb <- tmb2 12 | # save(tmb, file = "inst/extdata/tmb_example_fit.rda", 13 | # compress = "xz") 14 | #load(system.file("extdata/", "tmb_example_fit.rda", package = "afex")) 15 | ## previous versions checked for equivalence of summary() or coef(), but that 16 | ## seems unnecessary and did fail at some point 17 | ## (i.e., summary() on old glmmTMB object failed) 18 | # expect_equivalent(coef(tmb), #summary(tmb), 19 | # coef(tmb2), #summary(tmb2), 20 | # tolerance = 0.001) 21 | 22 | skip_if_not_installed("cowplot") 23 | skip_if_not_installed("ggplot2") 24 | library("ggplot2") 25 | 26 | p1n <- afex_plot(tmb2, "spp") 27 | p2n <- afex_plot(tmb2, "spp", data_geom = geom_violin) 28 | p3n <- afex_plot(tmb2, "spp", id = "site", data = Salamanders) 29 | expect_doppelganger("afex_plot: glmmTMB 1", p1n) 30 | expect_doppelganger("afex_plot: glmmTMB 2", p2n) 31 | expect_doppelganger("afex_plot: glmmTMB 3", p3n) 32 | }) 33 | 34 | 35 | test_that("rstanarm plots", { 36 | testthat::skip_if_not_installed("emmeans") 37 | testthat::skip_if_not_installed("ggplot2") 38 | skip_on_cran() 39 | #skip_on_ci() 40 | skip_if_not_installed("rstanarm") 41 | library("rstanarm") ## requires resetting the ggplot2 theme 42 | skip_if_not_installed("ggplot2") 43 | library("ggplot2") 44 | set_sum_contrasts() 45 | load("afex_plot-rstanarm.rda") ## comparison values 46 | 47 | tol <- 0.1 48 | 49 | cbpp <- lme4::cbpp 50 | cbpp$prob <- with(cbpp, incidence / size) 51 | suppressWarnings(capture_output({ 52 | example_model <- rstanarm::stan_glmer(prob ~ period + (1|herd), 53 | data = cbpp, family = binomial, weight = size, 54 | chains = 2, cores = 1, seed = 12345, 55 | iter = 1000, warmup = 500) 56 | })) 57 | 58 | b1d <- afex_plot(example_model, "period", return = "data") 59 | expect_equal(b1d, rstanenv$b1d, tolerance = tol) 60 | 61 | ## make cbpp long 62 | cbpp_l <- vector("list", nrow(cbpp)) 63 | for (i in seq_along(cbpp_l)) { 64 | cbpp_l[[i]] <- data.frame( 65 | herd = cbpp$herd[i], 66 | period = cbpp$period[i], 67 | incidence = rep(0, cbpp$size[i]) 68 | ) 69 | cbpp_l[[i]]$incidence[seq_len(cbpp$incidence[i])] <- 1 70 | } 71 | cbpp_l <- do.call("rbind", cbpp_l) 72 | cbpp_l$herd <- factor(cbpp_l$herd, levels = levels(cbpp$herd)) 73 | cbpp_l$period <- factor(cbpp_l$period, levels = levels(cbpp$period)) 74 | 75 | suppressWarnings(capture_output({ 76 | example_model2 <- rstanarm::stan_glmer(incidence ~ period + (1|herd), 77 | data = cbpp_l, family = binomial, 78 | chains = 2, cores = 1, seed = 12345, 79 | iter = 1000) 80 | })) 81 | 82 | b3d <- afex_plot(example_model2, "period", return = "data") 83 | b4d <- afex_plot(example_model2, "period", id = "herd", return = "data") 84 | expect_equal(b3d, rstanenv$b3d, tolerance = tol) 85 | expect_equal(b4d, rstanenv$b4d, tolerance = tol) 86 | 87 | skip_if_not_installed("MEMSS") 88 | data("Machines", package = "MEMSS") 89 | 90 | suppressWarnings(capture_output({ 91 | mm <- rstanarm::stan_lmer(score ~ Machine + (Machine|Worker), data=Machines, 92 | chains = 2, cores = 1, seed = 12345, iter = 1000) 93 | })) 94 | 95 | b5d <- afex_plot(mm, "Machine", return = "data") 96 | b6d <- afex_plot(mm, "Machine", id = "Worker", return = "data") 97 | expect_equal(b5d, rstanenv$b5d, tolerance = tol) 98 | expect_equal(b6d, rstanenv$b6d, tolerance = tol) 99 | 100 | #### save 101 | # rstanenv <- new.env() 102 | # rstanenv$b1d <- b1d 103 | # rstanenv$b3d <- b3d 104 | # rstanenv$b4d <- b4d 105 | # rstanenv$b5d <- b5d 106 | # rstanenv$b6d <- b6d 107 | # ls(envir = rstanenv) 108 | # save(rstanenv, file = "tests/testthat/afex_plot-rstanarm.rda") 109 | }) 110 | 111 | test_that("brms plots", { 112 | testthat::skip_if_not_installed("emmeans") 113 | testthat::skip_if_not_installed("ggplot2") 114 | skip_on_cran() 115 | #skip_on_os("windows") 116 | skip_if_not_installed("brms") 117 | library("brms") ## requires resetting the ggplot2 theme 118 | skip_if_not_installed("ggplot2") 119 | skip_if_not_installed("MEMSS") 120 | library("ggplot2") 121 | set_sum_contrasts() 122 | data("Machines", package = "MEMSS") 123 | suppressWarnings(capture_output({ 124 | mm2 <- brm(score ~ Machine + (Machine|Worker), data=Machines, 125 | chains = 2, cores = 1, seed = 12345, iter = 1000) 126 | })) 127 | bb1n <- afex_plot(mm2, "Machine", data = Machines, dv = "score", 128 | return = "data") 129 | bb2n <- afex_plot(mm2, "Machine", id = "Worker", 130 | data = Machines, dv = "score", return = "data") 131 | load("afex_plot-brms.rda") 132 | expect_equal(bb1n, brmslist$bb1n, tolerance = 5) 133 | expect_equal(bb2n, brmslist$bb2n, tolerance = 5) 134 | # brmslist <- list( 135 | # bb1n = bb1n, 136 | # bb2n = bb2n 137 | # ) 138 | # save(brmslist, file = "tests/testthat/afex_plot-brms.rda") 139 | 140 | expect_error(afex_plot(mm2, "Machine", data = Machines), 141 | "Could not detect dv column") 142 | 143 | }) 144 | -------------------------------------------------------------------------------- /tests/testthat/test-compare_2_vectors.R: -------------------------------------------------------------------------------- 1 | 2 | context("compare.2.vectors: known bugs") 3 | 4 | test_that("exactly equal mean does not fail", { 5 | x <- c(0.309, 0.222, 0.293, 0.238, 0.33, 0.215) 6 | y <- c(0.313, 0.213, 0.306, 0.253, 0.294, 0.228) 7 | out <- suppressWarnings(compare.2.vectors(x, y, paired = TRUE)) 8 | expect_is(out,"list") 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/test-lmerTest-support.R: -------------------------------------------------------------------------------- 1 | 2 | context("interplay with lmerTest") 3 | 4 | test_that("mixed allows both lme4 and lmerText calls and exports lmerTest::lmer", { 5 | aop <- afex_options() 6 | data(sk2011.1) 7 | m1 <- mixed(response ~ instruction*inference*plausibility +(1|id), sk2011.1, 8 | progress = FALSE, return = "merMod") 9 | m1b <- lmer(response ~ instruction*inference*plausibility +(1|id), sk2011.1) 10 | expect_true(inherits(m1, "merModLmerTest") || inherits(m1, "lmerModLmerTest")) 11 | expect_is(m1, "merMod") 12 | expect_true(inherits(m1b, "merModLmerTest") || inherits(m1b, "lmerModLmerTest")) 13 | afex_options(lmer_function = "lme4") 14 | m2 <- mixed(response ~ instruction*inference*plausibility +(1|id), sk2011.1, 15 | progress = FALSE, return = "merMod") 16 | expect_false(inherits(m2, "merModLmerTest") && inherits(m2, "lmerModLmerTest")) 17 | expect_is(m2, "merMod") 18 | afex_options(aop) 19 | expect_true("Pr(>F)" %in% colnames(lmerTest_anova(m1))) 20 | expect_true("Pr(>F)" %in% colnames(lmerTest_anova(m1b))) 21 | expect_false("Pr(>F)" %in% colnames(anova(m2))) 22 | expect_true("Pr(>F)" %in% colnames(lmerTest_anova(m2))) 23 | 24 | ## following tests only work with new lmerTest (March 2018) 25 | pkg_version <- "2.0-37.9005" 26 | skip_if(packageVersion(pkg = "lmerTest") < pkg_version) 27 | expect_true("Pr(>F)" %in% colnames(anova(m1))) 28 | expect_true("Pr(>F)" %in% colnames(anova(m1b))) 29 | 30 | }) 31 | 32 | -------------------------------------------------------------------------------- /tests/testthat/test-mixed-effects.R: -------------------------------------------------------------------------------- 1 | context("mixed interplay with effects") 2 | 3 | 4 | test_that("mixed works with effects", { 5 | skip_if_not_installed("MEMSS") 6 | data("Machines", package = "MEMSS") 7 | # simple model with random-slopes for repeated-measures factor 8 | # requires: set_data_arg = TRUE 9 | m1 <- mixed(score ~ Machine + (Machine|Worker), data=Machines, 10 | set_data_arg = TRUE, progress = FALSE) 11 | 12 | testthat::skip_if_not_installed("effects") 13 | testthat::skip_if_not_installed("emmeans") 14 | library("effects") 15 | 16 | set_default_contrasts() 17 | 18 | em1 <- emmeans::emmeans(m1, "Machine") 19 | ef1 <- Effect("Machine", m1$full_model) # 20 | 21 | expect_false(any( 22 | as.data.frame(ef1)$fit == as.data.frame(em1)$emmean 23 | )) 24 | 25 | set_sum_contrasts() 26 | ef2 <- Effect("Machine", m1$full_model) 27 | 28 | expect_equal(as.data.frame(ef2)$fit, as.data.frame(em1)$emmean) 29 | 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-mixed-mw.R: -------------------------------------------------------------------------------- 1 | 2 | context("Mixed LMMs: replicating Maxwell & Delaney (2004)") 3 | 4 | test_that("mixed: Maxell & Delaney (2004), Table 16.3, p. 837", { 5 | ### replicate results from Table 16.3 (Maxwell & Delaney, 2004, p. 837) 6 | data(md_16.1) 7 | # original results need treatment contrasts: 8 | mixed1_orig <- mixed(severity ~ sex + (1|id), md_16.1, check_contrasts=FALSE, progress=FALSE) 9 | expect_that(fixef(mixed1_orig$full_model), is_equivalent_to(c(60, -14))) 10 | expect_that(round(anova(mixed1_orig)[1,"F"],2), equals(9.97)) 11 | expect_that(round(anova(mixed1_orig)[1,"Pr(>F)"],2), equals(0.03)) 12 | }) 13 | 14 | test_that("mixed: Maxell & Delaney (2004), Table 16.6, p. 845", { 15 | data(md_16.4) 16 | skip_if_not_installed("Matrix") 17 | md_16.4b <- within(md_16.4, cond <- C(cond, contr.treatment, base = 2)) 18 | mixed2_orig <- mixed(induct ~ cond + (1|room:cond), md_16.4b, 19 | check_contrasts=FALSE, progress=FALSE) 20 | expect_equivalent( 21 | object = unname(round(fixef(mixed2_orig$full_model), 4)), 22 | expected = c(35.6261, -8.1485)) 23 | expect_that( 24 | object = unname(round(sqrt(Matrix::diag(vcov(mixed2_orig$full_model))), 25 | 3)), 26 | condition = equals(c(3.229, 4.548))) 27 | expect_that(round(mixed2_orig[[1]]$F, 1), equals(3.2)) 28 | }) 29 | 30 | test_that("mixed: Maxell & Delaney (2004), Table 16.7, p. 851 (uses simple F!)", { 31 | data(md_16.4) 32 | skip_if_not_installed("Matrix") 33 | md_16.4b <- within(md_16.4, cond <- C(cond, contr.treatment, base = 2)) 34 | ### replicate results from Table 16.7 (Maxwell & Delaney, 2004, p. 851) 35 | # F-values (almost) hold, p-values (especially for skill) are off 36 | # however, parameters are perfectly recovered when using the original contrasts: 37 | mixed3_orig <- mixed(induct ~ cond + skill + (1|room:cond), md_16.4b, 38 | check_contrasts=FALSE, progress=FALSE) 39 | expect_that(object = unname(round(fixef(mixed3_orig$full_model), 2)), 40 | condition = is_equivalent_to(c(20.25, -7.57, 2.31))) 41 | expect_that( 42 | object = unname(round(sqrt(Matrix::diag(vcov(mixed3_orig$full_model))), 43 | 2)), 44 | condition = equals(c(5.82, 2.72, 0.81))) 45 | expect_that(round(mixed3_orig[[1]]$F), equals(c(8, 8))) 46 | #mixed3_F_simple <- mixed(induct ~ cond + skill + (1|room:cond), md_16.4b, check_contrasts=FALSE, progress=FALSE, method = "F") 47 | #expect_that(round(fixef(mixed3_F_simple$full_model), 2), is_equivalent_to(c(20.25, -7.57, 2.31))) 48 | #expect_that(round(sqrt(diag(vcov(mixed3_F_simple$full_model))), 2), equals(c(5.82, 2.72, 0.81))) 49 | #expect_that(round(mixed3_F_simple[[1]]$F, 1), equals(c(7.8, 8.2))) 50 | }) 51 | 52 | test_that("mixed: Maxell & Delaney (2004), Table 16.10, p. 862 (does not replicate the table!)", { 53 | data(md_16.4) 54 | md_16.4b <- within(md_16.4, cond <- C(cond, contr.treatment, base = 2)) 55 | #note: the values in this test should not replicate the table... 56 | md_16.4b$cog <- scale(md_16.4b$cog, scale=FALSE) 57 | mixed4 <- mixed(induct ~ cond*cog + (cog|room:cond), md_16.4b, progress=FALSE, check_contrasts=FALSE) 58 | expect_that(unname(round(fixef(mixed4$full_model), 2)), is_equivalent_to(c(36.1, -9.07, 0.64, 0.03))) 59 | }) 60 | -------------------------------------------------------------------------------- /tests/testthat/test-predict.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | context("predict") 4 | 5 | data(obk.long, package = "afex") 6 | df <- obk.long 7 | df$hour <- as.numeric(df$hour) 8 | 9 | newdata <- df[1:5,] 10 | 11 | 12 | test_that("between (compare to lm)", { 13 | between <- aov_car(value ~ treatment*gender + Error(id), data = df, 14 | fun_aggregate = mean) 15 | fit.lm <- lm(value ~ treatment*gender, data = between$data$long) 16 | 17 | 18 | expect_equal(predict(between, newdata), predict(fit.lm, newdata)) 19 | expect_is(predict(between, newdata), "numeric") 20 | expect_is(predict(between, newdata, append = TRUE), "data.frame") 21 | }) 22 | 23 | test_that("within + factorized numerics", { 24 | within <- aov_car(value ~ 1 + Error(id/(phase*hour)), data = df) 25 | 26 | p1 <- predict(within, newdata = data.frame(phase = "pre", hour = 1)) 27 | p2 <- predict(within, newdata = data.frame(phase = "pre", hour = "1")) 28 | expect_equal(p1, p2) 29 | expect_equal(unname(p1), 3.8125) 30 | expect_error(predict(within, newdata = data.frame(phase = "pre", hour = 6))) 31 | }) 32 | 33 | -------------------------------------------------------------------------------- /tests/testthat/test-residuals.R: -------------------------------------------------------------------------------- 1 | context("residuals: check if it works") 2 | 3 | data(obk.long, package = "afex") 4 | between <- aov_car(value ~ treatment*gender + Error(id), data = obk.long, 5 | fun_aggregate = mean) 6 | mixed <- aov_car(value ~ treatment * gender + Error(id/(phase*hour)), data = obk.long) 7 | within <- aov_car(value ~ 1 + Error(id/(phase*hour)), data = obk.long) 8 | 9 | ## between data with correct order 10 | obk2 <- aggregate(value ~ gender + treatment + id , data = obk.long, FUN = mean) 11 | between2 <- aov_car(value ~ treatment*gender + Error(id), data = obk2) 12 | between2lm <- lm(value ~ treatment*gender, data = obk2) 13 | 14 | between3 <- aov_car(value ~ treatment*gender + Error(id), 15 | data = obk2[rev(seq_len(nrow(obk2))),]) 16 | 17 | 18 | ## within data with correct order 19 | obk3 <- obk.long[with(obk.long, order(id, phase, hour)), ] 20 | within2 <- aov_car(value ~ 1 + Error(id/(phase*hour)), data = obk3) 21 | 22 | test_that("Residuals", { 23 | expect_message(residuals(within), "Data was changed") 24 | expect_message(residuals(mixed), "Data was changed") 25 | expect_message(residuals(between), "Data was changed") 26 | expect_message(residuals(between3), "Data was changed") 27 | 28 | expect_message(residuals(between2), regexp = NA) 29 | expect_message(residuals(within2), regexp = NA) 30 | 31 | expect_equal(residuals(between2), residuals(between2lm)) 32 | 33 | expect_is(suppressWarnings(residuals(within)),"numeric") 34 | expect_is(suppressWarnings(residuals(mixed)),"numeric") 35 | expect_is(suppressWarnings(residuals(between)),"numeric") 36 | 37 | expect_is(residuals(within, append = TRUE),"data.frame") 38 | expect_is(residuals(mixed, append = TRUE),"data.frame") 39 | expect_is(residuals(between, append = TRUE),"data.frame") 40 | }) 41 | 42 | 43 | test_that("Fitted", { 44 | expect_message(fitted(within)) 45 | expect_message(fitted(mixed)) 46 | expect_message(fitted(between)) 47 | 48 | expect_message(fitted(between2), regexp = NA) 49 | expect_message(fitted(within2), regexp = NA) 50 | 51 | expect_equal(fitted(between2), fitted(between2lm)) 52 | 53 | expect_is(suppressWarnings(fitted(within)),"numeric") 54 | expect_is(suppressWarnings(fitted(mixed)),"numeric") 55 | expect_is(suppressWarnings(fitted(between)),"numeric") 56 | 57 | expect_is(fitted(within, append = TRUE),"data.frame") 58 | expect_is(fitted(mixed, append = TRUE),"data.frame") 59 | expect_is(fitted(between, append = TRUE),"data.frame") 60 | }) 61 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/introduction-mixed-models.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/singmann/afex/d72360a48e9c9b2b77168de024936805caaeab0b/vignettes/introduction-mixed-models.pdf -------------------------------------------------------------------------------- /vignettes/introduction-mixed-models.pdf.asis: -------------------------------------------------------------------------------- 1 | %\VignetteIndexEntry{An Introduction to Mixed Models for Experimental Psychology} 2 | %\VignetteEngine{R.rsp::asis} 3 | %\VignetteKeyword{PDF} 4 | %\VignetteKeyword{vignette} 5 | %\VignetteKeyword{package} 6 | 7 | --------------------------------------------------------------------------------