├── .Rbuildignore ├── .gitignore ├── .prettierignore ├── .prettierrc.yaml ├── .travis.yml ├── DATASETS.Rmd ├── DESCRIPTION ├── EXPLANATIONS.Rmd ├── MODELS.Rmd ├── PATTERNS.Rmd ├── Table1_APA.doc ├── _bookdown.yml ├── _output.yml ├── additional-stubs.Rmd ├── airquality-r-values.csv ├── anova.Rmd ├── basic-statistics.Rmd ├── bayes-mcmc.Rmd ├── bibliography.bib ├── cfa-sem.Rmd ├── cleaning-up-your-mess.Rmd ├── clustering.Rmd ├── code-hygiene.Rmd ├── colours.Rmd ├── column-types-and-missing.Rmd ├── confidence-and-intervals.Rmd ├── correlations.Rmd ├── crosstabulation.Rmd ├── data ├── angry_moods.csv ├── expt.data.RDS ├── eysenck.Rdata ├── fit-weight.RDS ├── funding-successful-projects-on-kickstarter │ ├── test.csv │ └── train.csv ├── injury.Rdata ├── juice.RDS ├── lakers.RDS ├── lego.RDS ├── mh-in-tech-survey.csv ├── miles-pre-1970.RDS ├── miles.RDS ├── miletimes.csv ├── multiple-file-example │ ├── person1.csv │ ├── person10.csv │ ├── person11.csv │ ├── person12.csv │ ├── person13.csv │ ├── person14.csv │ ├── person15.csv │ ├── person16.csv │ ├── person17.csv │ ├── person18.csv │ ├── person19.csv │ ├── person2.csv │ ├── person20.csv │ ├── person21.csv │ ├── person22.csv │ ├── person23.csv │ ├── person24.csv │ ├── person25.csv │ ├── person26.csv │ ├── person27.csv │ ├── person28.csv │ ├── person29.csv │ ├── person3.csv │ ├── person30.csv │ ├── person31.csv │ ├── person32.csv │ ├── person33.csv │ ├── person34.csv │ ├── person35.csv │ ├── person36.csv │ ├── person37.csv │ ├── person38.csv │ ├── person39.csv │ ├── person4.csv │ ├── person40.csv │ ├── person41.csv │ ├── person42.csv │ ├── person43.csv │ ├── person44.csv │ ├── person45.csv │ ├── person46.csv │ ├── person47.csv │ ├── person48.csv │ ├── person5.csv │ ├── person6.csv │ ├── person7.csv │ ├── person8.csv │ └── person9.csv ├── painmusic.RDS ├── phq-summary.csv ├── phq9.csv ├── sleep.long.RDS ├── sleep.wide.RDS └── titanic.csv ├── diagram.R ├── example.datasets.Rmd ├── examples-of-notes.Rmd ├── fancy-reshaping.Rmd ├── fixed-or-random.Rmd ├── generalized-linear-models.Rmd ├── graphics-ggplot-extras.Rmd ├── graphics.Rmd ├── headers.html ├── help.Rmd ├── import-export.Rmd ├── index.Rmd ├── install-bayes-tools.R ├── interactions.Rmd ├── license.txt ├── linear-models.Rmd ├── link-functions.Rmd ├── making-table-1.Rmd ├── media ├── Holding_the_eiffel_tower.jpg ├── arcane_bullshit_2x.png ├── aurora-1-px-grey.jpg ├── aurora-1-px-raw.png ├── aurora-1-px.jpg ├── aurora.jpg ├── aurora.png ├── backtick-mac-uk.png ├── backtick-windows-uk.png ├── budget1.png ├── budget2.png ├── choosing_a_good_chart.jpg ├── face1.png ├── face2.png ├── graphics-cookbook.png ├── homer-car.jpg ├── illusioncolours.jpg ├── inline-r-example.png ├── jeeves.jpg ├── keepcalm.png ├── large-family.jpg ├── lego-blocks-2458575_1280-1.jpg ├── map_projections.png ├── optimization_2x.png ├── patterns.png ├── r-code-chunk.png ├── rstudio-mainwindow.png ├── rstudio.png ├── rugs1.jpg ├── rugs1.png ├── rugs2.jpg ├── significant.png ├── sunset-sidebyside.jpg ├── sunset1.jpg ├── sunset2.jpg ├── telescope_names_2x.png ├── tubes.jpg └── xkcd_presidents_overfitting.png ├── mediation-and-covariance-models.Rmd ├── meta-analysis.Rmd ├── mixed-shrinkage.Rmd ├── models-are-data.Rmd ├── multilevel-models.Rmd ├── multiple-comparisons.Rmd ├── non-parametrics.Rmd ├── over-fitting.Rmd ├── packages.Rmd ├── polynomials.Rmd ├── power-analysis.Rmd ├── preamble.tex ├── predictions-and-margins.Rmd ├── quirks.Rmd ├── real-data.Rmd ├── references.Rmd ├── requirements.R ├── reshaping-video.Rmd ├── reshaping.Rmd ├── scaling-predictors.Rmd ├── set_chunk_options.R ├── sharing-and-publishing.Rmd ├── simplifying-and-reusing.Rmd ├── start_here.Rmd ├── string-handling.Rmd ├── style.css ├── summarising-data.Rmd ├── summarising-video.Rmd ├── t-tests.Rmd ├── tidy-data.Rmd ├── toc.css ├── troubles.Rmd ├── working-with-dataframes.Rmd └── writing-a-paper.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | libs/ 2 | docs/ 3 | TODO 4 | _archive 5 | unused* 6 | media/rstudio-screenshots.graffle/ 7 | just_enough_R.Rproj 8 | .Rhistory 9 | serve.R 10 | build.R 11 | .httr-oauth 12 | .Rproj.user 13 | *_cache 14 | *.md 15 | *_files/ 16 | !docs/*_files/ 17 | *.acorn 18 | *.mov 19 | myplot.pdf 20 | docsold/ 21 | howell-data/ 22 | assets/* 23 | Just Enough R.rds 24 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .travis.yml 2 | -------------------------------------------------------------------------------- /.prettierrc.yaml: -------------------------------------------------------------------------------- 1 | { 2 | "proseWrap": "always", 3 | "printWidth": 80, 4 | "tabWidth": 4, 5 | "singleQuote": true 6 | } 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # See https://docs.travis-ci.com/user/languages/r/ 2 | dist: trusty 3 | language: r 4 | # R binary packages not supported with 'sudo: false' or 'dist: precise', falling back to source install 5 | sudo: true 6 | 7 | cache: 8 | packages: yes 9 | 10 | before_install: 11 | - mkdir -p ~/.R/ 12 | - echo "CXX14 = g++-7 -fPIC -flto=2" >> ~/.R/Makevars 13 | - echo "CXX14FLAGS = -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations -Wno-attributes -O3" >> ~/.R/Makevars 14 | 15 | matrix: 16 | include: 17 | - os: linux 18 | addons: 19 | apt: 20 | sources: 21 | - ubuntu-toolchain-r-test 22 | packages: 23 | - g++-7 24 | env: 25 | - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" 26 | 27 | r_binary_packages: 28 | - data.table 29 | - dplyr 30 | - lavaan 31 | - lme4 32 | - nlme 33 | - Rcpp 34 | - reshape2 35 | - rstan 36 | - rstanarm 37 | - tidyverse 38 | 39 | apt_packages: 40 | - libxml2-dev 41 | - libv8-dev 42 | 43 | r_github_packages: 44 | - achetverikov/APAstats/apastats 45 | 46 | # repos: 47 | # CRAN: https://mran.microsoft.com/snapshot/2018-07-01 48 | 49 | script: 50 | - | 51 | Rscript -e 'bookdown::render_book("index.Rmd", "bookdown::gitbook")' 52 | Rscript -e 'bookdown::render_book("index.Rmd", "bookdown::pdf_book")' 53 | 54 | deploy: 55 | provider: pages 56 | skip-cleanup: true 57 | github-token: $GITHUB_TOKEN # Set in the settings page of your repository, as a secure variable 58 | keep-history: true 59 | local-dir: docs 60 | verbose: true 61 | -------------------------------------------------------------------------------- /DATASETS.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Datasets and dataframes' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | library(tufte) 8 | ``` 9 | 10 | # (PART) Data {- #data} 11 | 12 | # The `dataframe` {#datasets-dataframes} 13 | 14 | A `dataframe` is a container for our data. 15 | 16 | It's much like a spreadsheet, but with some constraints applied. 'Constraints' 17 | might sound bad, but they're actually helpful: they make dataframes more 18 | structured and predictable to work with. The main constraints are that: 19 | 20 | - Each column is a [vector](#vectors-and-lists), and so can 21 | [only store one type of data](#vectors-and-lists). 22 | 23 | - Every column has to be the same length (although missing values are 24 | allowed). 25 | 26 | - Each column must have a name. 27 | 28 | A `tibble` is an updated version of a dataframe with a whimsical name, which is 29 | part of the `tidyverse`. It's almost exactly the same a dataframe, but with some 30 | rough edges smoothed off — it's safe and preferred to use `tibble` in place of 31 | `data.frame`. 32 | 33 | You can make a simple tibble or dataframe like this: 34 | 35 | ```{r} 36 | data.frame(myvariable = 1:10) 37 | ``` 38 | 39 | Using a tible is much the same, but allows some extra tricks like creating one 40 | variable from another: 41 | 42 | ```{r} 43 | tibble( 44 | height_m = rnorm(10, 1.5, .2), 45 | weight_kg = rnorm(10, 65, 10), 46 | bmi = weight_kg / height_m ^ 2, 47 | overweight = bmi > 25 48 | ) 49 | ``` 50 | 51 | #### Using 'built in' data {- #built-in-data} 52 | 53 | The quickest way to see a dataframe in action is to use one that is built in to 54 | R 55 | ([this page](https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html) 56 | lists all the built-in datasets). For example: 57 | 58 | ```{r} 59 | head(airquality) 60 | ``` 61 | 62 | Or 63 | 64 | ```{r} 65 | head(mtcars) 66 | ``` 67 | 68 | In both these examples the datasets are already loaded and available to be used 69 | with the `head()` function. 70 | 71 | :::{.exercise} 72 | 73 | To find a list of all the built in datasets you can type `help(datasets)` into 74 | the console, or see 75 | . 76 | 77 | Familiarise yourself with some of the other included datasets, e.g. 78 | `datasets::attitude`. Watch out that not all the included datasets are 79 | _dataframes_: Some are just vectors of observations (e.g. the `airmiles` data) 80 | and some are 'time-series', (e.g. the `co2` data) 81 | 82 | ::: 83 | 84 | #### Looking at dataframes {- #looking-at-data} 85 | 86 | As we've already seen, using `print(df)` within an RMarkdown document creates a 87 | nice interactive table you can use to look at your data. 88 | 89 | However you won't want to print your whole data file when you Knit your 90 | RMarkdown document. The `head` function can be useful if you just want to show a 91 | few rows: 92 | 93 | ```{r} 94 | head(mtcars) 95 | ``` 96 | 97 | Or we can use `glimpse()` function from the `dplyr::` package (see the 98 | [section on loading and using packages](#packages)) for a different view of the 99 | first few rows of the `mtcars` data. This flips the dataframe so the variables 100 | are listed in the first column of the output: 101 | 102 | ```{r} 103 | glimpse(mtcars) 104 | ``` 105 | 106 | You can use the `pander()` function (from the `pander::` package) to format 107 | tables nicely, for when you Knit a document to HTML, Word or PDF. For example: 108 | 109 | ```{r} 110 | library(pander) 111 | pander(head(airquality), caption="Tables always need a caption.") 112 | ``` 113 | 114 | See the section on [sharing and publishing](#sharing-and-publication) for more 115 | ways to format and present tables. 116 | 117 | Other useful functions for looking at and exploring datasets include: 118 | 119 | - `summary(df)` 120 | - `psych::describe(df)` 121 | - `skimr::skim(df)` 122 | 123 | :::{.exercise} 124 | 125 | Experiment with a few of the functions for viewing/summarising dataframes. 126 | 127 | ::: 128 | 129 | There are also some helpful plotting functions which accept a whole dataframe as 130 | their input: 131 | 132 | ```{r, fig.cap="Box plot of all variables in a dataset."} 133 | boxplot(airquality) 134 | ``` 135 | 136 | ```{r, fig.cap="Correlation heatmap of all variables in a dataset. Colours indicate size of the correlation between pairs of variables."} 137 | psych::cor.plot(airquality) 138 | ``` 139 | 140 | These plots might not be worth including in a final write-up, but are very 141 | useful when exploring your data. 142 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: jer 2 | Title: Just Enough R 3 | Version: 0.3 4 | Imports: 5 | AER, 6 | afex, 7 | apa, 8 | apastats, 9 | apaTables, 10 | arm, 11 | bayesplot, 12 | bookdown, 13 | brms, 14 | broom, 15 | car, 16 | coin, 17 | corrgram, 18 | cowplot, 19 | DAAG, 20 | devtools, 21 | DiagrammeR, 22 | DiagrammeRsvg, 23 | emmeans, 24 | ez, 25 | gapminder, 26 | GGally, 27 | ggthemes, 28 | grDevices, 29 | gridExtra, 30 | Hmisc, 31 | huxtable, 32 | knitr, 33 | lmerTest, 34 | lsmeans, 35 | margins, 36 | mediation, 37 | merTools, 38 | mice, 39 | MuMIn, 40 | pander, 41 | png, 42 | psych, 43 | pwr, 44 | readxl, 45 | rmarkdown, 46 | rsvg, 47 | semPlot, 48 | simr, 49 | skimr, 50 | sn, 51 | statcheck, 52 | stats, 53 | tidybayes, 54 | tufte, 55 | waffle, 56 | 57 | -------------------------------------------------------------------------------- /EXPLANATIONS.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Explanations' 3 | --- 4 | 5 | # (PART) Explanations {-} 6 | -------------------------------------------------------------------------------- /MODELS.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Analysis' 3 | --- 4 | 5 | # (PART) Models {-} 6 | -------------------------------------------------------------------------------- /PATTERNS.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Patterns' 3 | --- 4 | 5 | # (PART) Patterns {-} 6 | 7 | # Learning key patterns 8 | 9 | ![](media/patterns.png) 10 | 11 | Statistics courses teach statistics, and software training or programming 12 | courses can teach you the fundamentals of a particular package --- for example 13 | R. 14 | 15 | However, a large part of learning how to analyse data is actually not about 16 | particular statistical techniques, nor the detals of implementing them in a 17 | particular package. 18 | 19 | Instead, the most useful things to take away from a course can be how to think 20 | about different types of problem, and general strategies for tackling them. One 21 | label applied to these approaches and strategies are 'patterns'. 22 | 23 | We've already come across one pattern in the section on 24 | [summarising data](summarising-data): the 25 | [split, apply, combine method](#split-apply-combine). 26 | 27 | This section outlines some other patterns or ways of working that may be 28 | helpful. 29 | -------------------------------------------------------------------------------- /_bookdown.yml: -------------------------------------------------------------------------------- 1 | bibliography: ["bibliography.bib"] 2 | citation_package: biblatex 3 | biblio-style: "apa6" 4 | link-citations: true 5 | # cover-image: "media/keepcalm.png" 6 | book_filename: "Just enough R" 7 | new_session: yes 8 | before_chapter_script: set_chunk_options.R 9 | output_dir: "docs" 10 | delete_merged_file: true 11 | rmd_files: 12 | 13 | [ 14 | # GETTING STARTED 15 | "index.Rmd", 16 | "start_here.Rmd", 17 | "packages.Rmd", 18 | 19 | # PART DATA 20 | "DATASETS.Rmd", 21 | "working-with-dataframes.Rmd", 22 | 23 | "real-data.Rmd", 24 | "import-export.Rmd", 25 | "column-types-and-missing.Rmd", 26 | "tidy-data.Rmd", 27 | "reshaping.Rmd", 28 | "summarising-data.Rmd", 29 | "fancy-reshaping.Rmd", 30 | 31 | 32 | "graphics.Rmd", 33 | "graphics-ggplot-extras.Rmd", 34 | 35 | # "example.datasets.Rmd", 36 | 37 | 38 | # PART MODELS 39 | "MODELS.Rmd", 40 | "basic-statistics.Rmd", 41 | "non-parametrics.Rmd", 42 | "crosstabulation.Rmd", 43 | "correlations.Rmd", 44 | "t-tests.Rmd", 45 | "linear-models.Rmd", 46 | "anova.Rmd", 47 | "generalized-linear-models.Rmd", 48 | "multilevel-models.Rmd", 49 | "mediation-and-covariance-models.Rmd", 50 | "cfa-sem.Rmd", 51 | 52 | # "additional-stubs.Rmd", 53 | "bayes-mcmc.Rmd", 54 | "power-analysis.Rmd", 55 | 56 | # PART Patterns 57 | "PATTERNS.Rmd", 58 | "interactions.Rmd", 59 | "predictions-and-margins.Rmd", 60 | "models-are-data.Rmd", 61 | "simplifying-and-reusing.Rmd", 62 | "making-table-1.Rmd", 63 | "quirks.Rmd", 64 | "string-handling.Rmd", 65 | "colours.Rmd", 66 | 67 | "help.Rmd", 68 | 69 | 70 | # PART explanations 71 | "EXPLANATIONS.Rmd", 72 | "confidence-and-intervals.Rmd", 73 | "multiple-comparisons.Rmd", 74 | "clustering.Rmd", 75 | "fixed-or-random.Rmd", 76 | "scaling-predictors.Rmd", 77 | "link-functions.Rmd", 78 | "over-fitting.Rmd", 79 | 80 | 81 | 82 | 83 | 84 | 85 | # "sharing-and-publishing.Rmd", 86 | # "writing-a-paper.Rmd", 87 | # "cleaning-up-your-mess.Rmd", 88 | 89 | 90 | 91 | "references.Rmd" 92 | ] 93 | -------------------------------------------------------------------------------- /_output.yml: -------------------------------------------------------------------------------- 1 | bookdown::gitbook: 2 | includes: 3 | in_header: headers.html 4 | css: style.css 5 | config: 6 | toc: 7 | collapse: section 8 | before: | 9 |
  • Just enough R
  • 10 | download: null 11 | split_by: section 12 | 13 | bookdown::pdf_book: 14 | includes: 15 | in_header: preamble.tex 16 | latex_engine: xelatex 17 | citation_package: natbib 18 | keep_tex: yes 19 | -------------------------------------------------------------------------------- /additional-stubs.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Bayes factors' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | library(pander) 8 | library(lmerTest) 9 | ``` 10 | 11 | # Additional stub articles 12 | 13 | These hopefully to be fleshed out soon. Contributions welcome! 14 | 15 | ## Meta analysis {- #meta-analysis} 16 | 17 | For the moment, 18 | [see this introduction to meta analysis in R](https://www.r-bloggers.com/r-and-meta-analysis/) 19 | 20 | ## Bayes factors {- #bayes-factors} 21 | 22 | TODO 23 | 24 | Tongue in cheek Chapter that Andy proposed as a Stage 4 option: "doing BF for 25 | rubbish data..." 26 | 27 | Cover: 28 | 29 | - What is a BF: 30 | http://bayesfactor.blogspot.co.uk/2014/02/the-bayesfactor-package-this-blog-is.html 31 | https://en.wikipedia.org/wiki/Bayes_factor#Interpretation 32 | 33 | - BF package manual http://bayesfactorpcl.r-forge.r-project.org/#twosample 34 | 35 | - BayesFactors not (too) sensitive to choice of priors: 36 | http://www.nicebread.de/interactive-exploration-of-a-priors-impact/ 37 | 38 | Also explore parameter estimation and inference from posterior of parameters as 39 | an alternative approach (see Krusche chapter, and Gelman papers). 40 | -------------------------------------------------------------------------------- /airquality-r-values.csv: -------------------------------------------------------------------------------- 1 | "","Ozone","Solar.R","Wind","Temp","Month","Day" 2 | "Ozone",1,0.348341692993603,-0.60154652988895,0.698360342150932,0.164519314380413,-0.013225646554047 3 | "Solar.R",0.348341692993603,1,-0.0567916657698467,0.275840271340805,-0.0753007638859408,-0.150274979240985 4 | "Wind",-0.60154652988895,-0.0567916657698467,1,-0.457987879104833,-0.17829257921769,0.027180902809146 5 | "Temp",0.698360342150932,0.275840271340805,-0.457987879104833,1,0.420947252266222,-0.130593175159278 6 | "Month",0.164519314380413,-0.0753007638859408,-0.17829257921769,0.420947252266222,1,-0.00796176260045312 7 | "Day",-0.013225646554047,-0.150274979240985,0.027180902809146,-0.130593175159278,-0.00796176260045312,1 8 | -------------------------------------------------------------------------------- /basic-statistics.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Common statistics' 3 | --- 4 | 5 | # Commonly used statistics {#common-stats} 6 | 7 | R has simple functions for common inferential statistics like Chi^2^, t-tests, 8 | correlations and many more. This section is by no means exhaustive, but covers 9 | [statistics for crosstabulations](#crosstabs), [differences in means](#t-tests), 10 | and [linear correlation](#correlations). 11 | -------------------------------------------------------------------------------- /bayes-mcmc.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Bayesian linear modelling via MCMC' 3 | --- 4 | 5 | ```{r, include=F} 6 | knitr::opts_chunk$set(echo = TRUE, collapse=TRUE, cache=TRUE, message=F, warning=F) 7 | 8 | library(tidyverse) 9 | library(pander) 10 | library(lmerTest) 11 | 12 | ``` 13 | 14 | # Baysian model fitting {#bayes-mcmc} 15 | 16 | ### Baysian fitting of linear models via MCMC methods {-} 17 | 18 | This is a minimal guide to fitting and interpreting regression and multilevel 19 | models via MCMC. For _much_ more detail, and a much more comprehensive 20 | introduction to modern Bayesian analysis see 21 | [Jon Kruschke's _Doing Bayesian Data Analysis_](http://www.indiana.edu/~kruschke/DoingBayesianDataAnalysis/). 22 | 23 | Let's revisit our 24 | [previous example which investigated the effect of familiar and liked music on pain perception](#pain-music-data): 25 | 26 | ```{r} 27 | painmusic <- readRDS('data/painmusic.RDS') 28 | painmusic %>% 29 | ggplot(aes(liked, with.music - no.music, 30 | group=familiar, color=familiar)) + 31 | stat_summary(geom="pointrange", fun.data=mean_se) + 32 | stat_summary(geom="line", fun.data=mean_se) + 33 | ylab("Pain (VAS) with.music - no.music") + 34 | scale_color_discrete(name="") + 35 | xlab("") 36 | ``` 37 | 38 | ```{r} 39 | # set sum contrasts 40 | options(contrasts = c("contr.sum", "contr.poly")) 41 | pain.model <- lm(with.music ~ 42 | no.music + familiar * liked, 43 | data=painmusic) 44 | summary(pain.model) 45 | ``` 46 | 47 | Do the same thing again, but with with MCMC using Stan: 48 | 49 | ```{r, echo=T, results="hide"} 50 | library(rstanarm) 51 | options(contrasts = c("contr.sum", "contr.poly")) 52 | pain.model.mcmc <- stan_lm(with.music ~ no.music + familiar * liked, 53 | data=painmusic, prior=NULL) 54 | ``` 55 | 56 | ```{r} 57 | summary(pain.model.mcmc) 58 | ``` 59 | 60 | ### Posterior probabilities for parameters {-} 61 | 62 | ```{r} 63 | library(bayesplot) 64 | 65 | mcmc_areas(as.matrix(pain.model.mcmc), regex_pars = 'familiar|liked', prob = .9) 66 | ``` 67 | 68 | ```{r} 69 | mcmc_intervals(as.matrix(pain.model.mcmc), regex_pars = 'familiar|liked', prob_outer = .9) 70 | ``` 71 | 72 | ### Credible intervals {- #credible-intervals} 73 | 74 | Credible intervals are distinct from [confidence intervals](#intervals) 75 | 76 | TODO EXPAND 77 | 78 | 86 | 87 | ```{r} 88 | 89 | params.of.interest <- 90 | pain.model.mcmc %>% 91 | as_tibble %>% 92 | reshape2::melt() %>% 93 | filter(stringr::str_detect(variable, "famil|liked")) %>% 94 | group_by(variable) 95 | 96 | params.of.interest %>% 97 | tidybayes::mean_hdi() %>% 98 | pander::pandoc.table(caption="Estimates and 95% credible intervals for the parameters of interest") 99 | ``` 100 | 101 | ### Bayesian 'p values' for parameters {-} 102 | 103 | We can do simple arithmetic with the posterior draws to calculate the 104 | probability a parameter is greater than (or less than) zero: 105 | 106 | ```{r} 107 | params.of.interest %>% 108 | summarise(estimate=mean(value), 109 | `p (x<0)` = mean(value < 0), 110 | `p (x>0)` = mean(value > 0)) 111 | ``` 112 | 113 | Or if you'd like the Bayes Factor (evidence ratio) for one hypotheses vs 114 | another, for example comparing the hypotheses that a parameter is > vs. <= 0, 115 | then you can use the `hypothesis` function in the `brms` package: 116 | 117 | ```{r} 118 | pain.model.mcmc.df <- 119 | pain.model.mcmc %>% 120 | as_tibble 121 | 122 | brms::hypothesis(pain.model.mcmc.df, 123 | c("familiar1 > 0", 124 | "liked1 > 0", 125 | "familiar1:liked1 < 0")) 126 | ``` 127 | 128 | Here although we only have a 'significant' p value for one of the parameters, we 129 | can also see there is "very strong" evidence that familiarity also influences 130 | pain, and "strong" evidence for the interaction of familiarity and liking, 131 | according to 132 | [conventional rules of thumb when interpreting Bayes Factors](https://en.wikipedia.org/wiki/Bayes_factor#Interpretation). 133 | 134 | TODO - add a fuller explanation of why 135 | [multiple comparisons](#mutiple-comparisons) are not an issue for Bayesian 136 | analysis [@gelman2012we], because _p_ values do not have the same interpretation 137 | in terms of long run frequencies of replication; they are a representation of 138 | the weight of the evidence in favour of a hypothesis. 139 | 140 | TODO: Also reference Zoltan Dienes Bayes paper. 141 | 142 | 152 | -------------------------------------------------------------------------------- /cleaning-up-your-mess.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Cleaning up the mess' 3 | --- 4 | 5 | ```{r, include=FALSE, message=F} 6 | library(tidyverse) 7 | library(reshape2) 8 | library(broom) 9 | library(pander) 10 | ``` 11 | 12 | ## Cleaning up the mess: dealing with raw data {- #raw-data-mess} 13 | 14 | XXX TODO expand on [multiple files example](#multiple-raw-data-files) and show 15 | it worked all the way through, merging multiple files with left_join and 16 | bind_rows/cols 17 | -------------------------------------------------------------------------------- /clustering.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Clustered data' 3 | --- 4 | 5 | # Non-independence {#clustering} 6 | 7 | Psychological data often contains natural _groupings_. In intervention research, 8 | multiple patients may be treated by individual therapists, or children taught 9 | within classes, which are further nested within schools; in experimental 10 | research participants may respond on multiple occasions to a variety of stimuli. 11 | 12 | Although disparate in nature, these groupings share a common characteristic: 13 | they induce _dependency_ between the observations we make. That is, our data 14 | points are _not independently sampled_ from one another. 15 | 16 | What this means is that observations _within_ a particular grouping will tend, 17 | all other things being equal, be more alike than those from a different group. 18 | 19 | #### Why does this matter? {-} 20 | 21 | Think of the last quantitative experiment you read about. If you were the author 22 | of that study, and were offered 10 additional datapoints for 'free', which would 23 | you choose: 24 | 25 | 1. 10 extra datapoints from existing participants. 26 | 2. 10 data points from 10 new participants. 27 | 28 | In general you will gain more _new information_ from data from a new 29 | participant. Intuitively we know this is correct because an extra observation 30 | from someone we have already studies is _less likely to surprise us_ or be 31 | different from the data we already have than an observation from a new 32 | participant. 33 | 34 | Most traditional statistical models assume that data _are_ sampled independently 35 | however. And the precision of the inferences we can draw from from statistical 36 | models is based on the _amount of information we have available_. This means 37 | that if we violate this assumption of independent sampling we will trick our 38 | model into thinking we have more information than we really do, and our 39 | inferences may be wrong. 40 | -------------------------------------------------------------------------------- /code-hygiene.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Code hygiene' 3 | --- 4 | 5 | Sometimes code has a 'smell' about it... 6 | 7 | # Naming variables 8 | 9 | # Using commments 10 | 11 | You can include comments within your R code, to help others understand what your 12 | code does. Comments start with a `#` symbol and are not processed by R when the 13 | code runs. 14 | -------------------------------------------------------------------------------- /colours.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Colours' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | knitr::opts_chunk$set(echo = TRUE, message=F) 7 | 8 | library(tidyverse) 9 | library(pander) 10 | ``` 11 | 12 | ## Colours {-} 13 | 14 | ### Picking colours for plots {- #picking-colours} 15 | 16 | See https://www.perceptualedge.com/articles/b-eye/choosing_colors.pdf for an 17 | interesting discussion on picking colours for data visualisation. 18 | 19 | Also check the 20 | [ggplots docs for colour brewer](http://ggplot2.tidyverse.org/reference/scale_brewer.html) 21 | and the [Colour Brewer website](http://colorbrewer2.org/). 22 | 23 | ### Named colours in R {- #named-colours} 24 | 25 | ```{r, results='asis'} 26 | print.col <- Vectorize(function(col){ 27 | rgb <- grDevices::col2rgb(col) 28 | sprintf("  %s \n\n", rgb[1], rgb[2], rgb[3], col, rgb[1], rgb[2], rgb[3]) 29 | }) 30 | 31 | pandoc.p(print.col(colours())) 32 | ``` 33 | 34 | ### ColourBrewer with ggplot {- #color-brewer} 35 | 36 | See: http://ggplot2.tidyverse.org/reference/scale_brewer.html 37 | -------------------------------------------------------------------------------- /confidence-and-intervals.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Intervals' 3 | bibliography: bibliography.bib 4 | --- 5 | 6 | ```{r, include=FALSE} 7 | library(tidyverse) 8 | ``` 9 | 10 | # Confidence and Intervals {#intervals} 11 | 12 | Some quick definitions to begin. Let's say we have made an estimate from a 13 | model. To keep things simple, it could just be the sample mean. 14 | 15 | 16 | 17 | A _Confidence interval_ is the range within which we would expect the 'true' 18 | value to fall, 95% of the time, if we replicated the study. 19 | 20 | A _Prediction interval_ is the range within which we expect 95% of new 21 | observations to fall. If we're considering the prediction interval for a 22 | specific point prediction (i.e. where we set predictors to specific values), 23 | then this interval woud be for new observations _with the same predictor 24 | values_. 25 | 26 | A Bayesian _Credible interval_ is the range of values within which we are 95% 27 | sure the true value lies, based on our prior knowledge and the data we have 28 | collected. 29 | 30 | ### The problem with confidence intervals {-} 31 | 32 | Confidence intervals are helpful when we want to think about how _precise our 33 | estimate_ is. For example, in an RCT we will want to estimate the difference 34 | between treatment groups, and it's conceivable we would to want to know, for 35 | example, the range within which the true effect would fall 95% of the time if we 36 | replicated our study many times (although in reality, this isn't a question many 37 | people would actually ask). 38 | 39 | If we run a study with small N, intuitively we know that we have less 40 | information about the difference between our RCT treatments, and so we'd like 41 | the CI to expand accordingly. 42 | 43 | So — all things being equal — the confidence interval reduces as we collect more 44 | data. 45 | 46 | The problem with confidence intervals comes about because many researchers and 47 | clinicians read them incorrectly. Typically, they either: 48 | 49 | - Forget that the CI represents only the _precision of the estimate_. The CI 50 | _doesn't_ reflect how good our predictions for new observations will be. 51 | 52 | - Misinterpret the CI as the range in which we are 95% sure the true value 53 | lies. 54 | 55 | ### Forgetting that the CI depends on sample size. {-} 56 | 57 | By forgetting that the CI contracts as the sample size increases, researchers 58 | can become overconfident about their ability to predict new observations. 59 | Imagine that we sample data from two populations with the same mean, but 60 | different variability: 61 | 62 | ```{r} 63 | set.seed(1234) 64 | df <- expand.grid(v=c(1,3,3,3), i=1:1000) %>% 65 | as_data_frame %>% 66 | mutate(y = rnorm(length(.$i), 100, v)) %>% 67 | mutate(samp = factor(v, labels=c("Low variability", "High variability"))) 68 | ``` 69 | 70 | ```{r} 71 | df %>% 72 | ggplot(aes(y)) + 73 | geom_histogram() + 74 | facet_grid(~samp) + 75 | scale_color_discrete("") 76 | ``` 77 | 78 | - If we sample 100 individuals from each population the confidence interval 79 | around the sample mean would be wider in the high variability group. 80 | 81 | If we increase our sample size we would become more confident about the location 82 | of the mean, and this confidence interval would shrink. 83 | 84 | But imagine taking a single _new sample_ from either population. These samples 85 | would be new grey squares, which we place on the histograms above. It does not 86 | matter how much extra data we have collected in group B or how sure what the 87 | mean of the group is: _We would always be less certain making predictions for 88 | new observations in the high variability group_. 89 | 90 | The important insight here is that _if our data are noisy and highly variable we 91 | can never make firm predictions for new individuals, even if we collect so much 92 | data that we are very certain about the location of the mean_. 93 | 94 | 102 | -------------------------------------------------------------------------------- /crosstabulation.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Crosstabulation' 3 | --- 4 | 5 | ```{r, include=FALSE, message=F} 6 | library(tidyverse) 7 | library(pander) 8 | ``` 9 | 10 | ## Crosstabulations and $\chi^2$ {- #crosstabs} 11 | 12 | We saw in a previous section 13 | [how to create a frequency table of one or more variables](#frequency-tables). 14 | Using that previous example, assume we already have a crosstabulation of `age` 15 | and `prefers` 16 | 17 | ```{r, include=F} 18 | lego.duplo.df <- readRDS("data/lego.RDS") 19 | lego.table <- xtabs(~age+prefers, lego.duplo.df) 20 | lego.duplo.df %>% glimpse 21 | ``` 22 | 23 | ```{r} 24 | lego.table 25 | ``` 26 | 27 | We can easily run the inferential $\chi^2$ (sometimes spelled "chi", but 28 | pronounced "kai"-squared) test on this table: 29 | 30 | ```{r} 31 | lego.test <- chisq.test(lego.table) 32 | lego.test 33 | ``` 34 | 35 | Note that we can access each number in this output individually because the 36 | `chisq.test` function returns a list. We do this by using the `$` syntax: 37 | 38 | ```{r} 39 | # access the chi2 value alone 40 | lego.test$statistic 41 | ``` 42 | 43 | Even nicer, you can use an R package to write up your results for you in APA 44 | format! 45 | 46 | ```{r} 47 | library(apa) 48 | apa(lego.test, print_n=T) 49 | ``` 50 | 51 | [See more on automatically displaying statistics in APA format](#apa-output) 52 | 53 | ### Three-way tables {-} 54 | 55 | You can also use `table()` or `xtabs()` to get 3-way tables of frequencies 56 | (`xtabs` is probably better for this than `table`). 57 | 58 | For example, using the `mtcars` dataset we create a 3-way table, and then 59 | convert the result to a dataframe. This means we can print the table nicely in 60 | RMarkdown using the `pander.table()` function, or process it further (e.g. by 61 | [sorting](#sorting) or [reshaping](#reshaping) it). 62 | 63 | ```{r} 64 | xtabs(~am+gear+cyl, mtcars) %>% 65 | as_data_frame() %>% 66 | pander() 67 | ``` 68 | 69 | Often, you will want to present a table in a wider format than this, to aid 70 | comparisons between categories. For example, we might want our table to make it 71 | easy to compare between US and non-US cars for each different number of 72 | cylinders: 73 | 74 | ```{r} 75 | xtabs(~am+gear+cyl, mtcars) %>% 76 | as_data_frame() %>% 77 | reshape2::dcast(am+gear~paste(cyl, "Cylinders")) %>% 78 | pander() 79 | ``` 80 | 81 | Or our primary question might be related to the effect of `am`, in which case we 82 | might prefer to incude separate columns for US and non-US cars: 83 | 84 | ```{r} 85 | xtabs(~am+gear+cyl, mtcars) %>% 86 | as_data_frame() %>% 87 | reshape2::dcast(gear+cyl~paste0("US=", am)) %>% 88 | pander() 89 | ``` 90 | -------------------------------------------------------------------------------- /data/angry_moods.csv: -------------------------------------------------------------------------------- 1 | Gender,Sports,Anger.Out,Anger.In,Control.Out,Control.In,Anger.Expression 2,1,18,13,23,20,36 2,1,14,17,25,24,30 2,1,13,14,28,28,19 2,1,17,24,23,23,43 1,1,16,17,26,28,27 1,1,16,22,25,23,38 1,1,12,12,31,27,14 2,1,13,16,22,31,24 2,1,16,16,22,24,34 2,1,12,16,29,29,18 1,1,12,13,24,25,24 1,1,17,23,24,22,42 1,1,18,19,29,30,26 1,2,27,10,23,27,35 2,2,18,14,17,11,52 1,2,9,20,28,24,25 2,2,13,25,27,24,35 2,2,20,21,15,18,56 2,2,16,24,26,26,36 2,2,23,16,15,14,58 1,2,12,21,29,15,37 1,2,15,29,29,23,40 2,2,26,21,14,13,68 2,2,17,30,16,18,61 2,2,20,19,17,14,56 2,2,9,24,21,21,39 1,2,24,20,18,13,61 1,2,12,21,26,24,31 2,2,23,14,17,14,54 2,2,14,12,22,22,30 2,2,23,26,28,23,46 2,2,13,11,27,21,24 2,2,18,19,21,19,45 2,2,11,22,25,24,32 1,2,15,27,21,16,53 1,2,20,22,16,18,56 2,2,11,26,24,25,36 1,2,16,15,30,26,23 2,2,11,19,22,16,40 2,2,15,31,21,22,51 1,2,17,22,22,19,46 1,2,18,17,27,24,32 1,2,16,21,30,30,25 2,2,14,18,20,17,43 2,2,18,13,27,20,32 1,2,11,22,32,22,27 2,2,12,13,24,22,27 2,2,18,14,19,19,42 2,2,21,22,25,19,47 1,2,22,20,17,18,55 2,2,22,17,22,23,42 1,2,26,24,15,16,67 1,2,11,15,29,19,26 2,2,17,18,28,20,35 2,2,16,18,24,22,36 2,2,9,14,32,32,7 2,2,11,23,24,16,42 2,2,17,11,21,24,31 2,2,13,22,21,21,41 2,2,18,19,27,22,36 1,2,19,15,19,19,44 2,2,15,21,25,26,33 1,2,15,22,25,24,36 1,2,18,18,20,19,45 2,2,12,16,31,32,13 2,2,15,18,30,29,22 1,1,14,14,27,23,26 2,1,14,22,30,29,25 1,1,15,15,27,27,24 1,1,21,19,21,17,50 1,1,18,19,24,23,38 2,1,17,10,18,17,40 2,1,24,19,18,23,50 2,1,14,11,18,15,40 2,1,10,18,30,32,14 2,1,11,14,29,24,20 1,1,15,17,20,18,42 2,1,15,17,24,26,30 -------------------------------------------------------------------------------- /data/expt.data.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/expt.data.RDS -------------------------------------------------------------------------------- /data/eysenck.Rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/eysenck.Rdata -------------------------------------------------------------------------------- /data/fit-weight.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/fit-weight.RDS -------------------------------------------------------------------------------- /data/injury.Rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/injury.Rdata -------------------------------------------------------------------------------- /data/juice.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/juice.RDS -------------------------------------------------------------------------------- /data/lakers.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/lakers.RDS -------------------------------------------------------------------------------- /data/lego.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/lego.RDS -------------------------------------------------------------------------------- /data/miles-pre-1970.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/miles-pre-1970.RDS -------------------------------------------------------------------------------- /data/miles.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/miles.RDS -------------------------------------------------------------------------------- /data/miletimes.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/miletimes.csv -------------------------------------------------------------------------------- /data/multiple-file-example/person1.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","1",284.549120280828 3 | "1",2,"1","1",309.316219809743 4 | "1",3,"1","1",346.658837316501 5 | "1",4,"1","1",291.11815523507 6 | "1",5,"1","1",281.623973021888 7 | "1",6,"1","1",292.095211146545 8 | "1",7,"1","1",347.508268062996 9 | "1",8,"1","1",187.231919263222 10 | "1",9,"1","1",365.542492996453 11 | "1",10,"1","1",249.525479711639 12 | "1",11,"1","1",224.131978896655 13 | "1",12,"1","1",226.720785601964 14 | "1",13,"1","1",162.204013980242 15 | "1",14,"1","1",260.790359006402 16 | "1",15,"1","1",308.907829622758 17 | "1",16,"1","1",190.778786914881 18 | "1",17,"1","1",214.166717528862 19 | "1",18,"1","1",253.794685299854 20 | "1",19,"1","1",309.854724393453 21 | "1",20,"1","1",187.837145002723 22 | "1",21,"1","1",214.505757169806 23 | "1",22,"1","1",176.960428319916 24 | "1",23,"1","1",292.492459245337 25 | "1",24,"1","1",304.959211500581 26 | "1",25,"1","1",238.224534592432 27 | "1",1,"2","1",367.954234097015 28 | "1",2,"2","1",263.70505822682 29 | "1",3,"2","1",220.400971292781 30 | "1",4,"2","1",208.449692813161 31 | "1",5,"2","1",292.894576942568 32 | "1",6,"2","1",143.829757299379 33 | "1",7,"2","1",281.902718266236 34 | "1",8,"2","1",196.953439246073 35 | "1",9,"2","1",366.576300764774 36 | "1",10,"2","1",245.572941848144 37 | "1",11,"2","1",179.113087238506 38 | "1",12,"2","1",314.233859650023 39 | "1",13,"2","1",316.81258541281 40 | "1",14,"2","1",290.627510995146 41 | "1",15,"2","1",218.626473054653 42 | "1",16,"2","1",249.107123762662 43 | "1",17,"2","1",206.366884045679 44 | "1",18,"2","1",254.680371383883 45 | "1",19,"2","1",316.391534195088 46 | "1",20,"2","1",342.608757522599 47 | "1",21,"2","1",271.212814899593 48 | "1",22,"2","1",282.496487510144 49 | "1",23,"2","1",261.189523607628 50 | "1",24,"2","1",388.508060145048 51 | "1",25,"2","1",161.094934718812 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person10.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","10",297.342084181048 3 | "1",2,"1","10",299.005641250954 4 | "1",3,"1","10",166.491044851802 5 | "1",4,"1","10",218.418465995139 6 | "1",5,"1","10",239.770525948513 7 | "1",6,"1","10",314.359121932992 8 | "1",7,"1","10",183.152894028114 9 | "1",8,"1","10",265.826915162854 10 | "1",9,"1","10",281.696109224924 11 | "1",10,"1","10",202.560668094179 12 | "1",11,"1","10",184.118329890551 13 | "1",12,"1","10",229.7877184773 14 | "1",13,"1","10",226.873218598244 15 | "1",14,"1","10",213.619099161417 16 | "1",15,"1","10",254.149503818685 17 | "1",16,"1","10",327.126814603867 18 | "1",17,"1","10",183.344206169715 19 | "1",18,"1","10",250.907875656349 20 | "1",19,"1","10",278.850320892178 21 | "1",20,"1","10",313.024983952362 22 | "1",21,"1","10",267.175609136116 23 | "1",22,"1","10",314.338803957448 24 | "1",23,"1","10",247.6308691831 25 | "1",24,"1","10",376.336792453548 26 | "1",25,"1","10",225.684782564806 27 | "1",1,"2","10",216.35892152177 28 | "1",2,"2","10",280.681387431862 29 | "1",3,"2","10",230.324818441149 30 | "1",4,"2","10",222.634296890043 31 | "1",5,"2","10",263.787620259974 32 | "1",6,"2","10",197.59210665023 33 | "1",7,"2","10",288.890741759873 34 | "1",8,"2","10",433.786283145737 35 | "1",9,"2","10",283.915710876599 36 | "1",10,"2","10",275.910046564249 37 | "1",11,"2","10",291.890702062983 38 | "1",12,"2","10",280.387124998349 39 | "1",13,"2","10",297.518618822891 40 | "1",14,"2","10",359.305221577208 41 | "1",15,"2","10",173.497155975284 42 | "1",16,"2","10",226.964246724387 43 | "1",17,"2","10",317.640110041958 44 | "1",18,"2","10",198.518661639889 45 | "1",19,"2","10",199.038424558879 46 | "1",20,"2","10",261.029927003449 47 | "1",21,"2","10",286.725411493457 48 | "1",22,"2","10",371.362664054393 49 | "1",23,"2","10",181.909890240822 50 | "1",24,"2","10",261.776515233423 51 | "1",25,"2","10",362.904185292133 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person11.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","11",217.238318061348 3 | "1",2,"1","11",345.518883388574 4 | "1",3,"1","11",233.644940393827 5 | "1",4,"1","11",210.098583587179 6 | "1",5,"1","11",207.02635472074 7 | "1",6,"1","11",310.832707886023 8 | "1",7,"1","11",306.849761009479 9 | "1",8,"1","11",289.150709622639 10 | "1",9,"1","11",179.697584435218 11 | "1",10,"1","11",257.970736217827 12 | "1",11,"1","11",210.341225227504 13 | "1",12,"1","11",215.234779535865 14 | "1",13,"1","11",213.562834245251 15 | "1",14,"1","11",198.122938486115 16 | "1",15,"1","11",275.764739883439 17 | "1",16,"1","11",211.286923939052 18 | "1",17,"1","11",219.093596949474 19 | "1",18,"1","11",174.383560187063 20 | "1",19,"1","11",344.320082310582 21 | "1",20,"1","11",313.021786030562 22 | "1",21,"1","11",230.631444215038 23 | "1",22,"1","11",260.014863197241 24 | "1",23,"1","11",236.192042105568 25 | "1",24,"1","11",229.614544127868 26 | "1",25,"1","11",335.433302537323 27 | "1",1,"2","11",227.023594329718 28 | "1",2,"2","11",258.227854529083 29 | "1",3,"2","11",182.730118982031 30 | "1",4,"2","11",202.476827771733 31 | "1",5,"2","11",265.014220578276 32 | "1",6,"2","11",123.596637347862 33 | "1",7,"2","11",233.555305391691 34 | "1",8,"2","11",298.158901626048 35 | "1",9,"2","11",186.304858204371 36 | "1",10,"2","11",207.932731763152 37 | "1",11,"2","11",260.907979722835 38 | "1",12,"2","11",353.529801258925 39 | "1",13,"2","11",230.158338053123 40 | "1",14,"2","11",163.12448195066 41 | "1",15,"2","11",318.700893043249 42 | "1",16,"2","11",231.387534124915 43 | "1",17,"2","11",360.224944248847 44 | "1",18,"2","11",250.241359835263 45 | "1",19,"2","11",170.198922300822 46 | "1",20,"2","11",201.101908185918 47 | "1",21,"2","11",238.050362546958 48 | "1",22,"2","11",292.701014069945 49 | "1",23,"2","11",279.05673218863 50 | "1",24,"2","11",271.675322204673 51 | "1",25,"2","11",273.780709643035 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person12.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","12",232.232847168847 3 | "1",2,"1","12",230.442408590338 4 | "1",3,"1","12",319.748547125399 5 | "1",4,"1","12",348.0873504703 6 | "1",5,"1","12",231.61954523831 7 | "1",6,"1","12",274.374900087615 8 | "1",7,"1","12",230.516946742845 9 | "1",8,"1","12",195.337869835313 10 | "1",9,"1","12",276.44703325869 11 | "1",10,"1","12",217.080177931355 12 | "1",11,"1","12",303.220695727002 13 | "1",12,"1","12",257.623280462963 14 | "1",13,"1","12",242.012165272772 15 | "1",14,"1","12",216.415004495923 16 | "1",15,"1","12",239.711712175188 17 | "1",16,"1","12",202.612288272714 18 | "1",17,"1","12",310.996974037289 19 | "1",18,"1","12",269.424181006819 20 | "1",19,"1","12",233.246677516802 21 | "1",20,"1","12",300.403147543829 22 | "1",21,"1","12",225.548535480612 23 | "1",22,"1","12",355.823432097888 24 | "1",23,"1","12",283.894986726008 25 | "1",24,"1","12",229.02935373654 26 | "1",25,"1","12",197.26608173019 27 | "1",1,"2","12",265.170751190132 28 | "1",2,"2","12",292.426807013269 29 | "1",3,"2","12",263.816897525461 30 | "1",4,"2","12",291.484358899875 31 | "1",5,"2","12",293.153579676275 32 | "1",6,"2","12",233.061509696031 33 | "1",7,"2","12",300.412932489547 34 | "1",8,"2","12",237.026600594393 35 | "1",9,"2","12",236.047827836755 36 | "1",10,"2","12",234.94765145297 37 | "1",11,"2","12",158.584525563374 38 | "1",12,"2","12",202.574747846723 39 | "1",13,"2","12",319.453386268103 40 | "1",14,"2","12",207.293534983438 41 | "1",15,"2","12",238.098100388124 42 | "1",16,"2","12",379.888867404574 43 | "1",17,"2","12",288.631532347508 44 | "1",18,"2","12",263.537262185336 45 | "1",19,"2","12",355.530207788415 46 | "1",20,"2","12",268.21865847933 47 | "1",21,"2","12",263.182659994526 48 | "1",22,"2","12",180.830378001966 49 | "1",23,"2","12",302.013070545223 50 | "1",24,"2","12",221.494920157118 51 | "1",25,"2","12",325.932161701892 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person13.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","13",266.12467365352 3 | "2",2,"1","13",227.332778409916 4 | "2",3,"1","13",299.620600112782 5 | "2",4,"1","13",209.547638722858 6 | "2",5,"1","13",245.449745484183 7 | "2",6,"1","13",222.437612641931 8 | "2",7,"1","13",175.632939832541 9 | "2",8,"1","13",189.15101558253 10 | "2",9,"1","13",178.582926807746 11 | "2",10,"1","13",191.456933214593 12 | "2",11,"1","13",262.913079903959 13 | "2",12,"1","13",214.450750419067 14 | "2",13,"1","13",218.796418330303 15 | "2",14,"1","13",234.950645971728 16 | "2",15,"1","13",205.493874202608 17 | "2",16,"1","13",160.524477528974 18 | "2",17,"1","13",254.656780611946 19 | "2",18,"1","13",245.413800127691 20 | "2",19,"1","13",300.088627107645 21 | "2",20,"1","13",201.404113381148 22 | "2",21,"1","13",238.84576439337 23 | "2",22,"1","13",158.60506184801 24 | "2",23,"1","13",202.493526224654 25 | "2",24,"1","13",222.024704614893 26 | "2",25,"1","13",180.751133371337 27 | "2",1,"2","13",261.061848657194 28 | "2",2,"2","13",238.006986918265 29 | "2",3,"2","13",253.697308014667 30 | "2",4,"2","13",218.847286354305 31 | "2",5,"2","13",218.704019202021 32 | "2",6,"2","13",273.65125443858 33 | "2",7,"2","13",239.516666897174 34 | "2",8,"2","13",158.394531232957 35 | "2",9,"2","13",104.025984688251 36 | "2",10,"2","13",183.708656457015 37 | "2",11,"2","13",85.7028501799975 38 | "2",12,"2","13",113.559225547337 39 | "2",13,"2","13",209.27327191993 40 | "2",14,"2","13",191.611447679206 41 | "2",15,"2","13",217.068948409661 42 | "2",16,"2","13",155.285472444146 43 | "2",17,"2","13",121.624482791011 44 | "2",18,"2","13",192.227479160823 45 | "2",19,"2","13",158.551307428506 46 | "2",20,"2","13",283.844024655349 47 | "2",21,"2","13",283.472656135777 48 | "2",22,"2","13",256.431124563305 49 | "2",23,"2","13",433.591386295921 50 | "2",24,"2","13",186.801409094455 51 | "2",25,"2","13",87.956110561686 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person14.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","14",346.105394015849 3 | "2",2,"1","14",160.57013963244 4 | "2",3,"1","14",173.94446927479 5 | "2",4,"1","14",312.06787419573 6 | "2",5,"1","14",188.755746686018 7 | "2",6,"1","14",205.148604310729 8 | "2",7,"1","14",225.086979047063 9 | "2",8,"1","14",268.681243834141 10 | "2",9,"1","14",243.791631292573 11 | "2",10,"1","14",235.03541270866 12 | "2",11,"1","14",225.317210748139 13 | "2",12,"1","14",206.19909861376 14 | "2",13,"1","14",111.000230078135 15 | "2",14,"1","14",225.268703329226 16 | "2",15,"1","14",180.30235304351 17 | "2",16,"1","14",248.074766664251 18 | "2",17,"1","14",254.699735896885 19 | "2",18,"1","14",324.982042810275 20 | "2",19,"1","14",170.317214226174 21 | "2",20,"1","14",180.598613336107 22 | "2",21,"1","14",168.183090424131 23 | "2",22,"1","14",180.995380834204 24 | "2",23,"1","14",155.444107397369 25 | "2",24,"1","14",231.504735088879 26 | "2",25,"1","14",207.592903058505 27 | "2",1,"2","14",141.98090698221 28 | "2",2,"2","14",242.44894653932 29 | "2",3,"2","14",301.836374071398 30 | "2",4,"2","14",212.162803091711 31 | "2",5,"2","14",314.713006135041 32 | "2",6,"2","14",183.20682379085 33 | "2",7,"2","14",283.785104559513 34 | "2",8,"2","14",308.226573253143 35 | "2",9,"2","14",326.674167163761 36 | "2",10,"2","14",212.398628802225 37 | "2",11,"2","14",280.217690365734 38 | "2",12,"2","14",294.093814932194 39 | "2",13,"2","14",199.39514427286 40 | "2",14,"2","14",276.694388855089 41 | "2",15,"2","14",232.584768898727 42 | "2",16,"2","14",189.775623703056 43 | "2",17,"2","14",131.878881456859 44 | "2",18,"2","14",207.321672899857 45 | "2",19,"2","14",300.734984105347 46 | "2",20,"2","14",117.300320871145 47 | "2",21,"2","14",158.150096349938 48 | "2",22,"2","14",215.17475718892 49 | "2",23,"2","14",262.674939905433 50 | "2",24,"2","14",167.711721710634 51 | "2",25,"2","14",287.637537580595 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person15.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","15",278.408965717256 3 | "2",2,"1","15",280.343973900682 4 | "2",3,"1","15",279.823323186869 5 | "2",4,"1","15",223.014749588651 6 | "2",5,"1","15",278.385773619728 7 | "2",6,"1","15",232.053237255605 8 | "2",7,"1","15",229.780003033854 9 | "2",8,"1","15",260.40536102858 10 | "2",9,"1","15",187.839719277744 11 | "2",10,"1","15",197.080505614892 12 | "2",11,"1","15",254.241321275286 13 | "2",12,"1","15",172.1452822691 14 | "2",13,"1","15",181.435458510604 15 | "2",14,"1","15",243.83077726567 16 | "2",15,"1","15",207.603074974181 17 | "2",16,"1","15",234.92106921533 18 | "2",17,"1","15",153.875172969665 19 | "2",18,"1","15",234.554498972215 20 | "2",19,"1","15",178.511845134533 21 | "2",20,"1","15",166.32114816212 22 | "2",21,"1","15",191.299221185008 23 | "2",22,"1","15",240.691137545945 24 | "2",23,"1","15",223.850996427996 25 | "2",24,"1","15",200.803276852781 26 | "2",25,"1","15",269.346630998061 27 | "2",1,"2","15",118.605436886432 28 | "2",2,"2","15",232.797088556249 29 | "2",3,"2","15",129.116645491307 30 | "2",4,"2","15",225.615991057538 31 | "2",5,"2","15",119.784372495771 32 | "2",6,"2","15",166.41665415584 33 | "2",7,"2","15",346.622156154464 34 | "2",8,"2","15",216.630732834548 35 | "2",9,"2","15",284.319979813689 36 | "2",10,"2","15",180.056031556285 37 | "2",11,"2","15",260.065575868643 38 | "2",12,"2","15",159.439419582221 39 | "2",13,"2","15",266.071401192935 40 | "2",14,"2","15",184.377537669091 41 | "2",15,"2","15",249.749818325856 42 | "2",16,"2","15",139.628011466292 43 | "2",17,"2","15",212.171732169019 44 | "2",18,"2","15",258.859515349605 45 | "2",19,"2","15",85.0718401441193 46 | "2",20,"2","15",125.311175674285 47 | "2",21,"2","15",230.882400328737 48 | "2",22,"2","15",298.738245158097 49 | "2",23,"2","15",154.966555612414 50 | "2",24,"2","15",281.592898730196 51 | "2",25,"2","15",122.068708640405 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person16.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","16",180.123357120021 3 | "2",2,"1","16",231.290729185979 4 | "2",3,"1","16",262.277082810607 5 | "2",4,"1","16",193.109310305776 6 | "2",5,"1","16",279.615416608916 7 | "2",6,"1","16",304.816609915733 8 | "2",7,"1","16",232.368006671862 9 | "2",8,"1","16",169.999191783631 10 | "2",9,"1","16",209.155620399212 11 | "2",10,"1","16",218.68192012728 12 | "2",11,"1","16",150.037292964991 13 | "2",12,"1","16",168.947490597085 14 | "2",13,"1","16",277.014375129276 15 | "2",14,"1","16",141.833881053871 16 | "2",15,"1","16",216.333096117262 17 | "2",16,"1","16",230.057486504668 18 | "2",17,"1","16",169.494941390436 19 | "2",18,"1","16",269.754482040908 20 | "2",19,"1","16",236.676947839014 21 | "2",20,"1","16",173.369868201235 22 | "2",21,"1","16",207.359693587684 23 | "2",22,"1","16",148.822881036629 24 | "2",23,"1","16",271.140721506847 25 | "2",24,"1","16",189.73631287223 26 | "2",25,"1","16",211.985247439874 27 | "2",1,"2","16",178.728722912413 28 | "2",2,"2","16",252.595903856304 29 | "2",3,"2","16",206.80673048337 30 | "2",4,"2","16",313.721356507577 31 | "2",5,"2","16",319.208962300131 32 | "2",6,"2","16",253.032251634918 33 | "2",7,"2","16",194.233987098519 34 | "2",8,"2","16",339.230174311312 35 | "2",9,"2","16",272.438073668319 36 | "2",10,"2","16",313.867362226188 37 | "2",11,"2","16",177.571724025112 38 | "2",12,"2","16",153.569904372784 39 | "2",13,"2","16",97.1694980168532 40 | "2",14,"2","16",162.393496294314 41 | "2",15,"2","16",179.059717117141 42 | "2",16,"2","16",278.288723538471 43 | "2",17,"2","16",317.251100625346 44 | "2",18,"2","16",83.456821398536 45 | "2",19,"2","16",176.024693899153 46 | "2",20,"2","16",135.727598931529 47 | "2",21,"2","16",223.086915897798 48 | "2",22,"2","16",103.60168020001 49 | "2",23,"2","16",290.488989813653 50 | "2",24,"2","16",185.520604235782 51 | "2",25,"2","16",298.662186918785 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person17.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","17",307.196770942498 3 | "2",2,"1","17",270.055036374838 4 | "2",3,"1","17",147.325986785585 5 | "2",4,"1","17",187.213498448739 6 | "2",5,"1","17",191.18211782175 7 | "2",6,"1","17",173.825514163874 8 | "2",7,"1","17",298.82093565128 9 | "2",8,"1","17",216.434500866821 10 | "2",9,"1","17",213.596293983659 11 | "2",10,"1","17",203.132202156926 12 | "2",11,"1","17",173.021331259556 13 | "2",12,"1","17",175.626096954053 14 | "2",13,"1","17",244.224930468325 15 | "2",14,"1","17",207.340863880691 16 | "2",15,"1","17",320.077232512081 17 | "2",16,"1","17",299.309255175789 18 | "2",17,"1","17",258.240871366017 19 | "2",18,"1","17",147.915436440285 20 | "2",19,"1","17",220.423065181025 21 | "2",20,"1","17",237.803005162712 22 | "2",21,"1","17",209.223186839895 23 | "2",22,"1","17",280.957877870737 24 | "2",23,"1","17",372.081569625077 25 | "2",24,"1","17",197.488558470406 26 | "2",25,"1","17",237.004498576614 27 | "2",1,"2","17",207.949822194171 28 | "2",2,"2","17",208.44215509026 29 | "2",3,"2","17",185.886235043637 30 | "2",4,"2","17",306.415662117579 31 | "2",5,"2","17",147.074056834051 32 | "2",6,"2","17",258.811897597032 33 | "2",7,"2","17",53.7715221718504 34 | "2",8,"2","17",194.574435789407 35 | "2",9,"2","17",304.606078228323 36 | "2",10,"2","17",247.142589616098 37 | "2",11,"2","17",175.018028660283 38 | "2",12,"2","17",173.019962753769 39 | "2",13,"2","17",234.764567583691 40 | "2",14,"2","17",248.338157903158 41 | "2",15,"2","17",240.967042232093 42 | "2",16,"2","17",129.749916734608 43 | "2",17,"2","17",159.600629167955 44 | "2",18,"2","17",169.714753454489 45 | "2",19,"2","17",207.225840751097 46 | "2",20,"2","17",151.952745357081 47 | "2",21,"2","17",237.682612421587 48 | "2",22,"2","17",219.3305427289 49 | "2",23,"2","17",142.242519450332 50 | "2",24,"2","17",64.7219093055133 51 | "2",25,"2","17",90.3094108913561 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person18.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","18",224.004978899924 3 | "2",2,"1","18",224.472433945954 4 | "2",3,"1","18",252.124610730654 5 | "2",4,"1","18",269.202693384602 6 | "2",5,"1","18",212.229263960999 7 | "2",6,"1","18",198.070436357967 8 | "2",7,"1","18",219.76151159933 9 | "2",8,"1","18",244.907472469743 10 | "2",9,"1","18",227.558325428902 11 | "2",10,"1","18",263.702057309454 12 | "2",11,"1","18",248.498449168218 13 | "2",12,"1","18",249.587456682721 14 | "2",13,"1","18",381.061372202975 15 | "2",14,"1","18",178.279002287456 16 | "2",15,"1","18",165.209226188256 17 | "2",16,"1","18",283.871592680474 18 | "2",17,"1","18",190.568357329271 19 | "2",18,"1","18",180.766577728913 20 | "2",19,"1","18",177.381547721296 21 | "2",20,"1","18",205.123670778338 22 | "2",21,"1","18",176.401207051503 23 | "2",22,"1","18",255.41836410757 24 | "2",23,"1","18",202.623246676516 25 | "2",24,"1","18",263.952013547699 26 | "2",25,"1","18",162.222774531095 27 | "2",1,"2","18",162.225258696193 28 | "2",2,"2","18",208.103447229401 29 | "2",3,"2","18",140.147142206986 30 | "2",4,"2","18",175.211497608752 31 | "2",5,"2","18",150.997214451606 32 | "2",6,"2","18",243.613919690339 33 | "2",7,"2","18",141.432420632593 34 | "2",8,"2","18",180.273116728908 35 | "2",9,"2","18",263.484017297148 36 | "2",10,"2","18",163.05123297055 37 | "2",11,"2","18",170.092972361824 38 | "2",12,"2","18",128.924519676592 39 | "2",13,"2","18",253.478745052022 40 | "2",14,"2","18",42.6341913362477 41 | "2",15,"2","18",58.3063373890966 42 | "2",16,"2","18",50.7197532159666 43 | "2",17,"2","18",136.738730595319 44 | "2",18,"2","18",275.939199062194 45 | "2",19,"2","18",191.3890172558 46 | "2",20,"2","18",265.784625181278 47 | "2",21,"2","18",47.348604201129 48 | "2",22,"2","18",244.376040790982 49 | "2",23,"2","18",163.770994521359 50 | "2",24,"2","18",128.569773393057 51 | "2",25,"2","18",250.155135855749 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person19.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","19",191.996760137635 3 | "2",2,"1","19",178.515406327968 4 | "2",3,"1","19",173.592522277616 5 | "2",4,"1","19",270.149567171536 6 | "2",5,"1","19",167.489267764077 7 | "2",6,"1","19",200.261704477815 8 | "2",7,"1","19",196.622988224179 9 | "2",8,"1","19",241.580919216022 10 | "2",9,"1","19",173.214863145349 11 | "2",10,"1","19",290.780240800304 12 | "2",11,"1","19",212.199498578303 13 | "2",12,"1","19",163.453962300663 14 | "2",13,"1","19",167.273832838431 15 | "2",14,"1","19",311.621740708681 16 | "2",15,"1","19",250.229966265606 17 | "2",16,"1","19",219.868995483622 18 | "2",17,"1","19",263.936660869754 19 | "2",18,"1","19",340.211455310283 20 | "2",19,"1","19",224.304521876566 21 | "2",20,"1","19",222.538978779695 22 | "2",21,"1","19",177.747563525284 23 | "2",22,"1","19",228.187198478845 24 | "2",23,"1","19",318.745096079641 25 | "2",24,"1","19",172.573392232042 26 | "2",25,"1","19",199.256474319204 27 | "2",1,"2","19",158.466722281142 28 | "2",2,"2","19",196.117416458355 29 | "2",3,"2","19",158.985590269547 30 | "2",4,"2","19",141.553857071325 31 | "2",5,"2","19",237.478156577878 32 | "2",6,"2","19",182.232852219157 33 | "2",7,"2","19",149.91457100209 34 | "2",8,"2","19",190.017388963622 35 | "2",9,"2","19",118.757975682897 36 | "2",10,"2","19",310.820808258716 37 | "2",11,"2","19",214.583294237576 38 | "2",12,"2","19",220.655684310714 39 | "2",13,"2","19",171.166976881097 40 | "2",14,"2","19",131.711048077699 41 | "2",15,"2","19",268.801614548069 42 | "2",16,"2","19",190.67811907898 43 | "2",17,"2","19",183.332912104258 44 | "2",18,"2","19",172.173928059542 45 | "2",19,"2","19",106.599686736335 46 | "2",20,"2","19",192.211037115412 47 | "2",21,"2","19",282.580918434866 48 | "2",22,"2","19",163.840803398902 49 | "2",23,"2","19",87.6069272423842 50 | "2",24,"2","19",165.99989623739 51 | "2",25,"2","19",188.440066486715 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person2.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","2",235.018060224752 3 | "1",2,"1","2",258.619445672936 4 | "1",3,"1","2",263.062973113008 5 | "1",4,"1","2",242.291136749002 6 | "1",5,"1","2",332.494377756248 7 | "1",6,"1","2",288.976080101959 8 | "1",7,"1","2",393.381890255923 9 | "1",8,"1","2",219.685513491648 10 | "1",9,"1","2",257.76982135612 11 | "1",10,"1","2",238.249131809672 12 | "1",11,"1","2",288.335019783896 13 | "1",12,"1","2",267.695734209633 14 | "1",13,"1","2",282.265181116353 15 | "1",14,"1","2",212.647675031965 16 | "1",15,"1","2",341.092883339568 17 | "1",16,"1","2",257.40177977312 18 | "1",17,"1","2",326.543272961161 19 | "1",18,"1","2",221.842051334503 20 | "1",19,"1","2",319.315099698415 21 | "1",20,"1","2",342.251036433882 22 | "1",21,"1","2",262.999540124212 23 | "1",22,"1","2",238.893673913203 24 | "1",23,"1","2",305.933974274851 25 | "1",24,"1","2",248.012300539277 26 | "1",25,"1","2",333.196393707185 27 | "1",1,"2","2",246.747776525859 28 | "1",2,"2","2",240.801378997044 29 | "1",3,"2","2",302.406316441882 30 | "1",4,"2","2",281.225332430731 31 | "1",5,"2","2",304.061267739276 32 | "1",6,"2","2",301.185932792854 33 | "1",7,"2","2",225.198264155631 34 | "1",8,"2","2",296.601215402385 35 | "1",9,"2","2",223.147177906322 36 | "1",10,"2","2",199.011320941248 37 | "1",11,"2","2",219.204196182428 38 | "1",12,"2","2",258.330834690083 39 | "1",13,"2","2",218.600663871678 40 | "1",14,"2","2",314.731956530227 41 | "1",15,"2","2",246.938079616314 42 | "1",16,"2","2",183.395044902451 43 | "1",17,"2","2",221.699416251938 44 | "1",18,"2","2",244.662100199575 45 | "1",19,"2","2",242.949268225481 46 | "1",20,"2","2",255.720334140191 47 | "1",21,"2","2",468.249285866708 48 | "1",22,"2","2",286.963499592597 49 | "1",23,"2","2",356.877203600881 50 | "1",24,"2","2",319.626516930522 51 | "1",25,"2","2",216.901977510399 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person20.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","20",286.304427165928 3 | "2",2,"1","20",323.818685711476 4 | "2",3,"1","20",307.503340065726 5 | "2",4,"1","20",179.613987168791 6 | "2",5,"1","20",287.073424670404 7 | "2",6,"1","20",169.513373974282 8 | "2",7,"1","20",208.830746261356 9 | "2",8,"1","20",277.703581015991 10 | "2",9,"1","20",253.769570202731 11 | "2",10,"1","20",214.039123263699 12 | "2",11,"1","20",311.742169861905 13 | "2",12,"1","20",259.053712859894 14 | "2",13,"1","20",223.27531251724 15 | "2",14,"1","20",233.047222946045 16 | "2",15,"1","20",300.301737614988 17 | "2",16,"1","20",172.474979394692 18 | "2",17,"1","20",298.469452727099 19 | "2",18,"1","20",206.798026130583 20 | "2",19,"1","20",128.261615020805 21 | "2",20,"1","20",180.712566603399 22 | "2",21,"1","20",224.933906014663 23 | "2",22,"1","20",220.634846529309 24 | "2",23,"1","20",140.80348532241 25 | "2",24,"1","20",311.698160727381 26 | "2",25,"1","20",183.465548085064 27 | "2",1,"2","20",285.292427178602 28 | "2",2,"2","20",311.883117434972 29 | "2",3,"2","20",206.736265478244 30 | "2",4,"2","20",296.53891802106 31 | "2",5,"2","20",242.175537736979 32 | "2",6,"2","20",297.28088570957 33 | "2",7,"2","20",309.522005795188 34 | "2",8,"2","20",174.332299482974 35 | "2",9,"2","20",177.273500894285 36 | "2",10,"2","20",85.336284505699 37 | "2",11,"2","20",160.88222888566 38 | "2",12,"2","20",301.202536237974 39 | "2",13,"2","20",95.4997161172451 40 | "2",14,"2","20",174.438982859837 41 | "2",15,"2","20",213.728027332982 42 | "2",16,"2","20",56.188295267269 43 | "2",17,"2","20",244.733356058979 44 | "2",18,"2","20",116.446863387344 45 | "2",19,"2","20",116.460037824581 46 | "2",20,"2","20",162.762380930795 47 | "2",21,"2","20",213.687014387373 48 | "2",22,"2","20",292.403007104852 49 | "2",23,"2","20",256.107069459493 50 | "2",24,"2","20",383.770488969585 51 | "2",25,"2","20",228.848204814457 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person21.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","21",345.093494096644 3 | "2",2,"1","21",227.782168750639 4 | "2",3,"1","21",339.640172972347 5 | "2",4,"1","21",270.693984243521 6 | "2",5,"1","21",254.542029412541 7 | "2",6,"1","21",205.829479594019 8 | "2",7,"1","21",210.182571470954 9 | "2",8,"1","21",242.579521588784 10 | "2",9,"1","21",178.817709561862 11 | "2",10,"1","21",233.262890167353 12 | "2",11,"1","21",336.861362935977 13 | "2",12,"1","21",182.746263218998 14 | "2",13,"1","21",194.026341275476 15 | "2",14,"1","21",172.350567826687 16 | "2",15,"1","21",230.620647811297 17 | "2",16,"1","21",230.288977931204 18 | "2",17,"1","21",192.511154686349 19 | "2",18,"1","21",172.542165993916 20 | "2",19,"1","21",182.788297512054 21 | "2",20,"1","21",257.791742369147 22 | "2",21,"1","21",294.885336970187 23 | "2",22,"1","21",173.022683834895 24 | "2",23,"1","21",165.226894580194 25 | "2",24,"1","21",236.572342487348 26 | "2",25,"1","21",220.862066591615 27 | "2",1,"2","21",179.54076120545 28 | "2",2,"2","21",203.9744229172 29 | "2",3,"2","21",173.910171125314 30 | "2",4,"2","21",258.496235032272 31 | "2",5,"2","21",292.213279185789 32 | "2",6,"2","21",223.668391892526 33 | "2",7,"2","21",308.261002353033 34 | "2",8,"2","21",104.598395366253 35 | "2",9,"2","21",192.492244472234 36 | "2",10,"2","21",88.2792365490295 37 | "2",11,"2","21",290.237510692924 38 | "2",12,"2","21",123.274122086144 39 | "2",13,"2","21",182.281776342515 40 | "2",14,"2","21",246.006552058706 41 | "2",15,"2","21",280.05819321872 42 | "2",16,"2","21",223.89588239664 43 | "2",17,"2","21",88.5533254013397 44 | "2",18,"2","21",154.643016439766 45 | "2",19,"2","21",147.814717956821 46 | "2",20,"2","21",107.152662410749 47 | "2",21,"2","21",198.955309453445 48 | "2",22,"2","21",272.888513043884 49 | "2",23,"2","21",188.172979576888 50 | "2",24,"2","21",137.214594718271 51 | "2",25,"2","21",182.32961044504 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person22.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","22",229.525666262366 3 | "2",2,"1","22",206.64572527026 4 | "2",3,"1","22",220.29475609248 5 | "2",4,"1","22",195.273303545042 6 | "2",5,"1","22",341.277090585565 7 | "2",6,"1","22",273.91231497665 8 | "2",7,"1","22",180.302793644531 9 | "2",8,"1","22",208.958068915974 10 | "2",9,"1","22",233.174698590755 11 | "2",10,"1","22",218.070990712063 12 | "2",11,"1","22",216.136644924165 13 | "2",12,"1","22",188.040527522789 14 | "2",13,"1","22",221.619914871283 15 | "2",14,"1","22",208.308802159727 16 | "2",15,"1","22",261.493076905344 17 | "2",16,"1","22",167.958618330114 18 | "2",17,"1","22",188.026375980825 19 | "2",18,"1","22",315.039506972269 20 | "2",19,"1","22",246.639269474735 21 | "2",20,"1","22",210.203170383848 22 | "2",21,"1","22",229.268310769455 23 | "2",22,"1","22",200.030363305836 24 | "2",23,"1","22",355.86871532477 25 | "2",24,"1","22",229.006813295951 26 | "2",25,"1","22",150.00907348012 27 | "2",1,"2","22",148.962981680712 28 | "2",2,"2","22",248.079173608225 29 | "2",3,"2","22",157.135106975256 30 | "2",4,"2","22",162.260612563179 31 | "2",5,"2","22",132.665051647709 32 | "2",6,"2","22",265.016045534144 33 | "2",7,"2","22",201.912138404309 34 | "2",8,"2","22",120.097451024514 35 | "2",9,"2","22",274.449636533125 36 | "2",10,"2","22",158.879397529027 37 | "2",11,"2","22",178.666311844142 38 | "2",12,"2","22",214.984776651817 39 | "2",13,"2","22",203.270621075943 40 | "2",14,"2","22",153.567284993096 41 | "2",15,"2","22",197.278350639799 42 | "2",16,"2","22",195.853141058196 43 | "2",17,"2","22",200.033281257512 44 | "2",18,"2","22",384.14242553684 45 | "2",19,"2","22",213.541713986419 46 | "2",20,"2","22",251.389434999346 47 | "2",21,"2","22",146.266835197023 48 | "2",22,"2","22",281.484031913558 49 | "2",23,"2","22",235.771918469388 50 | "2",24,"2","22",276.80206832915 51 | "2",25,"2","22",126.062051535505 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person23.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","23",202.133105885493 3 | "2",2,"1","23",179.991039811705 4 | "2",3,"1","23",284.221731416329 5 | "2",4,"1","23",223.194185519211 6 | "2",5,"1","23",241.042259825884 7 | "2",6,"1","23",227.294768161821 8 | "2",7,"1","23",166.10008967812 9 | "2",8,"1","23",209.467098803774 10 | "2",9,"1","23",159.682599271953 11 | "2",10,"1","23",195.218519204945 12 | "2",11,"1","23",181.82048224823 13 | "2",12,"1","23",266.92483550136 14 | "2",13,"1","23",145.946193169925 15 | "2",14,"1","23",275.951883845416 16 | "2",15,"1","23",188.55006525304 17 | "2",16,"1","23",305.612887326914 18 | "2",17,"1","23",255.55088387856 19 | "2",18,"1","23",177.880440439852 20 | "2",19,"1","23",118.424013333409 21 | "2",20,"1","23",211.671116783043 22 | "2",21,"1","23",196.58245928299 23 | "2",22,"1","23",132.707430247144 24 | "2",23,"1","23",209.310543201777 25 | "2",24,"1","23",258.015061632395 26 | "2",25,"1","23",193.975961467905 27 | "2",1,"2","23",244.07360045112 28 | "2",2,"2","23",120.946702477542 29 | "2",3,"2","23",292.520448892244 30 | "2",4,"2","23",365.477299785592 31 | "2",5,"2","23",131.742720695891 32 | "2",6,"2","23",208.392050701776 33 | "2",7,"2","23",161.981289335851 34 | "2",8,"2","23",164.809627194889 35 | "2",9,"2","23",112.362325555833 36 | "2",10,"2","23",151.815730344128 37 | "2",11,"2","23",280.489698120397 38 | "2",12,"2","23",176.619615907219 39 | "2",13,"2","23",219.686803940335 40 | "2",14,"2","23",192.013147331017 41 | "2",15,"2","23",216.674693542227 42 | "2",16,"2","23",166.947014550808 43 | "2",17,"2","23",295.557732931525 44 | "2",18,"2","23",131.045038467921 45 | "2",19,"2","23",60.3490839705422 46 | "2",20,"2","23",203.505575907464 47 | "2",21,"2","23",175.456462983584 48 | "2",22,"2","23",2.24821787920051 49 | "2",23,"2","23",167.540297067857 50 | "2",24,"2","23",137.681524602877 51 | "2",25,"2","23",350.408400691071 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person24.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "2",1,"1","24",357.802458329969 3 | "2",2,"1","24",206.498717394507 4 | "2",3,"1","24",258.962800335398 5 | "2",4,"1","24",302.529747903883 6 | "2",5,"1","24",252.693199868859 7 | "2",6,"1","24",142.800889170371 8 | "2",7,"1","24",240.299569347464 9 | "2",8,"1","24",220.760460787082 10 | "2",9,"1","24",287.345472216769 11 | "2",10,"1","24",319.743939991233 12 | "2",11,"1","24",218.591229719815 13 | "2",12,"1","24",226.722596078687 14 | "2",13,"1","24",181.387027502451 15 | "2",14,"1","24",205.929469016284 16 | "2",15,"1","24",186.517739213855 17 | "2",16,"1","24",175.56298720404 18 | "2",17,"1","24",187.511960547183 19 | "2",18,"1","24",147.987996912631 20 | "2",19,"1","24",255.54648960798 21 | "2",20,"1","24",286.318307043983 22 | "2",21,"1","24",150.675846234793 23 | "2",22,"1","24",233.047536191295 24 | "2",23,"1","24",146.703563570004 25 | "2",24,"1","24",204.167713008629 26 | "2",25,"1","24",204.45483378373 27 | "2",1,"2","24",219.361511171202 28 | "2",2,"2","24",213.85687120892 29 | "2",3,"2","24",182.822357712885 30 | "2",4,"2","24",217.790145969424 31 | "2",5,"2","24",172.157565766067 32 | "2",6,"2","24",112.194897923223 33 | "2",7,"2","24",221.955716175324 34 | "2",8,"2","24",195.04887940396 35 | "2",9,"2","24",131.651505726808 36 | "2",10,"2","24",237.309066848558 37 | "2",11,"2","24",127.318030538635 38 | "2",12,"2","24",141.79377504227 39 | "2",13,"2","24",222.353304392211 40 | "2",14,"2","24",321.86069905416 41 | "2",15,"2","24",234.929579159973 42 | "2",16,"2","24",259.392267220134 43 | "2",17,"2","24",375.375410526308 44 | "2",18,"2","24",215.392734514615 45 | "2",19,"2","24",135.680911919112 46 | "2",20,"2","24",167.959365065727 47 | "2",21,"2","24",92.2046512816961 48 | "2",22,"2","24",236.295638001354 49 | "2",23,"2","24",142.659740276484 50 | "2",24,"2","24",83.8076271660566 51 | "2",25,"2","24",149.035974769967 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person25.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","25",271.016811966855 3 | "3",2,"1","25",280.561401738339 4 | "3",3,"1","25",239.524024917382 5 | "3",4,"1","25",317.851365218683 6 | "3",5,"1","25",225.5385563839 7 | "3",6,"1","25",268.102442908055 8 | "3",7,"1","25",319.242299873424 9 | "3",8,"1","25",254.485115892085 10 | "3",9,"1","25",228.397324646609 11 | "3",10,"1","25",282.509944252338 12 | "3",11,"1","25",241.087796306372 13 | "3",12,"1","25",225.654356132506 14 | "3",13,"1","25",225.274113794695 15 | "3",14,"1","25",254.957133924886 16 | "3",15,"1","25",226.023591576016 17 | "3",16,"1","25",325.29932262 18 | "3",17,"1","25",167.84608644371 19 | "3",18,"1","25",293.041887870691 20 | "3",19,"1","25",369.327380452281 21 | "3",20,"1","25",248.406571685064 22 | "3",21,"1","25",191.405513410231 23 | "3",22,"1","25",237.142154969763 24 | "3",23,"1","25",230.255418933125 25 | "3",24,"1","25",280.577082217063 26 | "3",25,"1","25",202.210844297067 27 | "3",1,"2","25",255.719571997829 28 | "3",2,"2","25",266.932076638347 29 | "3",3,"2","25",206.261815052064 30 | "3",4,"2","25",265.729993339126 31 | "3",5,"2","25",244.499778314743 32 | "3",6,"2","25",209.157761209042 33 | "3",7,"2","25",415.897957837379 34 | "3",8,"2","25",319.248999962762 35 | "3",9,"2","25",234.654922132804 36 | "3",10,"2","25",321.107108368883 37 | "3",11,"2","25",310.364744053449 38 | "3",12,"2","25",314.150825372597 39 | "3",13,"2","25",320.61986256669 40 | "3",14,"2","25",99.9747511917445 41 | "3",15,"2","25",309.517900207189 42 | "3",16,"2","25",351.0404517838 43 | "3",17,"2","25",332.948975289792 44 | "3",18,"2","25",346.427558182022 45 | "3",19,"2","25",237.143091534889 46 | "3",20,"2","25",314.586567081609 47 | "3",21,"2","25",454.00968459441 48 | "3",22,"2","25",290.420354936165 49 | "3",23,"2","25",108.077902381028 50 | "3",24,"2","25",361.219005302975 51 | "3",25,"2","25",438.106585831549 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person26.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","26",253.793183840868 3 | "3",2,"1","26",290.587757440026 4 | "3",3,"1","26",233.4348256087 5 | "3",4,"1","26",283.066644524865 6 | "3",5,"1","26",265.72521792114 7 | "3",6,"1","26",252.746078441496 8 | "3",7,"1","26",233.755348196773 9 | "3",8,"1","26",222.035119259231 10 | "3",9,"1","26",344.101845773963 11 | "3",10,"1","26",217.689017337929 12 | "3",11,"1","26",210.524982443079 13 | "3",12,"1","26",225.10742101136 14 | "3",13,"1","26",321.377551754456 15 | "3",14,"1","26",251.614892660818 16 | "3",15,"1","26",375.545406411261 17 | "3",16,"1","26",273.459042795981 18 | "3",17,"1","26",244.485728548208 19 | "3",18,"1","26",307.916634398007 20 | "3",19,"1","26",228.830089985723 21 | "3",20,"1","26",289.982119963851 22 | "3",21,"1","26",226.43107589467 23 | "3",22,"1","26",298.167741215762 24 | "3",23,"1","26",249.889295387823 25 | "3",24,"1","26",270.692752960762 26 | "3",25,"1","26",212.390170332144 27 | "3",1,"2","26",530.295913469914 28 | "3",2,"2","26",186.192006348934 29 | "3",3,"2","26",281.294126208341 30 | "3",4,"2","26",219.385173956445 31 | "3",5,"2","26",457.693509725611 32 | "3",6,"2","26",251.20881487247 33 | "3",7,"2","26",466.698580622057 34 | "3",8,"2","26",293.873584952185 35 | "3",9,"2","26",350.723541992593 36 | "3",10,"2","26",224.500473270025 37 | "3",11,"2","26",242.467783145313 38 | "3",12,"2","26",184.482351285425 39 | "3",13,"2","26",212.08397102643 40 | "3",14,"2","26",342.566698647852 41 | "3",15,"2","26",284.978177000653 42 | "3",16,"2","26",258.879801970071 43 | "3",17,"2","26",291.184139623308 44 | "3",18,"2","26",281.561805746454 45 | "3",19,"2","26",288.206288335477 46 | "3",20,"2","26",382.575318003688 47 | "3",21,"2","26",376.408926195302 48 | "3",22,"2","26",420.518917346926 49 | "3",23,"2","26",358.850049930643 50 | "3",24,"2","26",197.369159659649 51 | "3",25,"2","26",426.636863379865 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person27.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","27",321.516434342096 3 | "3",2,"1","27",268.164630825233 4 | "3",3,"1","27",263.12563962539 5 | "3",4,"1","27",318.250786464494 6 | "3",5,"1","27",203.492324178507 7 | "3",6,"1","27",295.745748872021 8 | "3",7,"1","27",303.251100603066 9 | "3",8,"1","27",275.941896950475 10 | "3",9,"1","27",274.898299368919 11 | "3",10,"1","27",215.386310039344 12 | "3",11,"1","27",262.205193040007 13 | "3",12,"1","27",303.145451227015 14 | "3",13,"1","27",181.983114547077 15 | "3",14,"1","27",221.69589464952 16 | "3",15,"1","27",267.059829306156 17 | "3",16,"1","27",315.553504211209 18 | "3",17,"1","27",205.043084705298 19 | "3",18,"1","27",247.504464513493 20 | "3",19,"1","27",291.187415390687 21 | "3",20,"1","27",313.278922593581 22 | "3",21,"1","27",200.038551916655 23 | "3",22,"1","27",339.457425342441 24 | "3",23,"1","27",338.04392668947 25 | "3",24,"1","27",196.012929728789 26 | "3",25,"1","27",254.508774225812 27 | "3",1,"2","27",253.678038572281 28 | "3",2,"2","27",336.095262131877 29 | "3",3,"2","27",318.057381236122 30 | "3",4,"2","27",343.841367931917 31 | "3",5,"2","27",504.700478829024 32 | "3",6,"2","27",344.496716760289 33 | "3",7,"2","27",275.599467646539 34 | "3",8,"2","27",307.704404433347 35 | "3",9,"2","27",286.775485062633 36 | "3",10,"2","27",289.97966290728 37 | "3",11,"2","27",304.873230599994 38 | "3",12,"2","27",352.727566625809 39 | "3",13,"2","27",282.7719777971 40 | "3",14,"2","27",170.286603178764 41 | "3",15,"2","27",198.469109399352 42 | "3",16,"2","27",310.163696696211 43 | "3",17,"2","27",377.909312509932 44 | "3",18,"2","27",193.29932179284 45 | "3",19,"2","27",224.876577813212 46 | "3",20,"2","27",279.901524482094 47 | "3",21,"2","27",267.967870469244 48 | "3",22,"2","27",270.490725153118 49 | "3",23,"2","27",427.155087004654 50 | "3",24,"2","27",281.204958114453 51 | "3",25,"2","27",541.157928979618 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person28.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","28",214.561164180243 3 | "3",2,"1","28",273.77230037799 4 | "3",3,"1","28",262.171609846368 5 | "3",4,"1","28",225.069236712782 6 | "3",5,"1","28",378.40697463765 7 | "3",6,"1","28",249.448362270225 8 | "3",7,"1","28",224.616566871703 9 | "3",8,"1","28",332.195974263018 10 | "3",9,"1","28",294.857482332856 11 | "3",10,"1","28",288.694479175525 12 | "3",11,"1","28",196.219576739846 13 | "3",12,"1","28",307.348743877303 14 | "3",13,"1","28",250.386064244445 15 | "3",14,"1","28",189.842391253944 16 | "3",15,"1","28",266.804145406414 17 | "3",16,"1","28",208.980984374757 18 | "3",17,"1","28",207.091807538874 19 | "3",18,"1","28",253.414122270399 20 | "3",19,"1","28",246.81769030292 21 | "3",20,"1","28",300.850121799009 22 | "3",21,"1","28",326.588170252328 23 | "3",22,"1","28",239.307793108221 24 | "3",23,"1","28",226.613772900477 25 | "3",24,"1","28",239.916356932834 26 | "3",25,"1","28",205.772188150742 27 | "3",1,"2","28",302.692802110867 28 | "3",2,"2","28",304.16623809187 29 | "3",3,"2","28",360.637984481794 30 | "3",4,"2","28",381.641116336572 31 | "3",5,"2","28",289.119580918567 32 | "3",6,"2","28",383.867630054612 33 | "3",7,"2","28",223.102556387361 34 | "3",8,"2","28",274.133357347588 35 | "3",9,"2","28",350.278109130558 36 | "3",10,"2","28",263.654104947746 37 | "3",11,"2","28",339.07648368794 38 | "3",12,"2","28",287.327818436955 39 | "3",13,"2","28",268.060265671847 40 | "3",14,"2","28",336.391547569933 41 | "3",15,"2","28",410.23111873656 42 | "3",16,"2","28",320.456209890364 43 | "3",17,"2","28",416.615940921737 44 | "3",18,"2","28",383.577409699666 45 | "3",19,"2","28",335.52450935443 46 | "3",20,"2","28",439.509704277306 47 | "3",21,"2","28",307.332747161357 48 | "3",22,"2","28",288.599748562589 49 | "3",23,"2","28",312.653576632017 50 | "3",24,"2","28",252.30878230409 51 | "3",25,"2","28",334.532593263611 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person29.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","29",295.864149106514 3 | "3",2,"1","29",248.976807354462 4 | "3",3,"1","29",194.769714106468 5 | "3",4,"1","29",346.669476279483 6 | "3",5,"1","29",370.138814078185 7 | "3",6,"1","29",257.773847675121 8 | "3",7,"1","29",266.754590367205 9 | "3",8,"1","29",197.870940051682 10 | "3",9,"1","29",215.275139990315 11 | "3",10,"1","29",195.202883595476 12 | "3",11,"1","29",302.848315412867 13 | "3",12,"1","29",220.572883295 14 | "3",13,"1","29",362.847926838961 15 | "3",14,"1","29",205.674690539937 16 | "3",15,"1","29",252.779567242261 17 | "3",16,"1","29",181.437182190273 18 | "3",17,"1","29",217.387061203858 19 | "3",18,"1","29",227.97841190016 20 | "3",19,"1","29",401.854338112641 21 | "3",20,"1","29",354.841919246003 22 | "3",21,"1","29",301.263935088828 23 | "3",22,"1","29",222.676181650777 24 | "3",23,"1","29",393.222761469293 25 | "3",24,"1","29",220.142247099914 26 | "3",25,"1","29",197.080154388461 27 | "3",1,"2","29",279.863830847447 28 | "3",2,"2","29",347.535632241607 29 | "3",3,"2","29",224.089765367309 30 | "3",4,"2","29",320.506686753305 31 | "3",5,"2","29",205.14526954288 32 | "3",6,"2","29",250.49468774373 33 | "3",7,"2","29",337.664208363066 34 | "3",8,"2","29",437.887623316398 35 | "3",9,"2","29",307.484844996759 36 | "3",10,"2","29",263.93889936294 37 | "3",11,"2","29",374.555196757541 38 | "3",12,"2","29",281.579737757356 39 | "3",13,"2","29",379.128138942092 40 | "3",14,"2","29",361.897820678006 41 | "3",15,"2","29",324.942247532254 42 | "3",16,"2","29",289.440569456994 43 | "3",17,"2","29",389.095573151177 44 | "3",18,"2","29",361.681720011474 45 | "3",19,"2","29",279.336440442443 46 | "3",20,"2","29",327.791517099692 47 | "3",21,"2","29",285.44774919137 48 | "3",22,"2","29",455.779424464316 49 | "3",23,"2","29",401.625671519248 50 | "3",24,"2","29",257.295224796374 51 | "3",25,"2","29",206.860575621404 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person3.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","3",358.930676479976 3 | "1",2,"1","3",246.375802733011 4 | "1",3,"1","3",183.879420397678 5 | "1",4,"1","3",288.864367754079 6 | "1",5,"1","3",190.7645776852 7 | "1",6,"1","3",236.50738171178 8 | "1",7,"1","3",265.656668255339 9 | "1",8,"1","3",277.99899460314 10 | "1",9,"1","3",286.840566398723 11 | "1",10,"1","3",241.52846756805 12 | "1",11,"1","3",233.322306192768 13 | "1",12,"1","3",301.082040966193 14 | "1",13,"1","3",243.31078398292 15 | "1",14,"1","3",305.220639216446 16 | "1",15,"1","3",240.965023705716 17 | "1",16,"1","3",274.413605400874 18 | "1",17,"1","3",349.939210562327 19 | "1",18,"1","3",212.705987329322 20 | "1",19,"1","3",282.958408448393 21 | "1",20,"1","3",210.526305500971 22 | "1",21,"1","3",189.763234262764 23 | "1",22,"1","3",179.427692710473 24 | "1",23,"1","3",216.097861887171 25 | "1",24,"1","3",336.057161372885 26 | "1",25,"1","3",206.263368454813 27 | "1",1,"2","3",326.386697325379 28 | "1",2,"2","3",371.544366584075 29 | "1",3,"2","3",173.191383407112 30 | "1",4,"2","3",243.758740874964 31 | "1",5,"2","3",135.673865155629 32 | "1",6,"2","3",234.129984433177 33 | "1",7,"2","3",304.626674105849 34 | "1",8,"2","3",129.456853993006 35 | "1",9,"2","3",338.728512768395 36 | "1",10,"2","3",162.28102840474 37 | "1",11,"2","3",325.150208905201 38 | "1",12,"2","3",191.174604181088 39 | "1",13,"2","3",240.836128753873 40 | "1",14,"2","3",258.264458663345 41 | "1",15,"2","3",312.904330927648 42 | "1",16,"2","3",290.58975964376 43 | "1",17,"2","3",152.113919123045 44 | "1",18,"2","3",359.224456957014 45 | "1",19,"2","3",312.473534322273 46 | "1",20,"2","3",335.663852676675 47 | "1",21,"2","3",184.747750849521 48 | "1",22,"2","3",96.8343498047365 49 | "1",23,"2","3",308.992847859251 50 | "1",24,"2","3",252.060974140703 51 | "1",25,"2","3",370.338570188192 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person30.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","30",267.997521547845 3 | "3",2,"1","30",219.084884359246 4 | "3",3,"1","30",275.949806778196 5 | "3",4,"1","30",248.386458890739 6 | "3",5,"1","30",226.298885806769 7 | "3",6,"1","30",257.021664277849 8 | "3",7,"1","30",181.137828180321 9 | "3",8,"1","30",275.527773268009 10 | "3",9,"1","30",233.873352386566 11 | "3",10,"1","30",257.537234193187 12 | "3",11,"1","30",212.432716216959 13 | "3",12,"1","30",260.442066133033 14 | "3",13,"1","30",251.534295336404 15 | "3",14,"1","30",292.488358042776 16 | "3",15,"1","30",335.416523628738 17 | "3",16,"1","30",199.570127191277 18 | "3",17,"1","30",254.545709118567 19 | "3",18,"1","30",232.054419945958 20 | "3",19,"1","30",284.143744421016 21 | "3",20,"1","30",239.532332290707 22 | "3",21,"1","30",281.154209991473 23 | "3",22,"1","30",213.98385330256 24 | "3",23,"1","30",235.700306615532 25 | "3",24,"1","30",194.615480897885 26 | "3",25,"1","30",276.978323958135 27 | "3",1,"2","30",445.757471679206 28 | "3",2,"2","30",212.384708958577 29 | "3",3,"2","30",263.998682043848 30 | "3",4,"2","30",302.88813877192 31 | "3",5,"2","30",321.458568907359 32 | "3",6,"2","30",239.898736675724 33 | "3",7,"2","30",267.865711947093 34 | "3",8,"2","30",346.516888177525 35 | "3",9,"2","30",153.058393880854 36 | "3",10,"2","30",271.399754472666 37 | "3",11,"2","30",326.67724390509 38 | "3",12,"2","30",254.551369082993 39 | "3",13,"2","30",206.888883401758 40 | "3",14,"2","30",310.681987914106 41 | "3",15,"2","30",206.212757989983 42 | "3",16,"2","30",370.804047830798 43 | "3",17,"2","30",305.706569559069 44 | "3",18,"2","30",270.798280175618 45 | "3",19,"2","30",244.640433771165 46 | "3",20,"2","30",304.972000617913 47 | "3",21,"2","30",317.66646407123 48 | "3",22,"2","30",268.265311230429 49 | "3",23,"2","30",319.448255725359 50 | "3",24,"2","30",228.503758541787 51 | "3",25,"2","30",336.849143657025 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person31.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","31",247.329073233259 3 | "3",2,"1","31",339.024754030917 4 | "3",3,"1","31",324.250155660837 5 | "3",4,"1","31",202.462626191224 6 | "3",5,"1","31",180.657882157432 7 | "3",6,"1","31",183.200007004119 8 | "3",7,"1","31",283.308032787159 9 | "3",8,"1","31",294.33194110352 10 | "3",9,"1","31",204.272016075083 11 | "3",10,"1","31",308.604716366725 12 | "3",11,"1","31",201.157057700658 13 | "3",12,"1","31",216.823702611341 14 | "3",13,"1","31",218.918674012724 15 | "3",14,"1","31",252.065565764829 16 | "3",15,"1","31",291.958235169967 17 | "3",16,"1","31",249.384741201123 18 | "3",17,"1","31",276.654155571983 19 | "3",18,"1","31",215.375832672086 20 | "3",19,"1","31",216.267614041703 21 | "3",20,"1","31",272.397011456882 22 | "3",21,"1","31",260.748978749675 23 | "3",22,"1","31",350.669744155595 24 | "3",23,"1","31",211.127888247755 25 | "3",24,"1","31",305.389649012306 26 | "3",25,"1","31",280.439887132323 27 | "3",1,"2","31",310.459681078809 28 | "3",2,"2","31",392.102924716642 29 | "3",3,"2","31",331.834274784573 30 | "3",4,"2","31",229.545488147861 31 | "3",5,"2","31",402.417554212237 32 | "3",6,"2","31",332.649944589521 33 | "3",7,"2","31",414.867822406626 34 | "3",8,"2","31",296.63087673238 35 | "3",9,"2","31",337.041807752818 36 | "3",10,"2","31",464.985936595261 37 | "3",11,"2","31",337.454435785968 38 | "3",12,"2","31",186.405382681729 39 | "3",13,"2","31",289.8615811921 40 | "3",14,"2","31",335.177502214628 41 | "3",15,"2","31",247.423180128697 42 | "3",16,"2","31",204.328008789417 43 | "3",17,"2","31",334.476644754191 44 | "3",18,"2","31",413.449934643171 45 | "3",19,"2","31",283.93005968319 46 | "3",20,"2","31",369.509227960396 47 | "3",21,"2","31",337.556322519985 48 | "3",22,"2","31",310.672535343181 49 | "3",23,"2","31",378.220861524743 50 | "3",24,"2","31",404.592456392308 51 | "3",25,"2","31",299.333161194145 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person32.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","32",237.443810654937 3 | "3",2,"1","32",266.830929819225 4 | "3",3,"1","32",227.792631030619 5 | "3",4,"1","32",176.727817273749 6 | "3",5,"1","32",225.028609479954 7 | "3",6,"1","32",307.302516893762 8 | "3",7,"1","32",203.634704100226 9 | "3",8,"1","32",212.101109848854 10 | "3",9,"1","32",226.007740009998 11 | "3",10,"1","32",282.164728694518 12 | "3",11,"1","32",199.836973336354 13 | "3",12,"1","32",227.994662452503 14 | "3",13,"1","32",222.36623948266 15 | "3",14,"1","32",342.744776176995 16 | "3",15,"1","32",277.655978973215 17 | "3",16,"1","32",224.923112967013 18 | "3",17,"1","32",363.277465688888 19 | "3",18,"1","32",241.520615044195 20 | "3",19,"1","32",256.374031867387 21 | "3",20,"1","32",312.125886350996 22 | "3",21,"1","32",258.486739746049 23 | "3",22,"1","32",179.286774774078 24 | "3",23,"1","32",327.13831492938 25 | "3",24,"1","32",198.014720676755 26 | "3",25,"1","32",260.967073407135 27 | "3",1,"2","32",376.082031314563 28 | "3",2,"2","32",220.356764957656 29 | "3",3,"2","32",334.591287189457 30 | "3",4,"2","32",344.259606359315 31 | "3",5,"2","32",281.403549967721 32 | "3",6,"2","32",298.709769179973 33 | "3",7,"2","32",278.384523041954 34 | "3",8,"2","32",412.9878081469 35 | "3",9,"2","32",386.519887160345 36 | "3",10,"2","32",334.002576130311 37 | "3",11,"2","32",381.76619646427 38 | "3",12,"2","32",232.012537104036 39 | "3",13,"2","32",295.862092117558 40 | "3",14,"2","32",350.867739925241 41 | "3",15,"2","32",184.320604957972 42 | "3",16,"2","32",309.89629564633 43 | "3",17,"2","32",340.540125464691 44 | "3",18,"2","32",333.892880434854 45 | "3",19,"2","32",262.308840514762 46 | "3",20,"2","32",282.462333408265 47 | "3",21,"2","32",374.23021447647 48 | "3",22,"2","32",239.72517601322 49 | "3",23,"2","32",250.190514873236 50 | "3",24,"2","32",267.875617278888 51 | "3",25,"2","32",349.06805246248 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person33.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","33",238.031025670804 3 | "3",2,"1","33",246.290193900588 4 | "3",3,"1","33",303.426667675689 5 | "3",4,"1","33",239.81074157591 6 | "3",5,"1","33",238.08341089759 7 | "3",6,"1","33",227.863368989757 8 | "3",7,"1","33",248.485134481294 9 | "3",8,"1","33",248.337532321008 10 | "3",9,"1","33",332.56111621629 11 | "3",10,"1","33",381.701595524555 12 | "3",11,"1","33",329.499717044588 13 | "3",12,"1","33",290.366080137583 14 | "3",13,"1","33",230.020585513749 15 | "3",14,"1","33",229.264519306715 16 | "3",15,"1","33",224.72564583546 17 | "3",16,"1","33",232.904764914284 18 | "3",17,"1","33",192.191808256757 19 | "3",18,"1","33",238.055939161395 20 | "3",19,"1","33",265.084937003076 21 | "3",20,"1","33",260.929827360996 22 | "3",21,"1","33",265.89734215853 23 | "3",22,"1","33",254.586656078175 24 | "3",23,"1","33",312.192898741777 25 | "3",24,"1","33",265.881283068287 26 | "3",25,"1","33",193.518477881002 27 | "3",1,"2","33",169.322239309234 28 | "3",2,"2","33",227.955094341783 29 | "3",3,"2","33",170.532911786089 30 | "3",4,"2","33",316.113208383264 31 | "3",5,"2","33",251.381532356652 32 | "3",6,"2","33",328.861058864545 33 | "3",7,"2","33",307.384024599649 34 | "3",8,"2","33",326.781224636142 35 | "3",9,"2","33",320.040278256713 36 | "3",10,"2","33",239.511036264178 37 | "3",11,"2","33",417.093131531046 38 | "3",12,"2","33",359.698108777725 39 | "3",13,"2","33",244.619120809795 40 | "3",14,"2","33",274.545470399496 41 | "3",15,"2","33",122.895738662928 42 | "3",16,"2","33",312.187537607393 43 | "3",17,"2","33",260.641599684133 44 | "3",18,"2","33",336.289632495393 45 | "3",19,"2","33",193.347433998655 46 | "3",20,"2","33",293.478712997178 47 | "3",21,"2","33",264.852170197514 48 | "3",22,"2","33",295.848203735571 49 | "3",23,"2","33",428.997428032969 50 | "3",24,"2","33",348.352830016927 51 | "3",25,"2","33",256.135185745057 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person34.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","34",266.661773398015 3 | "3",2,"1","34",212.868843555056 4 | "3",3,"1","34",264.945368379056 5 | "3",4,"1","34",251.24480934922 6 | "3",5,"1","34",278.477663943684 7 | "3",6,"1","34",192.774178500755 8 | "3",7,"1","34",272.133938630177 9 | "3",8,"1","34",232.355025464737 10 | "3",9,"1","34",239.015912176679 11 | "3",10,"1","34",280.551481600424 12 | "3",11,"1","34",201.398625677994 13 | "3",12,"1","34",304.839518773254 14 | "3",13,"1","34",313.664591392744 15 | "3",14,"1","34",322.519494466971 16 | "3",15,"1","34",263.140237033483 17 | "3",16,"1","34",268.884599263599 18 | "3",17,"1","34",190.124606585467 19 | "3",18,"1","34",228.616580858862 20 | "3",19,"1","34",186.904274420721 21 | "3",20,"1","34",239.731571055725 22 | "3",21,"1","34",260.314802299943 23 | "3",22,"1","34",271.802900796165 24 | "3",23,"1","34",200.609401201314 25 | "3",24,"1","34",298.476932964373 26 | "3",25,"1","34",347.528262552044 27 | "3",1,"2","34",270.987834110816 28 | "3",2,"2","34",313.979737651096 29 | "3",3,"2","34",299.754705708545 30 | "3",4,"2","34",358.309577135129 31 | "3",5,"2","34",392.696898214169 32 | "3",6,"2","34",365.830756164409 33 | "3",7,"2","34",363.635490515402 34 | "3",8,"2","34",272.189080459944 35 | "3",9,"2","34",236.186436334054 36 | "3",10,"2","34",315.282571244708 37 | "3",11,"2","34",307.233475854723 38 | "3",12,"2","34",230.009112819847 39 | "3",13,"2","34",416.147127605042 40 | "3",14,"2","34",248.085306355047 41 | "3",15,"2","34",302.304997508748 42 | "3",16,"2","34",354.17630921427 43 | "3",17,"2","34",313.156611352987 44 | "3",18,"2","34",155.000705120743 45 | "3",19,"2","34",268.096681789072 46 | "3",20,"2","34",215.011622503396 47 | "3",21,"2","34",306.554053019545 48 | "3",22,"2","34",311.19604271791 49 | "3",23,"2","34",332.745856208558 50 | "3",24,"2","34",238.910150950701 51 | "3",25,"2","34",262.535478705967 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person35.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","35",304.571598599711 3 | "3",2,"1","35",219.093181083752 4 | "3",3,"1","35",181.591353780618 5 | "3",4,"1","35",283.754093134742 6 | "3",5,"1","35",216.967101440822 7 | "3",6,"1","35",212.32690682769 8 | "3",7,"1","35",203.645399082554 9 | "3",8,"1","35",278.211063256112 10 | "3",9,"1","35",226.962616482048 11 | "3",10,"1","35",248.265872079015 12 | "3",11,"1","35",289.26481951227 13 | "3",12,"1","35",166.521614800982 14 | "3",13,"1","35",239.689777916911 15 | "3",14,"1","35",346.76956504548 16 | "3",15,"1","35",290.908233387522 17 | "3",16,"1","35",248.231460064668 18 | "3",17,"1","35",235.233396826071 19 | "3",18,"1","35",261.117696421766 20 | "3",19,"1","35",275.349075789992 21 | "3",20,"1","35",232.284922196042 22 | "3",21,"1","35",174.818383528881 23 | "3",22,"1","35",256.863412185442 24 | "3",23,"1","35",215.114955646341 25 | "3",24,"1","35",298.446237860659 26 | "3",25,"1","35",236.475460610642 27 | "3",1,"2","35",256.404259420869 28 | "3",2,"2","35",324.521725256481 29 | "3",3,"2","35",283.621381893857 30 | "3",4,"2","35",254.272140717147 31 | "3",5,"2","35",433.483449147966 32 | "3",6,"2","35",354.311328596187 33 | "3",7,"2","35",315.295270481947 34 | "3",8,"2","35",280.484364150135 35 | "3",9,"2","35",290.776782672279 36 | "3",10,"2","35",351.111876769806 37 | "3",11,"2","35",231.676235047995 38 | "3",12,"2","35",255.514825125213 39 | "3",13,"2","35",311.06426904158 40 | "3",14,"2","35",348.791077334921 41 | "3",15,"2","35",303.402628617073 42 | "3",16,"2","35",179.504594115143 43 | "3",17,"2","35",360.184438673666 44 | "3",18,"2","35",303.367152880202 45 | "3",19,"2","35",291.937869978023 46 | "3",20,"2","35",320.010117204441 47 | "3",21,"2","35",303.175528270312 48 | "3",22,"2","35",211.169129309514 49 | "3",23,"2","35",171.783138328835 50 | "3",24,"2","35",288.477272487173 51 | "3",25,"2","35",372.296860897942 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person36.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "3",1,"1","36",261.989884381931 3 | "3",2,"1","36",320.978703006326 4 | "3",3,"1","36",179.337728316952 5 | "3",4,"1","36",251.401760882041 6 | "3",5,"1","36",246.074432795726 7 | "3",6,"1","36",366.049456695103 8 | "3",7,"1","36",305.986661442462 9 | "3",8,"1","36",256.805330520279 10 | "3",9,"1","36",239.973169578654 11 | "3",10,"1","36",233.205662608716 12 | "3",11,"1","36",232.241181107104 13 | "3",12,"1","36",254.294001406235 14 | "3",13,"1","36",354.118827836219 15 | "3",14,"1","36",261.434232850987 16 | "3",15,"1","36",322.003334842849 17 | "3",16,"1","36",264.057558753376 18 | "3",17,"1","36",234.602972000305 19 | "3",18,"1","36",233.278380159618 20 | "3",19,"1","36",214.25858091507 21 | "3",20,"1","36",251.632460036796 22 | "3",21,"1","36",274.52884974623 23 | "3",22,"1","36",276.861703287809 24 | "3",23,"1","36",216.796293652833 25 | "3",24,"1","36",252.955149191745 26 | "3",25,"1","36",225.448491345019 27 | "3",1,"2","36",177.432326690419 28 | "3",2,"2","36",395.970731374814 29 | "3",3,"2","36",250.782477267963 30 | "3",4,"2","36",247.560374464673 31 | "3",5,"2","36",281.320082388021 32 | "3",6,"2","36",382.465945285776 33 | "3",7,"2","36",215.178529389227 34 | "3",8,"2","36",333.142910642312 35 | "3",9,"2","36",335.640126475403 36 | "3",10,"2","36",275.448505252642 37 | "3",11,"2","36",366.93541824619 38 | "3",12,"2","36",379.322048234986 39 | "3",13,"2","36",267.501290700073 40 | "3",14,"2","36",384.160089502622 41 | "3",15,"2","36",337.746171252098 42 | "3",16,"2","36",270.490157868926 43 | "3",17,"2","36",356.727084629915 44 | "3",18,"2","36",304.876655164549 45 | "3",19,"2","36",278.350021760674 46 | "3",20,"2","36",418.572503727445 47 | "3",21,"2","36",308.235201781899 48 | "3",22,"2","36",417.952972529856 49 | "3",23,"2","36",333.834933368891 50 | "3",24,"2","36",379.229728972925 51 | "3",25,"2","36",275.837052752297 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person37.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","37",202.077103725549 3 | "4",2,"1","37",218.683499884815 4 | "4",3,"1","37",241.470913090978 5 | "4",4,"1","37",159.512461790069 6 | "4",5,"1","37",196.50046151858 7 | "4",6,"1","37",200.50958416117 8 | "4",7,"1","37",202.141138375552 9 | "4",8,"1","37",300.266078565297 10 | "4",9,"1","37",241.450753151045 11 | "4",10,"1","37",210.750644107729 12 | "4",11,"1","37",261.966529509946 13 | "4",12,"1","37",164.755074228899 14 | "4",13,"1","37",209.592002630957 15 | "4",14,"1","37",297.015507963133 16 | "4",15,"1","37",188.668669520516 17 | "4",16,"1","37",123.762235191465 18 | "4",17,"1","37",185.153475493935 19 | "4",18,"1","37",161.756876633453 20 | "4",19,"1","37",186.470159490612 21 | "4",20,"1","37",213.627497711206 22 | "4",21,"1","37",231.451955611676 23 | "4",22,"1","37",164.545306028725 24 | "4",23,"1","37",179.570090798212 25 | "4",24,"1","37",226.550928809877 26 | "4",25,"1","37",132.226059699946 27 | "4",1,"2","37",360.962389108229 28 | "4",2,"2","37",254.771565214994 29 | "4",3,"2","37",289.698932106951 30 | "4",4,"2","37",329.472432265069 31 | "4",5,"2","37",362.243311275579 32 | "4",6,"2","37",234.860966950434 33 | "4",7,"2","37",237.408181186679 34 | "4",8,"2","37",228.432915179957 35 | "4",9,"2","37",175.53747960847 36 | "4",10,"2","37",170.364220715163 37 | "4",11,"2","37",258.733009316761 38 | "4",12,"2","37",322.667933405268 39 | "4",13,"2","37",227.101768573078 40 | "4",14,"2","37",190.293502932504 41 | "4",15,"2","37",231.316904738078 42 | "4",16,"2","37",276.620482916062 43 | "4",17,"2","37",272.325856079932 44 | "4",18,"2","37",317.90996824182 45 | "4",19,"2","37",134.855313551013 46 | "4",20,"2","37",324.733324093374 47 | "4",21,"2","37",197.639145697124 48 | "4",22,"2","37",197.317068080416 49 | "4",23,"2","37",127.588742496398 50 | "4",24,"2","37",171.919168802109 51 | "4",25,"2","37",47.5538754559249 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person38.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","38",237.672694788349 3 | "4",2,"1","38",308.584348359954 4 | "4",3,"1","38",238.003900943235 5 | "4",4,"1","38",256.03885351902 6 | "4",5,"1","38",194.830600497338 7 | "4",6,"1","38",169.677191095365 8 | "4",7,"1","38",280.360375474141 9 | "4",8,"1","38",206.657083566078 10 | "4",9,"1","38",155.603758926991 11 | "4",10,"1","38",204.162717518646 12 | "4",11,"1","38",160.564863428556 13 | "4",12,"1","38",227.826036794078 14 | "4",13,"1","38",200.781283419088 15 | "4",14,"1","38",125.542272748238 16 | "4",15,"1","38",160.889584678889 17 | "4",16,"1","38",225.435304259959 18 | "4",17,"1","38",167.789049424633 19 | "4",18,"1","38",215.857831914567 20 | "4",19,"1","38",272.301675746879 21 | "4",20,"1","38",207.353673919127 22 | "4",21,"1","38",212.871385051996 23 | "4",22,"1","38",302.67527601956 24 | "4",23,"1","38",161.07270125504 25 | "4",24,"1","38",208.601758242222 26 | "4",25,"1","38",182.113780374274 27 | "4",1,"2","38",171.640474590131 28 | "4",2,"2","38",313.592806282257 29 | "4",3,"2","38",426.205669605769 30 | "4",4,"2","38",215.849470967423 31 | "4",5,"2","38",388.905555808402 32 | "4",6,"2","38",265.423557312098 33 | "4",7,"2","38",227.60253946699 34 | "4",8,"2","38",168.596272271828 35 | "4",9,"2","38",210.08918222981 36 | "4",10,"2","38",189.842301356779 37 | "4",11,"2","38",185.219619718493 38 | "4",12,"2","38",170.737053853623 39 | "4",13,"2","38",173.454468722665 40 | "4",14,"2","38",332.12624109636 41 | "4",15,"2","38",121.507403055622 42 | "4",16,"2","38",109.417212446479 43 | "4",17,"2","38",265.184061741267 44 | "4",18,"2","38",255.573916887227 45 | "4",19,"2","38",165.974152868164 46 | "4",20,"2","38",291.017880069527 47 | "4",21,"2","38",278.644432094707 48 | "4",22,"2","38",325.20557385426 49 | "4",23,"2","38",129.23441634972 50 | "4",24,"2","38",163.172023859203 51 | "4",25,"2","38",95.9670278014896 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person39.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","39",263.908208774615 3 | "4",2,"1","39",274.760028414148 4 | "4",3,"1","39",205.78308024803 5 | "4",4,"1","39",206.653606467423 6 | "4",5,"1","39",295.459636431467 7 | "4",6,"1","39",259.207981024874 8 | "4",7,"1","39",190.257906745559 9 | "4",8,"1","39",241.630671381743 10 | "4",9,"1","39",255.340739623885 11 | "4",10,"1","39",255.45783084005 12 | "4",11,"1","39",197.475927047121 13 | "4",12,"1","39",215.780403974734 14 | "4",13,"1","39",253.712799947625 15 | "4",14,"1","39",280.795407351769 16 | "4",15,"1","39",302.304562342994 17 | "4",16,"1","39",188.071680762188 18 | "4",17,"1","39",152.061004346094 19 | "4",18,"1","39",223.123521850774 20 | "4",19,"1","39",207.19652891127 21 | "4",20,"1","39",225.018049401719 22 | "4",21,"1","39",132.723995132627 23 | "4",22,"1","39",163.698261378154 24 | "4",23,"1","39",215.773630525745 25 | "4",24,"1","39",114.20743435666 26 | "4",25,"1","39",248.047816843168 27 | "4",1,"2","39",284.252368493476 28 | "4",2,"2","39",214.745864956041 29 | "4",3,"2","39",284.343551576515 30 | "4",4,"2","39",218.816135419451 31 | "4",5,"2","39",263.266475040523 32 | "4",6,"2","39",343.404718392091 33 | "4",7,"2","39",137.018586453765 34 | "4",8,"2","39",133.915554392687 35 | "4",9,"2","39",253.812844207677 36 | "4",10,"2","39",144.510389224174 37 | "4",11,"2","39",182.406123868515 38 | "4",12,"2","39",218.870131910471 39 | "4",13,"2","39",110.262187743469 40 | "4",14,"2","39",208.640338481636 41 | "4",15,"2","39",303.006304919169 42 | "4",16,"2","39",111.032088107729 43 | "4",17,"2","39",197.78264503167 44 | "4",18,"2","39",108.996974788322 45 | "4",19,"2","39",220.562957128923 46 | "4",20,"2","39",255.599452763469 47 | "4",21,"2","39",222.71450028568 48 | "4",22,"2","39",252.282492823195 49 | "4",23,"2","39",320.249883766956 50 | "4",24,"2","39",263.512635922556 51 | "4",25,"2","39",254.000618657682 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person4.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","4",233.101625502046 3 | "1",2,"1","4",313.605784991566 4 | "1",3,"1","4",266.941102667933 5 | "1",4,"1","4",199.582361603366 6 | "1",5,"1","4",277.100447361718 7 | "1",6,"1","4",215.588652885937 8 | "1",7,"1","4",244.989588186218 9 | "1",8,"1","4",260.929774849777 10 | "1",9,"1","4",229.680951648628 11 | "1",10,"1","4",215.2804827023 12 | "1",11,"1","4",243.739066783639 13 | "1",12,"1","4",203.911476019547 14 | "1",13,"1","4",188.018087956272 15 | "1",14,"1","4",213.026287925857 16 | "1",15,"1","4",257.083193660889 17 | "1",16,"1","4",303.049758242383 18 | "1",17,"1","4",186.661955854934 19 | "1",18,"1","4",254.031064617332 20 | "1",19,"1","4",293.201478114005 21 | "1",20,"1","4",237.907071054273 22 | "1",21,"1","4",198.53947257643 23 | "1",22,"1","4",257.925901489647 24 | "1",23,"1","4",306.953275405668 25 | "1",24,"1","4",196.960414367429 26 | "1",25,"1","4",217.077444077403 27 | "1",1,"2","4",248.272715134654 28 | "1",2,"2","4",246.237700716775 29 | "1",3,"2","4",253.800371912257 30 | "1",4,"2","4",259.578672043635 31 | "1",5,"2","4",314.987458247554 32 | "1",6,"2","4",280.089335994491 33 | "1",7,"2","4",426.973380552367 34 | "1",8,"2","4",435.277318693487 35 | "1",9,"2","4",222.929027161036 36 | "1",10,"2","4",54.0248737896462 37 | "1",11,"2","4",280.638273568481 38 | "1",12,"2","4",298.073016433465 39 | "1",13,"2","4",326.926373509665 40 | "1",14,"2","4",252.076541982912 41 | "1",15,"2","4",322.189152117738 42 | "1",16,"2","4",215.390239065961 43 | "1",17,"2","4",252.044690751328 44 | "1",18,"2","4",196.641446282082 45 | "1",19,"2","4",298.037940160848 46 | "1",20,"2","4",271.307778901263 47 | "1",21,"2","4",256.426227624037 48 | "1",22,"2","4",244.428853956418 49 | "1",23,"2","4",281.944972375426 50 | "1",24,"2","4",264.629644422954 51 | "1",25,"2","4",223.997248140589 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person40.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","40",269.415264684996 3 | "4",2,"1","40",182.283079772674 4 | "4",3,"1","40",224.488706173799 5 | "4",4,"1","40",173.705300632245 6 | "4",5,"1","40",324.450371007285 7 | "4",6,"1","40",239.002105425196 8 | "4",7,"1","40",224.853644604724 9 | "4",8,"1","40",181.450500120406 10 | "4",9,"1","40",269.393355896294 11 | "4",10,"1","40",232.854785087229 12 | "4",11,"1","40",179.585978922147 13 | "4",12,"1","40",146.531473315132 14 | "4",13,"1","40",306.818448185045 15 | "4",14,"1","40",206.296898321718 16 | "4",15,"1","40",251.907127627123 17 | "4",16,"1","40",180.829899162013 18 | "4",17,"1","40",310.05470240318 19 | "4",18,"1","40",150.200188630968 20 | "4",19,"1","40",145.698993917546 21 | "4",20,"1","40",212.624858848137 22 | "4",21,"1","40",388.935316226944 23 | "4",22,"1","40",152.016195137671 24 | "4",23,"1","40",192.808795185686 25 | "4",24,"1","40",203.58490708043 26 | "4",25,"1","40",149.004865728782 27 | "4",1,"2","40",333.70355555368 28 | "4",2,"2","40",251.173897433244 29 | "4",3,"2","40",172.32541926777 30 | "4",4,"2","40",225.204456106651 31 | "4",5,"2","40",224.248798315496 32 | "4",6,"2","40",327.647960570494 33 | "4",7,"2","40",111.990828091093 34 | "4",8,"2","40",238.16410342765 35 | "4",9,"2","40",315.165837413875 36 | "4",10,"2","40",90.5740293805893 37 | "4",11,"2","40",204.035697995132 38 | "4",12,"2","40",216.828816270771 39 | "4",13,"2","40",233.817394021483 40 | "4",14,"2","40",312.017602442355 41 | "4",15,"2","40",109.047989106877 42 | "4",16,"2","40",160.592337822294 43 | "4",17,"2","40",302.48547843065 44 | "4",18,"2","40",174.941896898668 45 | "4",19,"2","40",162.76514682522 46 | "4",20,"2","40",106.101088503097 47 | "4",21,"2","40",226.659441656662 48 | "4",22,"2","40",252.232171949627 49 | "4",23,"2","40",170.879254568319 50 | "4",24,"2","40",139.540163414978 51 | "4",25,"2","40",191.377196726579 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person41.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","41",192.018756635577 3 | "4",2,"1","41",234.838150137171 4 | "4",3,"1","41",241.873584009991 5 | "4",4,"1","41",266.793687433679 6 | "4",5,"1","41",264.318820586796 7 | "4",6,"1","41",291.012112144532 8 | "4",7,"1","41",196.20540209747 9 | "4",8,"1","41",158.410806657075 10 | "4",9,"1","41",256.62513092188 11 | "4",10,"1","41",272.960539936597 12 | "4",11,"1","41",242.108561498703 13 | "4",12,"1","41",249.960194439937 14 | "4",13,"1","41",215.893383361617 15 | "4",14,"1","41",193.184504595261 16 | "4",15,"1","41",206.616506695065 17 | "4",16,"1","41",236.389693103963 18 | "4",17,"1","41",200.077207348813 19 | "4",18,"1","41",217.107110733589 20 | "4",19,"1","41",176.732872505941 21 | "4",20,"1","41",221.827654397865 22 | "4",21,"1","41",197.674147837954 23 | "4",22,"1","41",187.766070176897 24 | "4",23,"1","41",198.139370862734 25 | "4",24,"1","41",265.832913437903 26 | "4",25,"1","41",236.447632675419 27 | "4",1,"2","41",238.640845508857 28 | "4",2,"2","41",212.756310015325 29 | "4",3,"2","41",207.53351970362 30 | "4",4,"2","41",286.887249235042 31 | "4",5,"2","41",280.45240647366 32 | "4",6,"2","41",240.320816824859 33 | "4",7,"2","41",256.085538992361 34 | "4",8,"2","41",268.452855328846 35 | "4",9,"2","41",276.326629645077 36 | "4",10,"2","41",275.036386029022 37 | "4",11,"2","41",113.478118280208 38 | "4",12,"2","41",295.281750807562 39 | "4",13,"2","41",279.519315624295 40 | "4",14,"2","41",295.747814206039 41 | "4",15,"2","41",244.926716779306 42 | "4",16,"2","41",233.461034156822 43 | "4",17,"2","41",100.712931136261 44 | "4",18,"2","41",150.824208444149 45 | "4",19,"2","41",247.392704933116 46 | "4",20,"2","41",217.80756122055 47 | "4",21,"2","41",172.201102517424 48 | "4",22,"2","41",145.5813407863 49 | "4",23,"2","41",186.245178714192 50 | "4",24,"2","41",123.201562856277 51 | "4",25,"2","41",104.334252757468 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person42.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","42",248.114820389977 3 | "4",2,"1","42",267.356719526519 4 | "4",3,"1","42",127.490529881887 5 | "4",4,"1","42",264.39481244298 6 | "4",5,"1","42",303.658279171236 7 | "4",6,"1","42",255.161827238776 8 | "4",7,"1","42",205.260503181238 9 | "4",8,"1","42",149.078489203504 10 | "4",9,"1","42",282.146973877112 11 | "4",10,"1","42",198.961360495845 12 | "4",11,"1","42",159.965243100046 13 | "4",12,"1","42",281.422354760093 14 | "4",13,"1","42",197.068729830122 15 | "4",14,"1","42",264.24078773546 16 | "4",15,"1","42",184.690433072584 17 | "4",16,"1","42",188.928823564341 18 | "4",17,"1","42",206.476837514781 19 | "4",18,"1","42",236.594177798399 20 | "4",19,"1","42",275.536897514254 21 | "4",20,"1","42",188.754513381894 22 | "4",21,"1","42",200.589147469765 23 | "4",22,"1","42",346.792696467407 24 | "4",23,"1","42",227.432054973751 25 | "4",24,"1","42",153.517635113421 26 | "4",25,"1","42",141.76376942082 27 | "4",1,"2","42",349.229817671514 28 | "4",2,"2","42",360.289776224666 29 | "4",3,"2","42",238.560500870713 30 | "4",4,"2","42",285.031058587845 31 | "4",5,"2","42",326.874737348078 32 | "4",6,"2","42",338.627407093602 33 | "4",7,"2","42",277.226915554906 34 | "4",8,"2","42",276.690388229824 35 | "4",9,"2","42",180.57393262626 36 | "4",10,"2","42",336.348803883291 37 | "4",11,"2","42",244.779661307452 38 | "4",12,"2","42",237.455733403499 39 | "4",13,"2","42",220.38526455084 40 | "4",14,"2","42",252.659584340503 41 | "4",15,"2","42",74.5802950683913 42 | "4",16,"2","42",246.813270910524 43 | "4",17,"2","42",202.774853242073 44 | "4",18,"2","42",212.94060423233 45 | "4",19,"2","42",175.77723845259 46 | "4",20,"2","42",233.585047005097 47 | "4",21,"2","42",121.984849538664 48 | "4",22,"2","42",307.941252217956 49 | "4",23,"2","42",258.084093952368 50 | "4",24,"2","42",280.834744360197 51 | "4",25,"2","42",225.803733402914 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person43.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","43",250.416705245335 3 | "4",2,"1","43",310.808386022635 4 | "4",3,"1","43",217.409467197789 5 | "4",4,"1","43",262.799695091641 6 | "4",5,"1","43",204.920999802595 7 | "4",6,"1","43",267.690277071422 8 | "4",7,"1","43",154.084411160961 9 | "4",8,"1","43",188.845744057878 10 | "4",9,"1","43",227.906944153996 11 | "4",10,"1","43",165.630042978144 12 | "4",11,"1","43",170.533774695846 13 | "4",12,"1","43",217.646916108993 14 | "4",13,"1","43",189.964099427236 15 | "4",14,"1","43",228.445621932497 16 | "4",15,"1","43",239.664682803466 17 | "4",16,"1","43",267.997249518887 18 | "4",17,"1","43",172.246814292996 19 | "4",18,"1","43",206.889794847852 20 | "4",19,"1","43",281.711682092903 21 | "4",20,"1","43",239.784008090274 22 | "4",21,"1","43",159.167491538547 23 | "4",22,"1","43",182.03733298401 24 | "4",23,"1","43",199.383592037865 25 | "4",24,"1","43",170.170396152354 26 | "4",25,"1","43",240.048915402615 27 | "4",1,"2","43",225.089467026618 28 | "4",2,"2","43",204.132698769226 29 | "4",3,"2","43",280.863023834252 30 | "4",4,"2","43",187.704881279492 31 | "4",5,"2","43",233.018143012712 32 | "4",6,"2","43",287.702836874492 33 | "4",7,"2","43",303.443025544576 34 | "4",8,"2","43",318.147296764243 35 | "4",9,"2","43",316.864636075019 36 | "4",10,"2","43",300.679227646153 37 | "4",11,"2","43",103.81626833888 38 | "4",12,"2","43",206.421883020313 39 | "4",13,"2","43",280.508492787858 40 | "4",14,"2","43",345.996350559585 41 | "4",15,"2","43",265.329701566174 42 | "4",16,"2","43",151.564487405498 43 | "4",17,"2","43",145.559293170211 44 | "4",18,"2","43",298.628672594177 45 | "4",19,"2","43",236.279222240073 46 | "4",20,"2","43",244.284995263228 47 | "4",21,"2","43",297.036347177964 48 | "4",22,"2","43",91.4569995473776 49 | "4",23,"2","43",153.877755970239 50 | "4",24,"2","43",260.24402127598 51 | "4",25,"2","43",154.198618962782 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person44.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","44",247.635181423464 3 | "4",2,"1","44",306.373215588577 4 | "4",3,"1","44",172.014950413771 5 | "4",4,"1","44",293.125910252406 6 | "4",5,"1","44",170.213842917235 7 | "4",6,"1","44",229.906822348922 8 | "4",7,"1","44",257.592771948258 9 | "4",8,"1","44",227.860030523286 10 | "4",9,"1","44",217.470289721393 11 | "4",10,"1","44",197.538833017249 12 | "4",11,"1","44",277.468414819807 13 | "4",12,"1","44",251.356453323208 14 | "4",13,"1","44",174.917931605536 15 | "4",14,"1","44",246.304214790315 16 | "4",15,"1","44",239.225319396679 17 | "4",16,"1","44",184.041162933841 18 | "4",17,"1","44",164.072730455203 19 | "4",18,"1","44",194.932547367269 20 | "4",19,"1","44",188.918100738725 21 | "4",20,"1","44",165.976305158903 22 | "4",21,"1","44",167.224599668436 23 | "4",22,"1","44",244.438813704896 24 | "4",23,"1","44",163.696453505689 25 | "4",24,"1","44",194.665845479215 26 | "4",25,"1","44",154.041166997218 27 | "4",1,"2","44",219.086168499801 28 | "4",2,"2","44",244.882032440528 29 | "4",3,"2","44",271.131642334617 30 | "4",4,"2","44",125.119177255764 31 | "4",5,"2","44",222.506186329773 32 | "4",6,"2","44",238.703040692049 33 | "4",7,"2","44",146.77389759034 34 | "4",8,"2","44",220.446064672599 35 | "4",9,"2","44",182.074712269565 36 | "4",10,"2","44",180.97893115745 37 | "4",11,"2","44",179.739543494412 38 | "4",12,"2","44",227.531810765264 39 | "4",13,"2","44",212.556036400509 40 | "4",14,"2","44",224.276249292024 41 | "4",15,"2","44",305.410296371734 42 | "4",16,"2","44",88.4081478512214 43 | "4",17,"2","44",219.82045287456 44 | "4",18,"2","44",131.021804861013 45 | "4",19,"2","44",94.2777314554781 46 | "4",20,"2","44",297.559328981216 47 | "4",21,"2","44",190.783508001737 48 | "4",22,"2","44",314.785198393478 49 | "4",23,"2","44",223.311501645991 50 | "4",24,"2","44",180.008709365425 51 | "4",25,"2","44",356.234271164629 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person45.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","45",236.385553119532 3 | "4",2,"1","45",189.834196721988 4 | "4",3,"1","45",205.324316145515 5 | "4",4,"1","45",172.297239904641 6 | "4",5,"1","45",145.499017602412 7 | "4",6,"1","45",219.044606475682 8 | "4",7,"1","45",229.830458399346 9 | "4",8,"1","45",215.903234471679 10 | "4",9,"1","45",312.815177225567 11 | "4",10,"1","45",323.848358555748 12 | "4",11,"1","45",197.321356994607 13 | "4",12,"1","45",205.479537179322 14 | "4",13,"1","45",256.406844821689 15 | "4",14,"1","45",220.092755131792 16 | "4",15,"1","45",246.328566787444 17 | "4",16,"1","45",151.093434092947 18 | "4",17,"1","45",263.937949915846 19 | "4",18,"1","45",306.450411706277 20 | "4",19,"1","45",196.729939079823 21 | "4",20,"1","45",210.097190221016 22 | "4",21,"1","45",152.478855738524 23 | "4",22,"1","45",277.10511995807 24 | "4",23,"1","45",187.396258291139 25 | "4",24,"1","45",253.61411365928 26 | "4",25,"1","45",194.155568516504 27 | "4",1,"2","45",271.737134017464 28 | "4",2,"2","45",261.476050747011 29 | "4",3,"2","45",169.287750439921 30 | "4",4,"2","45",248.535121021354 31 | "4",5,"2","45",250.722231375823 32 | "4",6,"2","45",174.923055508898 33 | "4",7,"2","45",219.725463939594 34 | "4",8,"2","45",190.901676623159 35 | "4",9,"2","45",210.666810835102 36 | "4",10,"2","45",197.508269100679 37 | "4",11,"2","45",242.614214883666 38 | "4",12,"2","45",130.716296161488 39 | "4",13,"2","45",109.17041910422 40 | "4",14,"2","45",157.070105555332 41 | "4",15,"2","45",148.089996571332 42 | "4",16,"2","45",117.842299470582 43 | "4",17,"2","45",79.1260491764618 44 | "4",18,"2","45",211.770761452961 45 | "4",19,"2","45",233.628869288456 46 | "4",20,"2","45",196.157891156168 47 | "4",21,"2","45",260.046953986094 48 | "4",22,"2","45",240.928393061015 49 | "4",23,"2","45",109.811434594418 50 | "4",24,"2","45",167.03153958578 51 | "4",25,"2","45",108.705333314627 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person46.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","46",147.51749125236 3 | "4",2,"1","46",203.407499808177 4 | "4",3,"1","46",356.383338346633 5 | "4",4,"1","46",182.504122335786 6 | "4",5,"1","46",200.101712069002 7 | "4",6,"1","46",276.617136666294 8 | "4",7,"1","46",201.514406698403 9 | "4",8,"1","46",252.242469709695 10 | "4",9,"1","46",204.760524568894 11 | "4",10,"1","46",223.656184213118 12 | "4",11,"1","46",205.660716410302 13 | "4",12,"1","46",168.666966227592 14 | "4",13,"1","46",252.187742800075 15 | "4",14,"1","46",308.067984135999 16 | "4",15,"1","46",170.46927804665 17 | "4",16,"1","46",169.777824534358 18 | "4",17,"1","46",199.284841146722 19 | "4",18,"1","46",153.257012739902 20 | "4",19,"1","46",190.04921526508 21 | "4",20,"1","46",275.503184964469 22 | "4",21,"1","46",339.029001428307 23 | "4",22,"1","46",199.92175831826 24 | "4",23,"1","46",191.236689209337 25 | "4",24,"1","46",138.872777272552 26 | "4",25,"1","46",377.557332754553 27 | "4",1,"2","46",215.424052406389 28 | "4",2,"2","46",277.912527509959 29 | "4",3,"2","46",303.131105359881 30 | "4",4,"2","46",282.299486494292 31 | "4",5,"2","46",212.337774328125 32 | "4",6,"2","46",329.233470383089 33 | "4",7,"2","46",276.123608963303 34 | "4",8,"2","46",236.439631255595 35 | "4",9,"2","46",238.232630686646 36 | "4",10,"2","46",308.306833184404 37 | "4",11,"2","46",175.075143111293 38 | "4",12,"2","46",291.30140453654 39 | "4",13,"2","46",184.026700182873 40 | "4",14,"2","46",278.541231805024 41 | "4",15,"2","46",232.425929974637 42 | "4",16,"2","46",143.890525858592 43 | "4",17,"2","46",246.432473319033 44 | "4",18,"2","46",316.756287417951 45 | "4",19,"2","46",117.620875858773 46 | "4",20,"2","46",230.462014052904 47 | "4",21,"2","46",153.414054288181 48 | "4",22,"2","46",70.8025959874627 49 | "4",23,"2","46",133.563572164857 50 | "4",24,"2","46",203.54644790463 51 | "4",25,"2","46",180.884770559227 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person47.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","47",270.207705134023 3 | "4",2,"1","47",341.105509821818 4 | "4",3,"1","47",281.125536877443 5 | "4",4,"1","47",217.426986090955 6 | "4",5,"1","47",213.223815458214 7 | "4",6,"1","47",316.471747787824 8 | "4",7,"1","47",171.908060908749 9 | "4",8,"1","47",205.145008553359 10 | "4",9,"1","47",278.891596063298 11 | "4",10,"1","47",270.407146007303 12 | "4",11,"1","47",226.818692537539 13 | "4",12,"1","47",164.100373155159 14 | "4",13,"1","47",188.506344871455 15 | "4",14,"1","47",216.917208091615 16 | "4",15,"1","47",269.241421126745 17 | "4",16,"1","47",153.842228656305 18 | "4",17,"1","47",178.912686925618 19 | "4",18,"1","47",233.301008035277 20 | "4",19,"1","47",196.349474814802 21 | "4",20,"1","47",227.101844518109 22 | "4",21,"1","47",216.794576897994 23 | "4",22,"1","47",202.555084211975 24 | "4",23,"1","47",269.535860375809 25 | "4",24,"1","47",240.610465738187 26 | "4",25,"1","47",200.826923264413 27 | "4",1,"2","47",195.947572325975 28 | "4",2,"2","47",240.44086245755 29 | "4",3,"2","47",244.380377320012 30 | "4",4,"2","47",352.975084720146 31 | "4",5,"2","47",218.371625565098 32 | "4",6,"2","47",236.661002786658 33 | "4",7,"2","47",234.549576952998 34 | "4",8,"2","47",263.028232031082 35 | "4",9,"2","47",276.050126292828 36 | "4",10,"2","47",278.527091566964 37 | "4",11,"2","47",297.866918491582 38 | "4",12,"2","47",196.568071730626 39 | "4",13,"2","47",170.774012668748 40 | "4",14,"2","47",211.994587252706 41 | "4",15,"2","47",187.105993608938 42 | "4",16,"2","47",206.617938967342 43 | "4",17,"2","47",162.935062328045 44 | "4",18,"2","47",269.387580170405 45 | "4",19,"2","47",172.482525088959 46 | "4",20,"2","47",289.37550418111 47 | "4",21,"2","47",266.491262655936 48 | "4",22,"2","47",249.022414734777 49 | "4",23,"2","47",173.992127168497 50 | "4",24,"2","47",237.111716597198 51 | "4",25,"2","47",343.585962359776 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person48.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "4",1,"1","48",236.390710464051 3 | "4",2,"1","48",322.066812657918 4 | "4",3,"1","48",238.651581515619 5 | "4",4,"1","48",201.390024185555 6 | "4",5,"1","48",228.598263213686 7 | "4",6,"1","48",230.732811172823 8 | "4",7,"1","48",294.706824503836 9 | "4",8,"1","48",181.067631361384 10 | "4",9,"1","48",241.513160789176 11 | "4",10,"1","48",189.973394236623 12 | "4",11,"1","48",209.136292168273 13 | "4",12,"1","48",193.775705456812 14 | "4",13,"1","48",212.772780532786 15 | "4",14,"1","48",172.996155970019 16 | "4",15,"1","48",173.119167034975 17 | "4",16,"1","48",172.707399113425 18 | "4",17,"1","48",265.780224327931 19 | "4",18,"1","48",219.960737309761 20 | "4",19,"1","48",149.527125737771 21 | "4",20,"1","48",244.046279904783 22 | "4",21,"1","48",201.132039820653 23 | "4",22,"1","48",168.078484712844 24 | "4",23,"1","48",141.279579448694 25 | "4",24,"1","48",246.894224649226 26 | "4",25,"1","48",199.096235488443 27 | "4",1,"2","48",266.283070035458 28 | "4",2,"2","48",152.144296790212 29 | "4",3,"2","48",254.358885998909 30 | "4",4,"2","48",219.33363599398 31 | "4",5,"2","48",411.784366113988 32 | "4",6,"2","48",273.530963668547 33 | "4",7,"2","48",167.535524550571 34 | "4",8,"2","48",272.747914829874 35 | "4",9,"2","48",205.891275876119 36 | "4",10,"2","48",311.63823775972 37 | "4",11,"2","48",355.751342014104 38 | "4",12,"2","48",147.947867557136 39 | "4",13,"2","48",167.291811135351 40 | "4",14,"2","48",188.859412558488 41 | "4",15,"2","48",176.745678265299 42 | "4",16,"2","48",277.545719449995 43 | "4",17,"2","48",157.248610202731 44 | "4",18,"2","48",129.256215510958 45 | "4",19,"2","48",190.637127812463 46 | "4",20,"2","48",286.706876227077 47 | "4",21,"2","48",188.051445763109 48 | "4",22,"2","48",175.460786282016 49 | "4",23,"2","48",205.742760987521 50 | "4",24,"2","48",116.4397468363 51 | "4",25,"2","48",158.741156412166 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person5.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","5",240.795083468961 3 | "1",2,"1","5",345.05208048587 4 | "1",3,"1","5",236.932137557478 5 | "1",4,"1","5",303.406319079865 6 | "1",5,"1","5",187.897076074243 7 | "1",6,"1","5",253.393054437353 8 | "1",7,"1","5",258.526938167344 9 | "1",8,"1","5",229.173716726813 10 | "1",9,"1","5",274.029142109428 11 | "1",10,"1","5",311.830173847219 12 | "1",11,"1","5",293.126934750396 13 | "1",12,"1","5",206.112624810534 14 | "1",13,"1","5",203.550968325087 15 | "1",14,"1","5",269.67151980006 16 | "1",15,"1","5",271.801772876828 17 | "1",16,"1","5",205.045559477734 18 | "1",17,"1","5",284.004069271161 19 | "1",18,"1","5",212.404440774361 20 | "1",19,"1","5",242.296865687918 21 | "1",20,"1","5",219.825433678677 22 | "1",21,"1","5",280.737260182039 23 | "1",22,"1","5",219.478114761281 24 | "1",23,"1","5",256.142813625419 25 | "1",24,"1","5",237.203839006883 26 | "1",25,"1","5",274.815055495302 27 | "1",1,"2","5",287.388433925121 28 | "1",2,"2","5",388.859728954902 29 | "1",3,"2","5",313.408788042801 30 | "1",4,"2","5",335.401999323732 31 | "1",5,"2","5",317.469763890609 32 | "1",6,"2","5",262.237495823054 33 | "1",7,"2","5",163.856127299867 34 | "1",8,"2","5",358.006025577143 35 | "1",9,"2","5",172.556736242427 36 | "1",10,"2","5",265.81419711114 37 | "1",11,"2","5",173.922989715414 38 | "1",12,"2","5",184.724102783779 39 | "1",13,"2","5",175.68036350559 40 | "1",14,"2","5",233.381168976151 41 | "1",15,"2","5",219.953017897351 42 | "1",16,"2","5",271.929780510144 43 | "1",17,"2","5",227.243509150916 44 | "1",18,"2","5",320.800658439682 45 | "1",19,"2","5",287.341784758665 46 | "1",20,"2","5",295.309247361691 47 | "1",21,"2","5",399.513988772764 48 | "1",22,"2","5",238.567699024868 49 | "1",23,"2","5",211.929027872049 50 | "1",24,"2","5",418.418152829534 51 | "1",25,"2","5",214.089468504698 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person6.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","6",321.014144015514 3 | "1",2,"1","6",266.516518108384 4 | "1",3,"1","6",253.49644875835 5 | "1",4,"1","6",351.483720948366 6 | "1",5,"1","6",163.353498450432 7 | "1",6,"1","6",287.453989279934 8 | "1",7,"1","6",259.800552701312 9 | "1",8,"1","6",289.625128503399 10 | "1",9,"1","6",190.501546910729 11 | "1",10,"1","6",280.860322433077 12 | "1",11,"1","6",235.046684999277 13 | "1",12,"1","6",304.222227782984 14 | "1",13,"1","6",385.375037038042 15 | "1",14,"1","6",212.461435806361 16 | "1",15,"1","6",192.144213351498 17 | "1",16,"1","6",239.708069474543 18 | "1",17,"1","6",201.732384719478 19 | "1",18,"1","6",320.022716774871 20 | "1",19,"1","6",208.537007591195 21 | "1",20,"1","6",304.923080448858 22 | "1",21,"1","6",365.272071870161 23 | "1",22,"1","6",191.792434893371 24 | "1",23,"1","6",184.880692954508 25 | "1",24,"1","6",294.33501917092 26 | "1",25,"1","6",344.953881916054 27 | "1",1,"2","6",213.407534837425 28 | "1",2,"2","6",247.817742974858 29 | "1",3,"2","6",233.792555310537 30 | "1",4,"2","6",190.390710497625 31 | "1",5,"2","6",223.252354084716 32 | "1",6,"2","6",277.741131515563 33 | "1",7,"2","6",179.146932285373 34 | "1",8,"2","6",202.09533775789 35 | "1",9,"2","6",377.548028548561 36 | "1",10,"2","6",291.279250821587 37 | "1",11,"2","6",281.434484476452 38 | "1",12,"2","6",235.942502167984 39 | "1",13,"2","6",375.414388424309 40 | "1",14,"2","6",171.074300038772 41 | "1",15,"2","6",211.168386570523 42 | "1",16,"2","6",123.01408912358 43 | "1",17,"2","6",202.614443084265 44 | "1",18,"2","6",313.214808945148 45 | "1",19,"2","6",236.824549458765 46 | "1",20,"2","6",337.22824718058 47 | "1",21,"2","6",180.760547823164 48 | "1",22,"2","6",278.538844091007 49 | "1",23,"2","6",126.305617021296 50 | "1",24,"2","6",242.604422918136 51 | "1",25,"2","6",294.691908461626 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person7.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","7",310.738977341622 3 | "1",2,"1","7",236.558148662972 4 | "1",3,"1","7",291.153268493076 5 | "1",4,"1","7",294.356144256726 6 | "1",5,"1","7",230.909869203209 7 | "1",6,"1","7",285.950846244906 8 | "1",7,"1","7",167.556610706088 9 | "1",8,"1","7",225.692551618915 10 | "1",9,"1","7",249.229238455415 11 | "1",10,"1","7",228.966881646004 12 | "1",11,"1","7",207.568874262267 13 | "1",12,"1","7",255.473203838453 14 | "1",13,"1","7",277.612298115099 15 | "1",14,"1","7",213.293531727966 16 | "1",15,"1","7",300.495509830343 17 | "1",16,"1","7",204.056346493768 18 | "1",17,"1","7",243.394433593835 19 | "1",18,"1","7",233.528122444004 20 | "1",19,"1","7",234.093182899585 21 | "1",20,"1","7",300.019532928442 22 | "1",21,"1","7",210.049952881659 23 | "1",22,"1","7",227.54311322001 24 | "1",23,"1","7",196.474810260162 25 | "1",24,"1","7",339.060506857341 26 | "1",25,"1","7",181.860299945369 27 | "1",1,"2","7",250.35893024764 28 | "1",2,"2","7",132.262077500546 29 | "1",3,"2","7",254.685810744 30 | "1",4,"2","7",216.220620005812 31 | "1",5,"2","7",273.068143749011 32 | "1",6,"2","7",184.62550519573 33 | "1",7,"2","7",266.777591302618 34 | "1",8,"2","7",286.001968932536 35 | "1",9,"2","7",356.50845575846 36 | "1",10,"2","7",234.356532440425 37 | "1",11,"2","7",318.296605185176 38 | "1",12,"2","7",118.671600458553 39 | "1",13,"2","7",306.86777478939 40 | "1",14,"2","7",197.435373235075 41 | "1",15,"2","7",190.997251416907 42 | "1",16,"2","7",242.119505969015 43 | "1",17,"2","7",204.393954862271 44 | "1",18,"2","7",248.512559831179 45 | "1",19,"2","7",255.965599313074 46 | "1",20,"2","7",304.031425976041 47 | "1",21,"2","7",222.320718947032 48 | "1",22,"2","7",295.601220964774 49 | "1",23,"2","7",299.083006714915 50 | "1",24,"2","7",240.057319148917 51 | "1",25,"2","7",302.077532649897 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person8.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","8",195.853432007632 3 | "1",2,"1","8",239.250391130913 4 | "1",3,"1","8",345.445936131877 5 | "1",4,"1","8",253.653492983286 6 | "1",5,"1","8",269.825868198037 7 | "1",6,"1","8",257.632506643459 8 | "1",7,"1","8",275.05899625059 9 | "1",8,"1","8",198.23243567429 10 | "1",9,"1","8",364.473490343398 11 | "1",10,"1","8",251.976295653358 12 | "1",11,"1","8",274.62500529148 13 | "1",12,"1","8",245.129357590444 14 | "1",13,"1","8",249.170416538968 15 | "1",14,"1","8",219.110707066242 16 | "1",15,"1","8",203.616352880585 17 | "1",16,"1","8",179.49278452474 18 | "1",17,"1","8",199.749791992847 19 | "1",18,"1","8",277.267175405118 20 | "1",19,"1","8",232.559913422573 21 | "1",20,"1","8",281.215180590198 22 | "1",21,"1","8",258.510968240728 23 | "1",22,"1","8",335.860828249033 24 | "1",23,"1","8",224.300126953988 25 | "1",24,"1","8",211.748222919916 26 | "1",25,"1","8",203.714423317918 27 | "1",1,"2","8",271.795973548921 28 | "1",2,"2","8",157.889572478892 29 | "1",3,"2","8",254.258820127642 30 | "1",4,"2","8",215.096350120398 31 | "1",5,"2","8",421.955824494969 32 | "1",6,"2","8",290.778285530621 33 | "1",7,"2","8",300.979917278774 34 | "1",8,"2","8",242.058094188539 35 | "1",9,"2","8",301.684090231411 36 | "1",10,"2","8",308.624191926374 37 | "1",11,"2","8",257.418213726053 38 | "1",12,"2","8",300.021584820343 39 | "1",13,"2","8",157.073730275906 40 | "1",14,"2","8",91.6360117433235 41 | "1",15,"2","8",143.33453170741 42 | "1",16,"2","8",235.600544412538 43 | "1",17,"2","8",157.664089233415 44 | "1",18,"2","8",229.769865843154 45 | "1",19,"2","8",378.630376913907 46 | "1",20,"2","8",232.251128193445 47 | "1",21,"2","8",138.828376689388 48 | "1",22,"2","8",151.907830150612 49 | "1",23,"2","8",361.709122117295 50 | "1",24,"2","8",242.80135159773 51 | "1",25,"2","8",243.503635145437 52 | -------------------------------------------------------------------------------- /data/multiple-file-example/person9.csv: -------------------------------------------------------------------------------- 1 | "Condition","trial","time","person","RT" 2 | "1",1,"1","9",270.660864967567 3 | "1",2,"1","9",205.610973946685 4 | "1",3,"1","9",275.703146271613 5 | "1",4,"1","9",232.196976534538 6 | "1",5,"1","9",299.118050683053 7 | "1",6,"1","9",254.306381072877 8 | "1",7,"1","9",283.93391323458 9 | "1",8,"1","9",364.727233796362 10 | "1",9,"1","9",213.918235208456 11 | "1",10,"1","9",212.990961612181 12 | "1",11,"1","9",207.678564113772 13 | "1",12,"1","9",214.309597022793 14 | "1",13,"1","9",223.977502581444 15 | "1",14,"1","9",296.423173386077 16 | "1",15,"1","9",236.608587127186 17 | "1",16,"1","9",230.014706909122 18 | "1",17,"1","9",323.400451698994 19 | "1",18,"1","9",245.300731606552 20 | "1",19,"1","9",321.793845971801 21 | "1",20,"1","9",217.51240712291 22 | "1",21,"1","9",336.34925549303 23 | "1",22,"1","9",248.743869910338 24 | "1",23,"1","9",242.995296636289 25 | "1",24,"1","9",258.008971439437 26 | "1",25,"1","9",215.608766154548 27 | "1",1,"2","9",333.621385066641 28 | "1",2,"2","9",383.946643601877 29 | "1",3,"2","9",227.277348371485 30 | "1",4,"2","9",228.187663120103 31 | "1",5,"2","9",259.371296733439 32 | "1",6,"2","9",193.883319975823 33 | "1",7,"2","9",324.530389354152 34 | "1",8,"2","9",224.32653372546 35 | "1",9,"2","9",134.246696740295 36 | "1",10,"2","9",318.837161819726 37 | "1",11,"2","9",198.73189088685 38 | "1",12,"2","9",264.456280572251 39 | "1",13,"2","9",218.632183227713 40 | "1",14,"2","9",292.323452131271 41 | "1",15,"2","9",203.836331713171 42 | "1",16,"2","9",314.661767016401 43 | "1",17,"2","9",279.454040607251 44 | "1",18,"2","9",271.109533817437 45 | "1",19,"2","9",121.847371317811 46 | "1",20,"2","9",260.80663307874 47 | "1",21,"2","9",313.67695428673 48 | "1",22,"2","9",283.422231922423 49 | "1",23,"2","9",420.643309608792 50 | "1",24,"2","9",232.206175049802 51 | "1",25,"2","9",297.431721940339 52 | -------------------------------------------------------------------------------- /data/painmusic.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/painmusic.RDS -------------------------------------------------------------------------------- /data/sleep.long.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/sleep.long.RDS -------------------------------------------------------------------------------- /data/sleep.wide.RDS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/data/sleep.wide.RDS -------------------------------------------------------------------------------- /diagram.R: -------------------------------------------------------------------------------- 1 | library(DiagrammeR) 2 | library(DiagrammeRsvg) 3 | 4 | knit_gv <- function(code, filename=NULL, width=NULL, height=800){ 5 | 6 | assetpath <- "assets" 7 | dir.create(assetpath, showWarnings = F) 8 | 9 | if (!is.character(knitr::current_input())){ 10 | format <- "png" 11 | } else { 12 | if (stringr::str_detect( 13 | knitr::opts_knit$get("rmarkdown.pandoc.to"), "beamer|latex|pdf")) { 14 | format <- "pdf" 15 | } else { 16 | format <- "png" 17 | } 18 | } 19 | if (!is.character(filename)){ 20 | filename <- file.path(assetpath, paste0(sample(1e6:1e7, 1), ".", format)) 21 | } else { 22 | filename = paste0(filename, ".", format) 23 | } 24 | 25 | library('rsvg') 26 | outfun <- get(paste0("rsvg_", format)) 27 | capture.output({ 28 | g <- grViz(paste("digraph{", code, "}")) 29 | DiagrammeRsvg::export_svg(g) %>% charToRaw %>% outfun(filename, width=width, height=height) 30 | }, file='NUL') 31 | 32 | knitr::include_graphics(filename) 33 | 34 | } 35 | -------------------------------------------------------------------------------- /example.datasets.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'More example datasets' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | 7 | knitr::opts_chunk$set(include=F) 8 | library(tidyverse) 9 | library(pander) 10 | library(lubridate) 11 | ``` 12 | 13 | # Example datasets {#example-datasets} 14 | 15 | The 16 | 17 | ```{r} 18 | # data from: https://en.wikipedia.org/wiki/Mile_run_world_record_progression#Men 19 | miles <- 20 | read_csv('data/miletimes.csv') %>% 21 | mutate(date=lubridate::dmy(date)) %>% 22 | select(-auto) %>% 23 | separate(time, into=c('m','s'), sep=":") %>% 24 | mutate_each(funs(as.numeric), m,s) %>% 25 | mutate(time=lubridate::seconds(m*60+s)) 26 | 27 | saveRDS(miles, file="data/miles.RDS") 28 | miles %>% filter(date < lubridate::dmy("01 January 1970")) %>% 29 | saveRDS(., file="data/miles-pre-1970.RDS") 30 | 31 | miles %>% glimpse 32 | 33 | ``` 34 | -------------------------------------------------------------------------------- /examples-of-notes.Rmd: -------------------------------------------------------------------------------- 1 | [admonition]{.admonition} 2 | 3 | [.exercise]{.exercise} 4 | 5 | [This is a paragraph with apa]{.apa-example} 6 | -------------------------------------------------------------------------------- /fancy-reshaping.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Fancy reshaping' 3 | --- 4 | 5 | ```{r, include=FALSE, message=F} 6 | library(tidyverse) 7 | library(reshape2) 8 | library(pander) 9 | ``` 10 | 11 | ### Fancy reshaping {- #fancy-reshaping} 12 | 13 | As noted above, it's common to combine the process of reshaping and aggregating 14 | or summarising in the same step. 15 | 16 | For example here we have multiple rows per person, 3 trial at time 1, and 3 more 17 | trials at time 2: 18 | 19 | ```{r, include=F} 20 | expt.data <- readRDS("data/expt.data.RDS") %>% filter(trial < 4) 21 | ``` 22 | 23 | ```{r} 24 | expt.data %>% 25 | arrange(person, time, trial) %>% 26 | head %>% 27 | pander 28 | ``` 29 | 30 | We can reshape and aggregate this in a single step using `dcast`. Here we 31 | request the mean for each person at each time, with observations for each time 32 | split across two columns: 33 | 34 | ```{r, message=T, warning=T} 35 | library(reshape2) 36 | expt.data %>% 37 | dcast(person~paste0('time',time), 38 | fun.aggregate=mean) %>% 39 | head %>% 40 | pander 41 | ``` 42 | 43 | Here `dcast` has correctly guessed that `RT` is the value we want to aggregate 44 | (you can specify explicitly with the `value.var=` parameter). 45 | 46 | `dcast` knows to aggregate using the mean because we set this with the 47 | `agg.function` parameter; this just stands for 'aggregation function'. 48 | 49 | We don't have to request the mean though: any function will do. Here we request 50 | the SD instead: 51 | 52 | ```{r, message=T, warning=T} 53 | expt.data %>% 54 | dcast(person~time, 55 | fun.aggregate=sd) %>% 56 | head %>% 57 | pander 58 | ``` 59 | -------------------------------------------------------------------------------- /fixed-or-random.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Fixed and Random effects' 3 | --- 4 | 5 | # Fixed and random effects {#fixed-or-random} 6 | 7 | As noted by @gelman_analysis_2005 (and 8 | [summarised here](http://andrewgelman.com/2005/01/25/why_i_dont_use/)), the 9 | terms 'fixed' and 'random' are used very loosely in both the methodological and 10 | applied literature. Gelman identifies 5 different senses in which the 11 | distinction between fixed and random effects can be drawn, and this 12 | inconsistency can lead to confusion. 13 | 14 | #### {- #random-slopes-intercepts} 15 | 16 | For practical purposes, if you think that you have some form of grouping in your 17 | data and that it makes sense to think of variation in outcomes between these 18 | groups then you should probably include it as a random intercept in your model. 19 | 20 | Likewise, if you include a predictor in your model and it is reasonable to think 21 | that the effect of this predictor would vary between groups in the data (e.g., 22 | between individuals) then you should include a random slope effect for this 23 | variable. 24 | 25 | ##### Random intercepts {- #random-intercepts} 26 | 27 | Some example of groupings which should be included as random intercepts: 28 | 29 | - Participants 30 | - Classes and Schools 31 | - Therapists or treatment providers (e.g. in cluster randomised trial) 32 | - Stimuli or 'items' 33 | 34 | Groupings which are not clear cut in either direction: 35 | 36 | - A smallish number of experimental conditions which could be thought of as 37 | 'sampled' from a larger population of possible groupings 38 | [@gelman2005analysis]. An example here would be groups which recieve 39 | different doses of a drug. 40 | 41 | Examples of groupings which are probably not best handled as random intercepts: 42 | 43 | - Experimental conditions especially where the conditions are qualitatively 44 | different (although the interventions might warrant inclusion as a random 45 | slope, see below). 46 | 47 | ##### Random slopes {- #random-slopes} 48 | 49 | Where the effect of a variable might vary between individuals (or other 50 | grouping) should be considered for inclusion as a random slopes. Some examples 51 | might include: 52 | 53 | - Time (or some function of time) 54 | - An experimental intervention (e.g. in a factorial design) 55 | 56 | For a more in depth discussion of when to include a random slope 57 | [this presentation and transcript from the Bristol CMM is excellent](http://www.bristol.ac.uk/cmm/learning/videos/random-slopes.html). 58 | 59 | 65 | -------------------------------------------------------------------------------- /graphics-ggplot-extras.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'ggplot extras' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | knitr::opts_chunk$set(echo = TRUE, collapse=TRUE, cache=TRUE, message=F) 7 | library(tidyverse) 8 | library(pander) 9 | library(knitr) 10 | ``` 11 | 12 | ## Tricks with ggplot {- #ggplot-details} 13 | 14 | ### More ways to facet a plot {- #facetting-plots} 15 | 16 | Facets are ways to repeat a plot for each level of another variable. `ggplot` 17 | has two ways of defining and displaying facets: 18 | 19 | - As a list of plots, using `facet_wrap`. 20 | - As a grid or matrix of plots, using `facet_grid()`. 21 | 22 | Examples of both are shown below, using the following plot as a starting point: 23 | 24 | ```{r} 25 | base.plot <- ggplot(mtcars, aes(mpg, wt)) + geom_point() 26 | base.plot 27 | ``` 28 | 29 | ### `facet_wrap` {-} 30 | 31 | If we want one facet we just type the tilde (`~`) symbol and then the name of 32 | the variable. This is like typing the right hand side of a 33 | [formula for a regression model](formulae): 34 | 35 | ```{r} 36 | base.plot + facet_wrap(~cyl) 37 | ``` 38 | 39 | If we want two facets we extend the formula, using the `+` sign: 40 | 41 | ```{r} 42 | base.plot + facet_wrap(~cyl+am) 43 | ``` 44 | 45 | Note, the order of variables in the formula makes a difference: 46 | 47 | ```{r} 48 | base.plot + facet_wrap(~am+cyl) 49 | ``` 50 | 51 | ### `facet_grid` {-} 52 | 53 | With one variable `facet_grid` produces similar output. Note the `.` (period) on 54 | the left hand side of the formula now to make explicit we only have one 55 | variable, and we want it on the x axis: 56 | 57 | ```{r} 58 | base.plot + facet_grid(.~cyl) 59 | ``` 60 | 61 | We can flip the facets around by putting the `cyl` variable on the left hand 62 | side of the `~`: 63 | 64 | ```{r} 65 | base.plot + facet_grid(cyl~.) 66 | ``` 67 | 68 | And `facet_grid` can also create facets for two or more variables: 69 | 70 | ```{r} 71 | base.plot + facet_grid(am~cyl) 72 | ``` 73 | 74 | Here the labelling and the arrangement of plots is perhaps nicer because it is 75 | clearer that plots for `cyl` are arrange left to right, and for `am` they are 76 | top to bottom. 77 | 78 | ### Combining separate plots in a grid {- #combining-plots} 79 | 80 | Note that combining separate plots in a grid is different from 81 | [facetting](#facetting-plots), and it may be you want that instead. 82 | 83 | If you really want to combine several plots, the `gridExtra` and `cowplot` 84 | packages can be helpful. This is the code from the 85 | [example in the graphics section](#layered-graphics), which may be a useful 86 | starting point: 87 | 88 | ```{r} 89 | comparison <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot() + ggtitle("Comparison") 90 | relationships <- ggplot(mtcars, aes(wt, mpg, color=factor(gear))) + geom_point() + ggtitle("Relationship") 91 | distributions <- ggplot(mtcars, aes(mpg, color=factor(gear))) + geom_density() + ggtitle("Distribution") 92 | composition <- ggplot(mtcars, aes(factor(cyl), fill = factor(gear))) + geom_bar() + ggtitle("Composition") 93 | mm <- theme(plot.margin=unit(rep(1.5,4), "line")) 94 | gridExtra::grid.arrange(relationships+mm, distributions+mm, comparison+mm, composition+mm, ncol=2) 95 | ``` 96 | 97 | ## Exporting for print {- #exporting-graphics} 98 | 99 | To export ggplot graphics you can use the `ggsave()` function: 100 | 101 | ```{r, eval=F} 102 | 103 | ggplot(mtcars, aes(wt, mpg)) + geom_point() 104 | ggsave(filename = "myplot.pdf") 105 | 106 | ``` 107 | 108 | See the 109 | [ggplot docs on exporting](http://ggplot2.tidyverse.org/reference/ggsave.html) 110 | or page 111 | [323 of the R Graphics Cookbook](https://ase.tufts.edu/bugs/guide/assets/R%20Graphics%20Cookbook.pdf) 112 | for lots more detail. 113 | -------------------------------------------------------------------------------- /headers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | -------------------------------------------------------------------------------- /help.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Getting help' 3 | --- 4 | 5 | # Getting help {#getting-help} 6 | 7 | If you don't know or can't remember what a function does, R provides help files 8 | which explain how they work. To access a help file for a function, just type 9 | `?command` in the console, or run `?command` command within an R block. For 10 | example, running `?mean` would bring up the documentation for the `mean` 11 | function. 12 | 13 | You can also type `CRTL-Shift-H` while your cursor is over any R function in the 14 | RStudio interface. 15 | 16 | It's fair to say R documentation isn't always written for beginners. However the 17 | 'examples' sections are usually quite informative: you can normally see this by 18 | scrolling right to the end of the help file. 19 | 20 | ### Finding the backtick on your keyboard {- #backtick-location} 21 | 22 | The backtick ``` symbol is unfamiliar to some readers. Here's where it is: 23 | 24 | ![On windows](media/backtick-windows-uk.png) 25 | 26 | ![On a Mac](media/backtick-mac-uk.png) 27 | -------------------------------------------------------------------------------- /index.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Just Enough R' 3 | site: bookdown::bookdown_site 4 | --- 5 | 6 | # Introduction {-} 7 | 8 | ![](media/keepcalm.png){.cup} 9 | 10 | 11 | 12 | R makes it easy to work with and learn from data. 13 | 14 | It also happens to be a programmming language, but if you're reading this, that 15 | might not be of interest. That's OK — the goal here is not to teach 16 | programming^[This is a lie, but hopefully it won't be obvious until it's too 17 | late.]. The goal is to teach you _just enough R_ to be confident to explore your 18 | data. 19 | 20 | This book uses R like any other statistics software: To work-with and visualise 21 | data, run statistical analyses, and share our results with others. To do that 22 | you don't need more than the _absolute basics_ of the R language itself. The 23 | first chapters walk you through what you need to know to be productive. 24 | 25 | #### Things to know Before you start {-} 26 | 27 | This guide is fairly opinionated, but for good reason. 28 | 29 | There are lots of ways to use R, and this has been a barrier for beginners. In 30 | particular base-R functions can be oddly-named, or lack a regular or predictable 31 | interface. For this reason we: 32 | 33 | - Recommend (strongly) that you install and use 'packages' that extend some of 34 | R's basic functionality. These packages are powerful tools in their own 35 | right, but also hide some of the complexities of R in a 36 | [clear and consistent way](https://www.youtube.com/watch?v=K-ss_ag2k9E). It 37 | might seem restrictive but, to begin with, learning _only_ these packages 38 | will help you form a more consistent mental model and make rapid progress. 39 | You can learn the crufty old bits (which still have their uses) later on. 40 | 41 | - Assume you are using the [RStudio editor](#rstudio) and working in an 42 | [RMarkdown document](#rmarkdown) (see the next section). If you don't have 43 | access to RStudio yet, see the [installation guide](installation.html). 44 | 45 | #### License {-} 46 | 47 | These documents are licensed under the 48 | [CC BY-SA licence](https://creativecommons.org/licenses/by-sa/4.0/). 49 | -------------------------------------------------------------------------------- /install-bayes-tools.R: -------------------------------------------------------------------------------- 1 | # This installs all dependencies successfully on OS X and Linux 2 | # provided you have a working GCC. 3 | # sudo apt-get install GCC R 4 | 5 | dotR <- file.path(Sys.getenv("HOME"), ".R") 6 | if (!file.exists(dotR)) dir.create(dotR) 7 | M <- file.path(dotR, "Makevars") 8 | if (!file.exists(M)) file.create(M) 9 | cat("\nCXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function", 10 | file = M, sep = "\n", append = TRUE) 11 | 12 | cat("\nCXXFLAGS+=-flto -ffat-lto-objects -Wno-unused-local-typedefs", 13 | file = M, sep = "\n", append = TRUE) 14 | 15 | Sys.setenv(MAKEFLAGS = "-j4") 16 | install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies=TRUE) 17 | 18 | 19 | install.packages('rstanarm') 20 | install.packages('bayesplot') 21 | devtools::install_github("mjskay/tidybayes") 22 | devtools::install_github("rmcelreath/rethinking") 23 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/. 2 | -------------------------------------------------------------------------------- /making-table-1.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Making "Table 1"' 3 | --- 4 | 5 | ```{r, include=FALSE, message=F} 6 | library(tidyverse) 7 | library(reshape2) 8 | library(broom) 9 | library(pander) 10 | ``` 11 | 12 | ## "Table 1" {- #table1} 13 | 14 | Table 1 in reports of clinical trials and many psychological studies reports 15 | characteristics of the sample. Typically, you will want to present information 16 | collected at baseline, split by experimental groups, including: 17 | 18 | - Means, standard deviations or other descriptive statistics for continuous 19 | variables 20 | - Frequencies of particular responses for categorical variables 21 | - Some kind of inferential test for a zero-difference between the groups; this 22 | could be a t-test, an F-statistic where there are more than 2 groups, or a 23 | chi-squared test for categorical variables. 24 | 25 | 26 | 27 | Producing this table is a pain because it requires collating multiple 28 | statistics, calculated from different functions. Many researchers resort to 29 | performing all the analyses required for each part of the table, and then 30 | copying-and-pasting results into Word. 31 | 32 | It can be automated though! This example combines and extends many of the 33 | techniques we have learned using the split-apply-combine method. 34 | 35 | To begin, let's simulate some data from a fairly standard 2-arm clinical trial 36 | or psychological experiment: 37 | 38 | ```{r, include=F} 39 | # make up some example data 40 | boring.study <- expand.grid(person=1:70, time=1:2, condition=c("Control", "Intervention")) %>% 41 | as_tibble %>% 42 | mutate(person=row_number(), 43 | yob=round(1979+rnorm(n(), 0,5)), 44 | WM=round(100+rnorm(n(), 0, 10)), 45 | education = sample(c("Primary", "Secondary", "Graduate", "Postgraduate", NA), n(), replace=T), 46 | ethnicity = sample(c("White British", "Mixed / multiple ethnic groups", "Asian / Asian British", "Black / African / Caribbean / Black British"), n(), replace=T), 47 | Attitude = round(5+2 * (condition=="Control") + rnorm(n(), 0, 3))) 48 | ``` 49 | 50 | Check our data: 51 | 52 | ```{r} 53 | boring.study %>% glimpse 54 | ``` 55 | 56 | Start by making a long-form table for the categorical variables: 57 | 58 | ```{r} 59 | boring.study.categorical.melted <- 60 | table1.categorical.Ns <- boring.study %>% 61 | select(condition, education, ethnicity) %>% 62 | melt(id.var='condition') 63 | ``` 64 | 65 | Then calculate the N's for each response/variable in each group: 66 | 67 | ```{r} 68 | (table1.categorical.Ns <- 69 | boring.study.categorical.melted %>% 70 | group_by(condition, variable, value) %>% 71 | summarise(N=n()) %>% 72 | dcast(variable+value~condition, value.var="N")) 73 | ``` 74 | 75 | Then make a second table containing Chi2 test statistics for each variable: 76 | 77 | ```{r} 78 | (table1.categorical.tests <- 79 | boring.study.categorical.melted %>% 80 | group_by(variable) %>% 81 | do(., chisq.test(.$value, .$condition) %>% tidy) %>% 82 | # this purely to facilitate matching rows up below 83 | mutate(firstrowforvar=T)) 84 | ``` 85 | 86 | Combine these together: 87 | 88 | ```{r} 89 | (table1.categorical.both <- table1.categorical.Ns %>% 90 | group_by(variable) %>% 91 | # we join on firstrowforvar to make sure we don't duplicate the tests 92 | mutate(firstrowforvar=row_number()==1) %>% 93 | left_join(., table1.categorical.tests, by=c("variable", "firstrowforvar")) %>% 94 | # this is gross, but we don't want to repeat the variable names in our table 95 | ungroup() %>% 96 | mutate(variable = ifelse(firstrowforvar==T, as.character(variable), NA)) %>% 97 | select(variable, value, Control, Intervention, statistic, parameter, p.value)) 98 | ``` 99 | 100 | Now we deal with the continuous variables. First we make a 'long' version of the 101 | continuous data 102 | 103 | ```{r} 104 | continuous_variables <- c("yob", "WM") 105 | boring.continuous.melted <- 106 | boring.study %>% 107 | select(condition, continuous_variables) %>% 108 | melt() %>% 109 | group_by(variable) 110 | 111 | boring.continuous.melted %>% head 112 | ``` 113 | 114 | Then calculate separate tables of t-tests and means/SD's: 115 | 116 | ```{r} 117 | (table.continuous_variables.tests <- 118 | boring.continuous.melted %>% 119 | # note that we pass the result of t-test to tidy, which returns a dataframe 120 | do(., t.test(.$value~.$condition) %>% tidy) %>% 121 | select(variable, statistic, parameter, p.value)) 122 | 123 | (table.continuous_variables.descriptives <- 124 | boring.continuous.melted %>% 125 | group_by(variable, condition) %>% 126 | # this is not needed here because we have no missing values, but if there 127 | # were missing value in this dataset then mean/sd functions would fail below, 128 | # so best to remove rows without a response: 129 | filter(!is.na(value)) %>% 130 | # note, we might also want the median/IQR 131 | summarise(Mean=mean(value), SD=sd(value)) %>% 132 | group_by(variable, condition) %>% 133 | # we format the mean and SD into a single column using sprintf. 134 | # we don't have to do this, but it makes reshaping simpler and we probably want 135 | # to round the numbers at some point, and so may as well do this now. 136 | transmute(MSD = sprintf("%.2f (%.2f)", Mean, SD)) %>% 137 | dcast(variable~condition)) 138 | ``` 139 | 140 | And combine them: 141 | 142 | ```{r} 143 | (table.continuous_variables.both <- 144 | left_join(table.continuous_variables.descriptives, 145 | table.continuous_variables.tests)) 146 | 147 | ``` 148 | 149 | Finally put the whole thing together: 150 | 151 | ```{r} 152 | (table1 <- table1.categorical.both %>% 153 | # make these variables into character format to be consistent with 154 | # the Mean (SD) column for continuus variables 155 | mutate_each(funs(format), Control, Intervention) %>% 156 | # note the '.' as the first argument, which is the input from the pipe 157 | bind_rows(., 158 | table.continuous_variables.both) %>% 159 | # prettify a few things 160 | rename(df = parameter, 161 | p=p.value, 162 | `Control N/Mean (SD)`= Control, 163 | Variable=variable, 164 | Response=value, 165 | `t/χ2` = statistic)) 166 | ``` 167 | 168 | And we can print to markdown format for outputting. This is best done in a 169 | separate chunk to avoid warnings/messages appearing in the final document. 170 | 171 | ```{r} 172 | table1 %>% 173 | # split.tables argument needed to avoid the table wrapping 174 | pander(split.tables=Inf, 175 | missing="-", 176 | justify=c("left", "left", rep("center", 5)), 177 | caption='Table presenting baseline differences between conditions. Categorical variables tested with Pearson χ2, continuous variables with two-sample t-test.') 178 | ``` 179 | 180 | Some exercises to work on/extensions to this code you might need: 181 | 182 | - Add a new continuous variable to the simulated dataset and include it in the 183 | final table 184 | - Create a third experimental group and amend the code to i) include 3 columns 185 | for the N/Mean and ii) report the F-test from a one-way Anova as the test 186 | statistic. 187 | - Add the within-group percentage for each response to a categorical variable. 188 | -------------------------------------------------------------------------------- /media/Holding_the_eiffel_tower.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/Holding_the_eiffel_tower.jpg -------------------------------------------------------------------------------- /media/arcane_bullshit_2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/arcane_bullshit_2x.png -------------------------------------------------------------------------------- /media/aurora-1-px-grey.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/aurora-1-px-grey.jpg -------------------------------------------------------------------------------- /media/aurora-1-px-raw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/aurora-1-px-raw.png -------------------------------------------------------------------------------- /media/aurora-1-px.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/aurora-1-px.jpg -------------------------------------------------------------------------------- /media/aurora.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/aurora.jpg -------------------------------------------------------------------------------- /media/aurora.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/aurora.png -------------------------------------------------------------------------------- /media/backtick-mac-uk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/backtick-mac-uk.png -------------------------------------------------------------------------------- /media/backtick-windows-uk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/backtick-windows-uk.png -------------------------------------------------------------------------------- /media/budget1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/budget1.png -------------------------------------------------------------------------------- /media/budget2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/budget2.png -------------------------------------------------------------------------------- /media/choosing_a_good_chart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/choosing_a_good_chart.jpg -------------------------------------------------------------------------------- /media/face1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/face1.png -------------------------------------------------------------------------------- /media/face2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/face2.png -------------------------------------------------------------------------------- /media/graphics-cookbook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/graphics-cookbook.png -------------------------------------------------------------------------------- /media/homer-car.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/homer-car.jpg -------------------------------------------------------------------------------- /media/illusioncolours.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/illusioncolours.jpg -------------------------------------------------------------------------------- /media/inline-r-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/inline-r-example.png -------------------------------------------------------------------------------- /media/jeeves.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/jeeves.jpg -------------------------------------------------------------------------------- /media/keepcalm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/keepcalm.png -------------------------------------------------------------------------------- /media/large-family.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/large-family.jpg -------------------------------------------------------------------------------- /media/lego-blocks-2458575_1280-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/lego-blocks-2458575_1280-1.jpg -------------------------------------------------------------------------------- /media/map_projections.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/map_projections.png -------------------------------------------------------------------------------- /media/optimization_2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/optimization_2x.png -------------------------------------------------------------------------------- /media/patterns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/patterns.png -------------------------------------------------------------------------------- /media/r-code-chunk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/r-code-chunk.png -------------------------------------------------------------------------------- /media/rstudio-mainwindow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/rstudio-mainwindow.png -------------------------------------------------------------------------------- /media/rstudio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/rstudio.png -------------------------------------------------------------------------------- /media/rugs1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/rugs1.jpg -------------------------------------------------------------------------------- /media/rugs1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/rugs1.png -------------------------------------------------------------------------------- /media/rugs2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/rugs2.jpg -------------------------------------------------------------------------------- /media/significant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/significant.png -------------------------------------------------------------------------------- /media/sunset-sidebyside.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/sunset-sidebyside.jpg -------------------------------------------------------------------------------- /media/sunset1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/sunset1.jpg -------------------------------------------------------------------------------- /media/sunset2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/sunset2.jpg -------------------------------------------------------------------------------- /media/telescope_names_2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/telescope_names_2x.png -------------------------------------------------------------------------------- /media/tubes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/tubes.jpg -------------------------------------------------------------------------------- /media/xkcd_presidents_overfitting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benwhalley/just-enough-r/cf12a971b5f4285d3c33a2b4d0b3aa975e8c69e3/media/xkcd_presidents_overfitting.png -------------------------------------------------------------------------------- /meta-analysis.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Meta analysis' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | library(pander) 8 | library(lmerTest) 9 | ``` 10 | 11 | # Meta analysis in R {#meta-analysis} 12 | 13 | For the moment, 14 | [see this introduction to meta analysis in R](https://www.r-bloggers.com/r-and-meta-analysis/) 15 | -------------------------------------------------------------------------------- /mixed-shrinkage.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Shrinkage' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | library(pander) 8 | library(lmerTest) 9 | ``` 10 | 11 | ```{r} 12 | set.seed(1) 13 | within.sd <- 1 14 | between.sd <- 1 15 | df <- expand.grid(person=1:10, trial=1:10, group=factor(1:3)) %>% 16 | mutate(person = factor(as.numeric(factor(paste(person, group))))) %>% 17 | group_by(person) %>% 18 | mutate(u = rnorm(1, 0, between.sd)) %>% 19 | ungroup() %>% 20 | mutate(y = rnorm(n(), 0, within.sd) + u + 1*as.numeric(group)) 21 | 22 | m <- lmer(y ~ group + (1|person), data=df) 23 | 24 | df <- left_join(df, 25 | ranef(m)$person %>% rownames_to_column(var="person") %>% rename(uhat=`(Intercept)`)) 26 | 27 | 28 | 29 | peeps.df <- df %>% group_by(person) %>% summarise_all(funs(first)) 30 | xb.person <- predict(m, re.form=NA, newdata=peeps.df) 31 | 32 | ranef(m)$person %>% 33 | rownames_to_column(var="person") %>% 34 | left_join(peeps.df, .) %>% 35 | mutate(person=person, 36 | xb= xb.person, shrunk = `(Intercept)`+xb) %>% 37 | ggplot(aes(x=person, y=shrunk, xend=person, yend=xb, color=group)) + 38 | geom_segment(arrow=arrow(length = unit(0.03, "npc"))) + 39 | facet_wrap(~group) 40 | ``` 41 | -------------------------------------------------------------------------------- /non-parametrics.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Non-parametric statistics 3 | --- 4 | 5 | ## Non-parametric statistics {#nonparametrics} 6 | 7 | This guide is very light on non-parametric statistics in R. 8 | 9 | For more on this topic 10 | [this page on the statmethods site](http://www.statmethods.net/stats/nonparametric.html) 11 | is a useful guide. 12 | 13 | The [`coin::` package](http://finzi.psych.upenn.edu/R/library/coin/doc/coin.pdf) 14 | implements many resampling tests, which can also be useful when assumptions of 15 | parametric tests are not valid. 16 | [See this intro to resampling statistics](http://www.statmethods.net/stats/resampling.html). 17 | -------------------------------------------------------------------------------- /over-fitting.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Model comparison and selection' 3 | --- 4 | 5 | # Building and choosing models {#comparison-and-selection} 6 | 7 | ### Like maps, models are imperfect but useful {-} 8 | 9 | ![](media/map_projections.png) 10 | 11 | Maps are always imperfect, and the decisons we make as we build them entail 12 | different visions of how the world is. 13 | 14 | For example, when making maps cartographers must decide at what size to print 15 | it, and how much detail to include. The smaller the map the more convenient it 16 | is to carry, but a smaller map can never represent reality as accurately. 17 | Similarly, we must leave out details to make the map practical to use; but 18 | _what_ we omit depends on the planned use of the map. 19 | 20 | Stretching he analogy a little, we could evaluate maps according to their 21 | performance: did the map help us navigate to a desired location, for example? 22 | This is likely to be a function of two things: 23 | 24 | - _Veracity_: that is, how faithfully does the map represent the 'reality' of 25 | the terrain it covers? 26 | - _Simplicity_: does the map include details which are ephemeral, or irrelvant 27 | to the task in hand? 28 | 29 | At one extreme, we might take an aerial photo of a city, which would accurately 30 | represent the terrain, but would include many details which are ephemeral or 31 | transient and not necessary to the task of, for example, finding the city's 32 | railway station. Indeed the photo is literally a snapshot of the city on a given 33 | day, and some elements might be unhelpful in navigating the city several months 34 | later; the photo might include temporary roadworks, for example, which could 35 | lead the reader to assume a street was blocked to traffic when this was not 36 | normally the case. At the other extreme, we might consider a highly stylised 37 | cartoon map of the same city, which includes onlu major roads and the station 38 | itself, but none of the secondary roads or other landmarks. Here the map is so 39 | lacking in detail that it may be hard to orient ourselves to the actual terrain. 40 | 41 | Statistical models are not exactly like maps, but we can evaluate them using 42 | similar criteria. A good model enables the user to make sense of the data they 43 | collect (i.e. navigate the city) and this involves making reliable predictions. 44 | Reliable predictions are possible when the model accurately represents the 45 | underlying reality of a phenomena, but also when the model is simple enough to 46 | ignore ephemeral or irrelevant information. 47 | 48 | Evaluating and selecting statistical models involves just this kind of tradeoff 49 | between _veracity_ and _simplicity_. 50 | 51 | To stretch the analogy above, when we collect data, we are taking a photo of the 52 | city, making a snapshot of a given process at a particular place and time. This 53 | snapshot (hopefully) contains valuable information about how the process works 54 | in general, but it also includes noise and irrelevant information which could 55 | distract us, preventing us from using the data to accurately predict the future. 56 | 57 | ### Overfitting/underfitting {- #over-fitting} 58 | 59 | To ~~steal~~use a different analogy, imagine you want to predict who will win 60 | the next US presidential election: 61 | 62 | ![Cartoon: xkcd.com](media/xkcd_presidents_overfitting.png) 63 | 64 | In total there have only been 57 presidential elections and 44 presidents in the 65 | US, which isn't a lot of data to learn from. The point of the cartoon is that if 66 | we try and include ephemeral predictors like beards and false teeth then the 67 | space of possible combinations becomes huge. This means that some of these 68 | combinations will start to fit the data because of chance variations, and not 69 | because they represent some fundamental aspect of the process generating the 70 | outcome (election wins). 71 | 72 | If you allow statistical models to expand in this way (that is, driven only by 73 | patterns in the data you have) then you will find that, inevitably, the model 74 | fits the data you have, but the you won't be able to predict _new_ data at all. 75 | 76 | This is one of the reasons why we prefer simpler models, all other things being 77 | equal. It also explains why practices like stepwise regression, where we add or 78 | remove variables depending on whether they are 'statistically significant', 79 | [are almost always a bad idea](http://www.stata.com/support/faqs/statistics/stepwise-regression-problems/). 80 | We should only accept a complex model (e.g. one including false teeth as a 81 | predictor of the presidency) if we have enough evidence to be confident this 82 | will predict new data. 83 | 84 | ### Choosing the 'right variables' {- #variable-selection} 85 | 86 | As an aside, if you do find yourself in a situation with a large number of 87 | predictors and hope to build a simpler model --- either with the goal of 88 | prediction or theory development --- then it's hopefully obvious from the 89 | discussion above that simply dropping or selecting predictors based on _p_ 90 | values is unlikely to lead to good science. Not only will you tend to over-fit 91 | the data you have, but you may also discount valid predictor variables because 92 | of problems like multicollinearity (correlations between predictors). 93 | 94 | In other disciplines where inference from observational data are more common 95 | (e.g. ecology and biological anthropolgy) the concepts of model averaging or 96 | multimodal inference have gained currency, and may be be useful to applied 97 | psychologists. The core concept is that if we have several models, all of which 98 | are approximately as good as each other, then we should make predictions and 99 | inferences by averaging across the models, weighting each model by how well it 100 | fits the data: that is, we give the most weight to the best fitting model, but 101 | don't completely discount other models which fit almost as well. 102 | 103 | See @mcelreath2016rethinking, chapter 6, for a good introduction. 104 | [This video explains the concept well](https://www.youtube.com/watch?v=LQb7l5IfS0s). 105 | The R package 106 | [MuMln package](https://cran.r-project.org/web/packages/MuMIn/index.html) 107 | implements most of the methods needed. See also this 108 | [interesting post on model selection problems](https://www.r-bloggers.com/model-selection-and-multi-model-inference/). 109 | -------------------------------------------------------------------------------- /packages.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Loading packages (Teaching an old dog new tricks)' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | ``` 8 | 9 | ## Packages {- #packages} 10 | 11 | R has been around for ages. It remains popular because it's _easy for people to 12 | add to it_. 13 | 14 | You can run almost any statistical model and produce many different plots in R 15 | because users write 'packages' which extend the base language. For now we assume 16 | someone has helped you install all the packages you need^[See the 17 | [installation guide](installation.html) if this isn't the case]. 18 | 19 | To _access_ features in packages, you normally load the package with the 20 | `library()` function. Running `library()` loads all the new 21 | functions within it, and it is then possible to call them from your code. For 22 | example, typing: 23 | 24 | ```{r} 25 | library(ggplot2) 26 | ``` 27 | 28 | Will load the `ggplot2` package. You can then call the `qplot` function it 29 | provides: 30 | 31 | ```{r} 32 | qplot(mtcars$mpg, bins=7) 33 | ``` 34 | 35 | :::{.tip} 36 | 37 | It's good style to load packages at the top of an R script, or in the first 38 | chunk of an RMarkdown document. This makes it easy for others to see what 39 | packages they need to install, and helps avoid certain sorts of errors in your 40 | code. 41 | 42 | ::: 43 | 44 | #### {- #package-namespacing} 45 | 46 | You don't strictly _need_ to load packages to use their features. If a package 47 | is installed on your system you can also call a function it provides directly. 48 | In the example below we call the `hist.data.frame` from the `Hmisc` package, and 49 | obtain histograms of all the variables in the `mtcars` dataset: 50 | 51 | ```{r} 52 | Hmisc::hist.data.frame(mtcars) 53 | ``` 54 | 55 | The rule is to type `package::function(parameters)`, where `::` separates the 56 | package and function names. Parameters are just the inputs to the function. 57 | 58 | There are two reasons not to load a package before using it: 59 | 60 | 1. Laziness: it can save typing if you just want to use one function from a 61 | package, and only once. 62 | 63 | 2. Explicitness: It's an unfortunate truth that some function names are repeated 64 | in different packages. This can be confusing if they work differently or do 65 | comepletely different things. If you don't know which package the version you 66 | are using comes from. Using `package_name:function_name` can help make things 67 | explicit. 68 | 69 | :::{.exercise} 70 | 71 | Try using the `hist.data.frame` function in the `Hmisc` package on the `mtcars` 72 | data. 73 | 74 | - First using the `::` syntax 75 | - Then load the `Hmisc` package, and repeat without using the `::`. 76 | 77 | ::: 78 | -------------------------------------------------------------------------------- /polynomials.Rmd: -------------------------------------------------------------------------------- 1 | From field: 2 | 3 | A quadratic trend is where there is one change in the direction of the line 4 | (e.g., the line is curved in one place). An example of this might be a situation 5 | in which a drug enhances performance on a task at first, but then as the dose 6 | increases the performance drops again. To find a quadratic trend you need at 7 | least three groups (because in the two-group situation there are not enough 8 | categories of the independent variable for the means of the dependent variable 9 | to change one way and then another). A cubic trend is where there are two 10 | changes in the direction of the trend. So, for example, the mean of the 11 | dependent variable at first goes up across the first couple of categories of the 12 | independent variable, then across the succeeding categories the means go down, 13 | but then across the last few categories the means rise again. To have two 14 | changes in the direction of the mean you must have at least four categories of 15 | the independent variable. The final trend that you are likely to come across is 16 | the quartic trend, and this trend has three changes of direction (so you need at 17 | least five categories of the independent variable). 18 | -------------------------------------------------------------------------------- /power-analysis.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Power analysis' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | library(pander) 8 | library(simr) 9 | ``` 10 | 11 | # Power analysis {#power-analysis} 12 | 13 | ### For most inferential statistics {-} 14 | 15 | If you want to do power analysis for a standard statistical test, e.g. t-tests, 16 | chi^2^ or Anova, the `pwr::` package is what you need. 17 | [This guide has a good walkthrough](http://www.statmethods.net/stats/power.html). 18 | 19 | ### For multilevel or generalised linear models {-} 20 | 21 | If you'd like to run power analyses for linear mixed models 22 | ([multilevel models](#multilevel-models)) then you need 23 | [the `simr::` package](http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12504/full). 24 | It has some neat features for calculating power by simulating data and results 25 | from a model you specify. 26 | 27 | To take a simple example, let's fabricate some data where outcomes `y` are 28 | nested within groups `g`, and where there is a covariate of interest `x`. That 29 | is, we are interested in estimating our power to detect an effect of `x`. 30 | 31 | Note though that in this simulated data, we create outcomes (`y`) with no 32 | relationship to `x`, and no clustering by `g` at this stage (i.e. `y`, `x` and 33 | `g` are uncorrelated). 34 | 35 | ```{r} 36 | set.seed(1234) 37 | simulated.df <- data_frame( 38 | x = rep(0:1, 50), 39 | g = rep(1:10, 10), 40 | y = rnorm(100) 41 | ) 42 | GGally::ggpairs(simulated.df) 43 | ``` 44 | 45 | To use `simr::` we first run our 'model of interest'. In this case it's a 46 | random-intercepts [multilevel model](#multilevel-models). We can verify `x` is 47 | unrelated to outcome with `lmerTest::anova`: 48 | 49 | ```{r} 50 | library(lmerTest) 51 | model.of.interest <- lmer(y ~ x + (1|g), data=simulated.df) 52 | anova(model.of.interest) 53 | ``` 54 | 55 | The next step is to modify our saved model of interest. We tweak the fitted 56 | parameters to represent our predicted values for effect sizes, variances, and 57 | covariances. 58 | 59 | First, let's change the 'true' effect of `x` to be 0.2: 60 | 61 | ```{r} 62 | fixef(model.of.interest)['x'] <- .2 63 | ``` 64 | 65 | We now use the `powerSim` function to use our tweaked model to: 66 | 67 | - create a dataset using the parameters of our model (i.e. make random draws 68 | of `y` which relate to `g` and `x` as specified in the model summary). 69 | - re-run `lmer` on this simulated data. 70 | - repeat this hundreds or thousands of times 71 | - count how many times (i.e., for what proportion) we get a significant _p_ 72 | value 73 | 74 | ```{r include=F, echo=T} 75 | power.sim <- powerSim(model.of.interest, nsim=100) 76 | ``` 77 | 78 | ```{r} 79 | power.sim 80 | ``` 81 | 82 | Our observed power (proportion of times we get a significant _p_ value) is very 83 | low here, so we might want increase our hypothesised effect of `x`, for example 84 | to see what power we have to detect an effect of x = .8: 85 | 86 | ```{r} 87 | fixef(model.of.interest)['x'] <- .8 88 | ``` 89 | 90 | ```{r include=F, echo=T} 91 | power.sim <- powerSim(model.of.interest, nsim=100) 92 | ``` 93 | 94 | ```{r} 95 | power.sim 96 | ``` 97 | 98 | We might also want to set one of the variance parameters of our model to 99 | represent clustering within-`g`. First we can use `VarCorr()` to check the 100 | variance parameters of the model we just ran: 101 | 102 | ```{r} 103 | VarCorr(model.of.interest) 104 | ``` 105 | 106 | And we could simulate increasing the variance parameter for `g` to 0.5: 107 | 108 | ```{r} 109 | VarCorr(model.of.interest)['g'] <- .5 110 | ``` 111 | 112 | ```{r include=F, echo=T} 113 | power.sim <- powerSim(model.of.interest, nsim=100) 114 | ``` 115 | 116 | ```{r} 117 | power.sim 118 | ``` 119 | 120 | Because the amount of clustering in our data has increased our statistical power 121 | has gone down. This is because, when clustering is present, each new observation 122 | (row) in the dataset provides less new _information_ to estimate our treatment 123 | effect. Note that in this example we increased the variance associated with `g` 124 | by quite a lot: setting the variance of `g` to 0.5 equates to an ICC for `g` of 125 | .33 (because .5 / (.5 + 1) = .33; see the section on [calculating ICCs and 126 | VPCs]{#icc-and-vpc}) 127 | 128 | For more details of `simr` see: 129 | http://onlinelibrary.wiley.com/doi/10.1111/2041-210X.12504/full 130 | 131 | [Note that for real applications you would want to set `nsim` to something 132 | reasonably large. Certainly at least 1000 simulations, and perhaps up to 133 | ~5000.]{.admonition} 134 | -------------------------------------------------------------------------------- /preamble.tex: -------------------------------------------------------------------------------- 1 | \usepackage{booktabs} 2 | \usepackage{amsthm} 3 | \makeatletter 4 | \def\thm@space@setup{% 5 | \thm@preskip=8pt plus 2pt minus 4pt 6 | \thm@postskip=\thm@preskip 7 | } 8 | \makeatother 9 | -------------------------------------------------------------------------------- /quirks.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Quirks' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | library(tufte) 8 | library(pander) 9 | ``` 10 | 11 | # Dealing with quirks of R {#quirks} 12 | 13 | ## Rownames are evil {- #rownames} 14 | 15 | Historically 'row names' were used on R to label individual rows in a dataframe. 16 | It turned out that this is generally a bad idea, because sorting and some 17 | summary functions would get very confused and mix up row names and the data 18 | itself. 19 | 20 | It's now considered best practice to avoid row names for this reason. 21 | Consequently, the functions in the `dplyr` library remove row names when 22 | processing dataframes. For example here we see the row names in the `mtcars` 23 | data: 24 | 25 | ```{r} 26 | mtcars %>% 27 | head(3) 28 | ``` 29 | 30 | But here we don't because `arrange` has stripped them: 31 | 32 | ```{r} 33 | mtcars %>% 34 | arrange(mpg) %>% 35 | head(3) 36 | ``` 37 | 38 | Converting the results of `psych::describe()` also returns rownames, which can 39 | get lots if we sort the data. 40 | 41 | We see row names here: 42 | 43 | ```{r} 44 | psych::describe(mtcars) %>% 45 | as_data_frame() %>% 46 | head(3) 47 | ``` 48 | 49 | But not here (just numbers in their place): 50 | 51 | ```{r} 52 | psych::describe(mtcars) %>% 53 | as_data_frame() %>% 54 | arrange(mean) %>% 55 | head(3) 56 | ``` 57 | 58 | ##### Preserving row names {-} 59 | 60 | If you want to preserve row names, it's best to convert the names to an extra 61 | colum in the data. So, the example below does what we probably want: 62 | 63 | ```{r} 64 | # the var='car.name' argument is optional, but can be useful 65 | mtcars %>% 66 | rownames_to_column(var="car.name") %>% 67 | arrange(mpg) %>% 68 | head(3) 69 | ``` 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | ```{r} 89 | lm(mpg~wt, data=mtcars) %>% 90 | broom::tidy() %>% 91 | pander 92 | ``` 93 | -------------------------------------------------------------------------------- /real-data.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Real data' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | knitr::opts_chunk$set(echo = TRUE, collapse=TRUE, cache=F, message=F, warning=F) 7 | library(tufte) 8 | library(tidyverse) 9 | library(broom) 10 | library(pander) 11 | ``` 12 | 13 | # 'Real' data {#real-data} 14 | 15 | _Note: If you already lucky enough to have nicely formatted data, ready for use 16 | in R, then you could skip this section and revisit it later,_ save for the 17 | section on [factors and other variable types](#factors-and-numerics). 18 | 19 | Most tutorials and textbooks use neatly formatted example datasets to illustrate 20 | particular techniques. However in the real-world our data can be: 21 | 22 | - In the wrong format 23 | - Spread across multiple files 24 | - Badly coded, or with errors 25 | - Incomplete, with values missing for many different reasons 26 | 27 | This chapter will give you techniques to address each of these problems. 28 | -------------------------------------------------------------------------------- /references.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'References' 3 | --- 4 | 5 | # References {-} 6 | -------------------------------------------------------------------------------- /requirements.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | # see https://github.com/s-u/PKI/issues/17 4 | install.packages('PKI',,'http://www.rforge.net/') 5 | 6 | # Install other packages often used 7 | pkgs <- c( 8 | 'AER', 9 | 'afex', 10 | 'apa', 11 | 'apaTables', 12 | 'arm', 13 | 'blme', 14 | 'bookdown', 15 | 'brms', 16 | 'broom', 17 | 'car', 18 | 'caret', 19 | 'coin', 20 | 'corrgram', 21 | 'cowplot', 22 | 'data.table', 23 | 'devtools', 24 | 'DAAG', 25 | 'DiagrammeR', 26 | 'DiagrammeRsvg', 27 | 'ez', 28 | 'gapminder', 29 | 'GGally', 30 | 'granova', 31 | 'ggthemes', 32 | 'ggrepel', 33 | 'gridExtra', 34 | 'haven', 35 | 'Hmisc', 36 | 'ggjoy', 37 | 'knitr', 38 | 'lavaan', 39 | 'lmerTest', 40 | 'lsr', 41 | 'lubridate', 42 | 'margins', 43 | 'mediation', 44 | 'merTools', 45 | 'mi', 46 | 'mice', 47 | 'multcomp', 48 | 'MuMIn', 49 | 'pander', 50 | 'png', 51 | 'psych', 52 | 'pwr', 53 | 'repmis', 54 | 'reshape2', 55 | 'rgl', 56 | 'rsvg', 57 | 'semPlot', 58 | 'servr', 59 | 'simr', 60 | 'statcheck', 61 | 'tidyverse', 62 | 'tufte', 63 | 'waffle' 64 | ) 65 | 66 | install.packages(pkgs) 67 | 68 | 69 | 70 | devtools::install_github("ropenscilabs/skimr") 71 | devtools::install_github('ralfer/apa_format_and_misc', subdir='apastats') 72 | -------------------------------------------------------------------------------- /reshaping-video.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Reshaping video' 3 | --- 4 | 5 | In this video I'll show some useful ways to reshape data, and to create 6 | summaries of data in the process. 7 | 8 | Before we start I'll just load a few packages that we'll use later. 9 | 10 | ```{r} 11 | library(tidyverse) 12 | library(pander) 13 | library(reshape2) 14 | library(gapminder) 15 | ``` 16 | 17 | So the simplest case is that we have some data in a wide format, and we want to 18 | make them long-form. 19 | 20 | When we have long format data, perhaps for a repeated measures experiment: 21 | 22 | - each row of the dataframe corresponds to a single measurement occasion 23 | - each column corresponds to a variable which is measured 24 | 25 | So - let's take the sleepstudy example. We might have a wide version of it where 26 | each person represents a row, and each column represents their reaction time, 27 | measured over 9 days. 28 | 29 | ```{r} 30 | (sleep.wide <- readRDS('data/sleep.wide.RDS')) 31 | ``` 32 | 33 | OK - so we don't want it in this format, and we'd prefer it in long form where 34 | we have 35 | 36 | - Multiple rows per person 37 | - One column called `reaction time` or something similar: 38 | 39 | To do this we can use the melt function. 40 | 41 | But that hasn't done what we might have wanted... We now have only two columns: 42 | variable and value... We can see our RTs towards the end of the dataframe if we 43 | page through, but the Subject column has also been melted, but we didn't want 44 | that. 45 | 46 | ```{r} 47 | sleep.wide %>% melt 48 | ``` 49 | 50 | What we need to do is to tell melt which is the identifying variable or 51 | `id.var`. This creates the data we want, and we can also rename the variable if 52 | we want. 53 | 54 | ```{r} 55 | sleep.long <- sleep.wide %>% 56 | melt(id.var="Subject") %>% 57 | rename(RT=value) 58 | 59 | sleep.long 60 | ``` 61 | 62 | To go back the other way we can use the `dcast` function. 63 | 64 | This way we get a column per day - the variable name to the left of the tilde 65 | symbol becomes the rows, and the one on the right gets turned into columns. 66 | 67 | ```{r} 68 | sleep.long %>% 69 | dcast(Subject~variable) 70 | ``` 71 | 72 | If we reverse them we get one-column per Subject 73 | 74 | ```{r} 75 | sleep.long %>% 76 | dcast(Subject~variable) 77 | ``` 78 | 79 | Ok - that's it. Have a practice yourself. 80 | -------------------------------------------------------------------------------- /reshaping.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Reshaping 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | knitr::opts_chunk$set(echo = TRUE, collapse=TRUE, cache=TRUE, message=F, warning=F) 7 | library(tidyverse) 8 | library(tufte) 9 | library(pander) 10 | ``` 11 | 12 | ## Reshaping {- #reshaping} 13 | 14 | 16 | 17 | This section will probably require more attention than any other in the guide, 18 | but will likely be one of the most useful things you learn in R. 19 | 20 | As previously discussed, most things work best in R if you have data in _long 21 | format_. This means we prefer data that look like this: 22 | 23 | ```{r, echo=F} 24 | d <- expand.grid(person=1:3, time=paste("Time", 1:4)) %>% 25 | mutate(outcome = rnorm(n(), 20, 3)) 26 | d %>% pander 27 | ``` 28 | 29 | And NOT like this: 30 | 31 | ```{r, echo=F} 32 | d %>% 33 | reshape2::dcast(person~time, value.var = "outcome") %>% 34 | pander 35 | ``` 36 | 37 | In long format data: 38 | 39 | - each row of the dataframe corresponds to a single measurement occasion 40 | - each column corresponds to a variable which is measured 41 | 42 | Fortunately it's fairly easy to move between the two formats, provided your 43 | variables are named in a consistent way. 44 | 45 | #### Wide to long format {- #wide-to-long} 46 | 47 | This is the most common requirement. Often you will have several columns which 48 | actually measure the same thing, and you will need to convert these two two 49 | columns - a 'key', and a value. 50 | 51 | For example, let's say we measure patients on 10 days: 52 | 53 | ```{r, include=F} 54 | sleep.wide <- lme4::sleepstudy %>% 55 | reshape2::dcast(Subject~paste0("Day.", Days), value.var = "Reaction") %>% 56 | mutate(Subject=as.numeric(Subject)) %>% 57 | arrange(Subject) 58 | 59 | saveRDS(sleep.wide, 'data/sleep.wide.RDS') 60 | ``` 61 | 62 | ```{r} 63 | sleep.wide %>% 64 | head(4) %>% 65 | pander(caption="Data for the first 4 subjects") 66 | ``` 67 | 68 | We want to convert RT measurements on each Day to a single variable, and create 69 | a new variable to keep track of what `Day` the measurement was taken: 70 | 71 | The `melt()` function in the `reshape2::` package does this for us: 72 | 73 | ```{r} 74 | library(reshape2) 75 | sleep.long <- sleep.wide %>% 76 | melt(id.var="Subject") %>% 77 | arrange(Subject, variable) 78 | 79 | sleep.long %>% 80 | head(12) %>% 81 | pander 82 | ``` 83 | 84 | ```{r include=F} 85 | saveRDS(sleep.long, 'data/sleep.long.RDS') 86 | ``` 87 | 88 | Here melt has created two new variable: `variable`, which keeps track of what 89 | was measured, and `value` which contains the score. This is the format we need 90 | when [plotting graphs](#graphics) and running 91 | [regression and Anova models](#linear-models-simple). 92 | 93 | #### Long to wide format {- #long-to-wide} 94 | 95 | To continue the example from above, these are long form data we just made: 96 | 97 | ```{r} 98 | sleep.long %>% 99 | head(3) %>% 100 | pander(caption="First 3 rows in the long format dataset") 101 | ``` 102 | 103 | We can convert these back to the original wide format using `dcast`, again in 104 | the `reshape2` package. The name of the `dcast` function indicates we can 'cast' 105 | a dataframe (the d prefix). So here, casting means the opposite of 'melting'. 106 | 107 | Using `dcast` is a little more fiddly than `melt` because we have to say _how_ 108 | we want the data spread wide. In this example we could either have: 109 | 110 | - Columns for each day, with rows for each subject 111 | - Columns for each subject, with rows for each day 112 | 113 | Although it's obvious to _us_ which format we want, we have to be explicit for R 114 | to get it right. 115 | 116 | We do this using a [formula](#formulae), which we'll see again in the regression 117 | section. 118 | 119 | Each formula has two sides, left and right, separated by the tilde (`~`) symbol. 120 | On the left hand side we say which variable we want to keep in rows. On the 121 | right hand side we say which variables to convert to columns. So, for example: 122 | 123 | ```{r} 124 | # rows per subject, columns per day 125 | sleep.long %>% 126 | dcast(Subject~variable) %>% 127 | head(3) 128 | ``` 129 | 130 | To compare, we can convert so each Subject has a column by reversing the 131 | formula: 132 | 133 | ```{r} 134 | # note we select only the first 7 Subjects to 135 | # keep the table to a manageable size 136 | sleep.long %>% 137 | filter(Subject < 8) %>% 138 | dcast(variable~Subject) 139 | ``` 140 | 141 | ###### {- .tip} 142 | 143 | One neat trick when casting is to use `paste` to give your columns nicer names. 144 | So for example: 145 | 146 | ```{r} 147 | sleep.long %>% 148 | filter(Subject < 4) %>% 149 | dcast(variable~paste0("Person.", Subject)) 150 | ``` 151 | 152 | Notice we used `paste0` rather than `paste` to avoid spaces in variable names, 153 | which is allowed but can be a pain. 154 | [See more on working with character strings in a later section](#string-handling). 155 | 156 | ##### {-} 157 | 158 | For a more detailed explanation and various other methods for reshaping data, 159 | see: http://r4ds.had.co.nz/tidy-data.html 160 | 161 | ### Which package should you use to reshape data? {- #which-reshape-package} 162 | 163 | There are three main options: 164 | 165 | - `tidyr::`, which comes as part of the `tidyverse`, using `gather` and 166 | `spread()` 167 | - `reshape2::` using `melt()` and `dcast()` 168 | - `data.table::` also using functions called `melt()` and `dcast()` (but which 169 | are slightly different from those in `reshape2`) 170 | 171 | This post walks through some of the differences: 172 | https://www.r-bloggers.com/how-to-reshape-data-in-r-tidyr-vs-reshape2/ but the 173 | short answer is whichever you find simplest and easiest to remember (for me 174 | that's `melt` and `dcast`). 175 | 176 | ` 177 | 178 | ### Aggregating and reshaping at the same time {-} 179 | 180 | One common trick when reshaping is to convert a datafile which has multiple rows 181 | and columns per person to one with only a single row per person. That is, we 182 | aggregae by using a summary (perhaps the mean) and reshape at the same time. 183 | 184 | Although useful this isn't covered in this section, because it is combining two 185 | techniques: 186 | 187 | - Reshaping (i.e. from long to wide or back) 188 | - Aggregating or summarising (converting multiple rows to one) 189 | 190 | In the next section we cover [summarising data](#summarising-data), and 191 | introduce the 'split-apply-combine' method for summarising. 192 | 193 | Once you have a good grasp of this, you could check out the 194 | ['fancy reshaping' section](#fancy-reshaping) which does provide examples of 195 | aggregating and reshaping simultaneously. 196 | -------------------------------------------------------------------------------- /scaling-predictors.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Scaling predictors' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | library(pander) 8 | ``` 9 | 10 | # Scaling predictor variables {#scaling-predictors} 11 | 12 | ![Image: [Wikimedia][1]](media/Holding_the_eiffel_tower.jpg) 13 | 14 | [1]: 15 | https://commons.wikimedia.org/wiki/File:Holding_the_eiffel_tower_(4114302348).jpg 16 | 17 | When predictors have a natural scale, interpreting them can be relatively 18 | straightforward. However when predictors are on an arbitrary scale, or when 19 | multiple predictors are on different scales, then interpreting the model (or 20 | comparing between models) can be hard. In these cases scaling or standardising 21 | predictors in the model can make it easier to interpret the coefficients that 22 | are estimated. 23 | 24 | ### Standardising {- #standardizing} 25 | 26 | 'Standardising' predictors, by subtracting the mean and dividng by the standard 27 | deviation, is a common way to make interpreting regression models easier, and 28 | particularly to make comparisons between predictors --- e.g. regarding their 29 | relative importance in predicting the outcome. 30 | 31 | @gelman*scaling_2008 covers in detail the advantages and disadvantages of 32 | standardising regression coefficients. Based on the observation that we often 33 | wish to compare continuous with binary predictors, they recommend 34 | standardisation by subtracting the mean and dividing by \_two* standard 35 | deviations (rather thant the normal one SD). The `arm` package implements this 36 | procedure, and makes it easy to automatically scale the predictors in a linear 37 | model. 38 | 39 | First, we run the linear model: 40 | 41 | ```{r} 42 | m1 <- lm(mpg ~ wt + am, data=mtcars) 43 | m1 44 | ``` 45 | 46 | And then use `arm::standardize` to standardize the coefficients: 47 | 48 | ```{r} 49 | arm::standardize(m1) 50 | ``` 51 | 52 | This automatically scales the data for `m1` and re-fits the model. 53 | 54 | An alternative is to use the `MuMIn::stdizeFit` although this applies scaling 55 | rules slightly differently to `arm`, in this case standardising by a single SD: 56 | 57 | ```{r} 58 | MuMIn::stdizeFit(m1, mtcars) 59 | ``` 60 | 61 | Check the help file for `MuMIn::stdize` for a detailed discussion of the 62 | differences with `arm::standardize`. 63 | 64 | ### Dichotomising continuous predictors (or outcomes) {- #dichotomising} 65 | 66 | Dichotomising a continuous scale is almost always a bad idea. Although it is 67 | sometimes done to aid interpretation or presentation, there are better 68 | alternatives (for example estimating means from a model using Stata's `margins` 69 | command and plotting them, something we will do in the next session). As the 70 | Cochrane collaboration puts it: 71 | 72 | > The down side of converting other forms of data to a dichotomous form is that 73 | > information about the size of the effect may be lost. For example a 74 | > participant's blood pressure may have lowered when measured on a continuous 75 | > scale (mmHg), but if it has not lowered below the cut point they will still be 76 | > in the 'high blood pressure group' and you will not see this improvement. In 77 | > addition the process of dichotomising continuous data requires the setting of 78 | > an appropriate clinical point about which to 'split' the data, and this may 79 | > not be easy to determine. 80 | 81 | See and also 82 | @peacock_dichotomising_2012. Also note that trichotomising (splitting into 3) is 83 | likely to be a better better/more efficient approach, see @gelman2009splitting. 84 | -------------------------------------------------------------------------------- /set_chunk_options.R: -------------------------------------------------------------------------------- 1 | knitr::opts_chunk$set(echo = TRUE, collapse=TRUE, cache=TRUE, comment=NA) -------------------------------------------------------------------------------- /sharing-and-publishing.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Sharing and publishing analyses' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | library(lmerTest) 8 | library(apastats) 9 | ``` 10 | 11 | # Sharing, publishing and archiving {#sharing-and-publication} 12 | 13 | RMarkdown is an excellent format to collaborate on with other people. Because 14 | it's plain text it works well with version control systems like git (e.g. using 15 | ). 16 | 17 | You can also knit documents into formats that journals and 18 | 19 | ### Tips for dead tree journals {- #publication} 20 | 21 | - Save graphics to .pdf format. 22 | 23 | - Use RMarkdown documents to create supplementary online files or appendices 24 | for published papers. 25 | 26 | - Wait until you're an expert to 27 | [try writing the whole paper in RMarkdown (e.g. with citeproc)](https://kieranhealy.org/blog/archives/2014/01/23/plain-text/). 28 | 29 | ### Registering your predictions {- #register-predictions} 30 | 31 | An RMarkdown file which produced simulated data to illustrate your predictions, 32 | and then run the analysis you propose, would be an excellent document to upload 33 | to a service like 34 | -------------------------------------------------------------------------------- /simplifying-and-reusing.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Simplifying and re-using' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | ``` 8 | 9 | ## Simplifying and re-using {- #code-reuse} 10 | 11 | Complex programming is beyond the scope of this guide, but if you sometimes find 12 | yourself repeating the same piece of code over and over then it might be worth 13 | writing a simple function. 14 | 15 | The examples shown in this book are mostly very simple, and are typically not 16 | repetitive. However in running your own analyses you may find that you start to 17 | repeat chunks of code in a number of places (even across many files). 18 | 19 | Not only is this sort of copying-and-pasting tedious, it can be hard to read and 20 | maintain. For example, if you are repeating the same analysis for multiple 21 | variables and discover an error in your calculations you would have to fix this 22 | is in multiple places in your code. You can also introduce errors when copying 23 | and pasting code in this way, and these can be hard to spot. 24 | 25 | The sorts of tasks which can end up being repetitive include: 26 | 27 | - Running models 28 | - Extracting results from models you run 29 | - Producing tables 30 | - Specifying output settings for graphs 31 | 32 | In these cases it might be worth writing your own function to facilitate this 33 | repetition, or use some other forms of code re-use (e.g. see the 34 | [example for `ggplot` graphics below](#ggplot-reuse)). 35 | 36 | ### Writing helper functions {- #helper-functions} 37 | 38 | For example, in the section on logistic regression 39 | [we wrote a helper function called `logistic()`](#helper-function-logistic) 40 | which was simply a shortcut for `glm()` but with the correct 'family' argument 41 | pre-specified. 42 | 43 | For more information on writing your own R functions I recommend 44 | [Hadley Wickham's 'R for Data Scientists', chapter 19](http://r4ds.had.co.nz/functions.html) 45 | and, if necessary, 46 | ['Advanced R': http://adv-r.had.co.nz](http://adv-r.had.co.nz). 47 | 48 | Or you prefer a book, try @grolemund2014hands. 49 | 50 | ### Re-using code with `ggplot` {- #ggplot-reuse} 51 | 52 | Another common case where we might want to re-use code is when we produce a 53 | number of similar plots, and where we might want to re-use many of the same 54 | settings. 55 | 56 | Sometimes repeating plots is best achieved by creating a single long-form 57 | dataframe and [facetting the plot](#facetting-plots). However this may not 58 | always be possible or desireable. Lets say we have two plots like these: 59 | 60 | ```{r} 61 | plot.mpg <- mtcars %>% 62 | ggplot(aes(factor(cyl), mpg)) + 63 | geom_boxplot() 64 | 65 | plot.wt <- mtcars %>% 66 | ggplot(aes(factor(cyl), wt)) + 67 | geom_boxplot() 68 | ``` 69 | 70 | And we want to add consistent labels and other settings to them. We can simply 71 | type: 72 | 73 | ```{r} 74 | myplotsettings <- xlab("Number of cylinders") 75 | ``` 76 | 77 | And then we simply add (`+`) these settings to each plot: 78 | 79 | ```{r} 80 | plot.mpg + myplotsettings 81 | ``` 82 | 83 | And: 84 | 85 | ```{r} 86 | plot.wt + myplotsettings 87 | ``` 88 | 89 | This reduces typing and makes easier to produce a consistent set of plots. 90 | -------------------------------------------------------------------------------- /string-handling.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Working with character strings' 3 | --- 4 | 5 | ## Working with character strings {- #string-handling} 6 | 7 | ```{r, include=FALSE} 8 | library(tidyverse) 9 | library(tufte) 10 | library(pander) 11 | library(reshape2) 12 | ``` 13 | 14 | ### Searching and replacing 15 | 16 | If you want to search inside a string there are lots of useful functions in the 17 | `stringr::` library. These replicate some functionality in base R, but like 18 | other packages in the 'tidyverse' they tend to be more consistent and easier to 19 | use. For example: 20 | 21 | ```{r} 22 | cheese <- c("Stilton", "Brie", "Cheddar") 23 | stringr::str_detect(cheese, "Br") 24 | stringr::str_locate(cheese, "i") 25 | stringr::str_replace(cheese, "Stil", "Mil") 26 | ``` 27 | 28 | ### Using `paste` to make labels {- #paste} 29 | 30 | Paste can combine character strings with other types of variable to produce a 31 | new vector: 32 | 33 | ```{r} 34 | paste(mtcars$cyl, "cylinders")[1:10] 35 | ``` 36 | 37 | Which can be a useful way to label graphs: 38 | 39 | ```{r} 40 | mtcars %>% 41 | ggplot(aes(paste(mtcars$cyl, "cylinders"), mpg)) + 42 | geom_boxplot() + xlab("") 43 | ``` 44 | 45 | ### Fixing up `variable` after melting {- #separate-and-extract} 46 | 47 | In this example `melt()` creates a new column called `variable`. 48 | 49 | ```{r, include=F} 50 | sleep.wide <- readRDS('data/sleep.wide.RDS') 51 | ``` 52 | 53 | ```{r} 54 | sleep.wide %>% 55 | melt(id.var="Subject") %>% 56 | arrange(Subject, variable) %>% 57 | head 58 | ``` 59 | 60 | However the contents of `variable` are now a character string (i.e. a list of 61 | letters and numbers) rather than numeric values (see 62 | [column types](#factors-and-numerics)) but in this instance we know that the 63 | values `Day.1`, `Day.2`... are not really separate categories but actually form 64 | a linear sequence, from 1 to 9. 65 | 66 | We can use the `extract` or `separate` functions to split up `variable` and 67 | create a numeric column for `Day`: 68 | 69 | ```{r include=F} 70 | sleep.long <- readRDS('data/sleep.long.RDS') 71 | ``` 72 | 73 | ```{r} 74 | sleep.long %>% 75 | separate(variable, c("variable", "Day")) %>% 76 | mutate(Day=as.numeric(Day)) %>% 77 | arrange(Subject) %>% 78 | head %>% pander 79 | ``` 80 | 81 | See the user guide for `separate` and `extract` for more details. 82 | 83 | [If you are familiar with 84 | [regular expressions](https://code.tutsplus.com/tutorials/you-dont-know-anything-about-regular-expressions-a-complete-guide--net-7869) 85 | you will be happy to know that you can use regex to separate variables using 86 | `extract` and `separate`. 87 | [See this guide for more details on how `separate` and `extract` work](https://rpubs.com/bradleyboehmke/data_wrangling)]{.explainer} 88 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | .caption { font-style: italic; font-size: .8em; } 2 | 3 | .admonition { 4 | background-color: #FFFD75; 5 | padding:2em; 6 | display:block; 7 | min-height: 100px; 8 | margin: 0 2em 2em 1em; 9 | background: linear-gradient(top, rgba(0,0,0,.05), rgba(0,0,0,.25)); 10 | box-shadow: 5px 5px 10px -2px rgba(33,33,33,.3); 11 | transform: rotate(1deg); 12 | transform: skew(-.05deg,.05deg); 13 | } 14 | .apa-example { 15 | background-color: #ADCBE7; 16 | padding:2em; 17 | display:block; 18 | min-height: 100px; 19 | margin: 0 2em 2em 1em; 20 | background: linear-gradient(top, rgba(0,0,0,.05), rgba(0,0,0,.25)); 21 | box-shadow: 5px 5px 10px -2px rgba(33,33,33,.3); 22 | transform: rotate(1deg); 23 | transform: skew(-.05deg,.05deg); 24 | } 25 | 26 | .apa-example:before { 27 | content: "APA style example: "; 28 | font-weight: bold; 29 | } 30 | 31 | 32 | .exercise { 33 | background-color: #C4EFE4; 34 | padding:2em; 35 | display:block; 36 | min-height: 100px; 37 | margin: 0 2em 2em 1em; 38 | background: linear-gradient(top, rgba(0,0,0,.05), rgba(0,0,0,.25)); 39 | box-shadow: 5px 5px 10px -2px rgba(33,33,33,.3); 40 | transform: rotate(1deg); 41 | transform: skew(-.05deg,.05deg); 42 | } 43 | 44 | .exercise:before { 45 | content: "Exercise: "; 46 | font-weight: bold; 47 | margin-bottom: .5em; 48 | } 49 | 50 | 51 | 52 | 53 | 54 | .explainer { 55 | background-color: #E6E6E6; 56 | width:90%; 57 | padding:2em; 58 | display:block; 59 | min-height: 100px; 60 | margin: 0 2em 2em 1em; 61 | background: linear-gradient(top, rgba(0,0,0,.05), rgba(0,0,0,.25)); 62 | box-shadow: 5px 5px 10px -2px rgba(33,33,33,.3); 63 | transform: rotate(1deg); 64 | transform: skew(-.05deg,.05deg); 65 | } 66 | 67 | 68 | 69 | 70 | .tip { 71 | background-color: #C3FDB2; 72 | width:90%; 73 | padding:2em; 74 | display:block; 75 | min-height: 100px; 76 | margin: 0 2em 2em 1em; 77 | background: linear-gradient(top, rgba(0,0,0,.05), rgba(0,0,0,.25)); 78 | box-shadow: 5px 5px 10px -2px rgba(33,33,33,.3); 79 | transform: rotate(1deg); 80 | transform: skew(-.05deg,.05deg); 81 | } 82 | 83 | 84 | 85 | 86 | table { margin-bottom: 2em !important; } 87 | 88 | 89 | .cup { width:20em !important; } 90 | 91 | .small-image { width: 33%; } 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /summarising-data.Rmd: -------------------------------------------------------------------------------- 1 | -- title: 'Summarising data' 2 | 3 | --- 4 | 5 | # Summaries {#summarising-data} 6 | 7 | ```{r, include=FALSE, message=F} 8 | library(tidyverse) 9 | library(pander) 10 | angry.moods <- read_csv('data/angry_moods.csv') 11 | ``` 12 | 13 | Before you begin this section, make sure you have fully understood the section 14 | on [datasets and dataframes](datasets.html), and in particular that you are 15 | happy using the `%>%` symbol to [describe a flow of data](#pipes). 16 | 17 | Although R contains many functions like `table`, or `xtabs`, `describe` or 18 | `summarise` which you might see used elsewhere to tabulate or summarise data, 19 | for beginners these base-R functions can be confusing; their names and input 20 | names are not always consistent, and they don't always work together nicely. 21 | 22 | Instead we recommend using `dplyr` and other parts of the tidyverse because they 23 | provide a general set of tools to make any kind of table or summary. 24 | 25 | They also encourage more coherent thinking about _what summary is really 26 | needed_, rather than accepting or fighting with default options. 27 | 28 | ## A generalised approach {- #dplyr-general} 29 | 30 | #### The 'split, apply, combine' model {- #split-apply-combine} 31 | 32 | The `dplyr::` package, and especially the `summarise()` function provides a 33 | generalised way to create dataframes of frequencies and other summary 34 | statistics, grouped and sorted however we like. 35 | 36 | **Each of the `dplyr` 'verbs' acts on a dataframe in some way, and returns a 37 | dataframe as it's result. This is convenient because we can chain together the 38 | different verbs to describe exactly the table we want.** 39 | 40 | For example, let's say we want the mean of some of our variables across the 41 | whole dataframe: 42 | 43 | ```{r} 44 | angry.moods %>% 45 | summarise( 46 | mean.anger.out=mean(Anger.Out), 47 | sd.anger.out=sd(Anger.Out) 48 | ) 49 | ``` 50 | 51 | :::{.explainer} 52 | 53 | Here the `summarise` function accepts the `angry.moods` dataframe as an input, 54 | and has returned a dataframe containing the statistics we need. In this instance 55 | the result dataframe only has one row. 56 | 57 | ::: 58 | 59 | What if we want the numbers for men and women separately? 60 | 61 | The key is to think about what we want to achieve, and work out how to describe 62 | it. However, in general, we will often want to follow this pattern: 63 | 64 | - _Split_ our data (into men and women, or some other categorisation) 65 | - _Apply_ some operation (function) to each group individually (e.g. calculate 66 | the mean) 67 | - _Combine_ it into a single table again 68 | 69 | It's helpful to think of this _split $\rightarrow$ apply $\rightarrow$ combine_ 70 | pattern whenever we are processing data because it _makes explicit what we want 71 | to do_. 72 | 73 | #### Split: breaking the data into groups {-} 74 | 75 | The first task is to organise our dataframe into the relevant groups. To do this 76 | we use `group_by()`: 77 | 78 | ```{r} 79 | angry.moods %>% 80 | group_by(Gender) %>% 81 | glimpse 82 | ``` 83 | 84 | Weirdly, this doesn't seem to have done anything. The data aren't sorted by 85 | `Gender`, and there is no visible sign of the grouping, but stick with it... the 86 | grouping is there and the effect will be clearer in a moment. 87 | 88 | #### Apply and combine {-} 89 | 90 | Continuing the example above, once we have grouped our data we can then _apply_ 91 | a function to it — for example, we can summarise each group by taking the mean 92 | of the `Anger.Out` variable: 93 | 94 | ```{r} 95 | angry.moods %>% 96 | group_by(Gender) %>% 97 | summarise( 98 | mean.anger.out=mean(Anger.Out) 99 | ) 100 | ``` 101 | 102 | The **combine** step happens automatically for us: `dplyr` has combined the 103 | summaries of each gender into a single dataframe for us. 104 | 105 | In summary, we: 106 | 107 | - _split_ the data by `Gender`, using `group_by()` 108 | - _apply_ the `summarise()` function 109 | - _combine_ the results into a new data frame (happens automatically) 110 | 111 | #### A 'real' example {-} 112 | 113 | Imagine we have raw data from a study which had measured depression with the 114 | PHQ-9 scale. 115 | 116 | Each `patient` was measured on numerous occasions (the `month` of observation is 117 | recorded), and were split into treatment `group` (0=control, 1=treatment). The 118 | `phq9` variable is calculated as the sum of all their questionnaire responses. 119 | 120 | ```{r, mesage=F, echo=F, include=F} 121 | phq9.df <- readr::read_csv("data/phq9.csv") %>% 122 | mutate(phq9 = rowMeans( 123 | select(., starts_with("phq9_0")), na.rm=T 124 | )) %>% 125 | select(patient, group, month, phq9) %>% 126 | mutate(phq9=round(phq9, 2)) 127 | phq9.df 128 | write_csv(phq9.df, "data/phq-summary.csv") 129 | ``` 130 | 131 | ```{r} 132 | phq9.df %>% glimpse 133 | ``` 134 | 135 | If this were our data we might want to: 136 | 137 | - Calculate the average PHQ-9 score at each month, and in each group 138 | - Show these means by group for months 0, 7 and 12 139 | 140 | We can do this using `group_by` and `summarise`: 141 | 142 | ```{r} 143 | phq9.df %>% 144 | group_by(group) %>% 145 | summarise(average_phq9 = mean(phq9)) 146 | ``` 147 | 148 | :::{.exercise} 149 | 150 | You can load the PHQ9 data above by typing: 151 | 152 | ```{r} 153 | # remeber to load the tidyverse package first 154 | phq9 <- read_csv('data/phq-summary.csv') 155 | ``` 156 | 157 | Try to edit the code above to: 158 | 159 | - Create summary table with the mean at each month 160 | - The mean at each month, in each group 161 | - The mean and SD by month and group 162 | 163 | ::: 164 | -------------------------------------------------------------------------------- /t-tests.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 't-tests' 3 | --- 4 | 5 | ```{r, include=F} 6 | library(tidyverse) 7 | library(pander) 8 | panderOptions('digits', 2) 9 | panderOptions('round', 3) 10 | panderOptions('keep.trailing.zeros', TRUE) 11 | ``` 12 | 13 | ## t-tests {- #t-tests} 14 | 15 | ### Visualising your data first {-} 16 | 17 | Before you run any tests it's worth plotting your data. 18 | 19 | Assuming you have a continuous outcome and categorical (binary) predictor (here 20 | we use a subset of the built in `chickwts` data), a boxplot can work well: 21 | 22 | ```{r boxplot, fig.cap="The box in a boxplot indictes the IQR; the whisker indicates the min/max values or 1.5 \times the IQR, whichever is the smaller. If there are outliers beyond 1.5 \times the IQR then they are shown as points."} 23 | chicks.eating.beans <- chickwts %>% 24 | filter(feed %in% c("horsebean", "soybean")) 25 | 26 | chicks.eating.beans %>% 27 | ggplot(aes(feed, weight)) + 28 | geom_boxplot() 29 | ``` 30 | 31 | Or a violin or bottle plot, which shows the distributions within each group and 32 | makes it relatively easy to check some of the main assumptions of the test: 33 | 34 | ```{r} 35 | chicks.eating.beans %>% 36 | ggplot(aes(feed, weight)) + 37 | geom_violin() 38 | ``` 39 | 40 | Layering boxes and bottles can work well too because it combines information 41 | about the distribution with key statistics like the median and IQR, and also 42 | because it scales reasonably well to multiple categories: 43 | 44 | ```{r} 45 | chickwts %>% 46 | ggplot(aes(feed, weight)) + 47 | geom_violin() + 48 | geom_boxplot(width=.1) 49 | ``` 50 | 51 | 70 | 71 | ### Running a t-test {-} 72 | 73 | Assuming you really do still want to run a null hypothesis test on one or two 74 | means, the `t.test()` function performs most common variants, illustrated below. 75 | 76 | ##### 2 independent groups {-} 77 | 78 | Assuming your data are in long format: 79 | 80 | ```{r} 81 | t.test(weight ~ feed, data=chicks.eating.beans) 82 | ``` 83 | 84 | Or equivalently, if your [data are untidy](#tidying-data) and each group has 85 | it's own column (e.g. chicks eating soybeans in one column and those eating 86 | horsebeans in another): 87 | 88 | ```{r, include=F} 89 | untidy.chicks <- chicks.eating.beans %>% 90 | mutate(chick = row_number()) %>% 91 | reshape2::dcast(chick~feed, value.var = 'weight') 92 | ``` 93 | 94 | ```{r} 95 | with(untidy.chicks, t.test(horsebean, soybean)) 96 | ``` 97 | 98 | ##### Equal or unequal variances? {- #equal-variances .admonition} 99 | 100 | By default R assumes your groups have unequal variances and applies an 101 | appropriate correction (you will notice the output labelled 'Welch Two Sample 102 | t-test'). 103 | 104 | You can turn this correction off (for example, if you're trying to replcate an 105 | analysis done using the default settings in SPSS) but you probably do want to 106 | assume unequal variances [see @ruxton2006unequal]. 107 | 108 | ##### Paired samples {-} 109 | 110 | If you have repeated measures on a sample you need a paired samples test. 111 | 112 | ```{r} 113 | # simulate paired samples in pre-post design 114 | set.seed(1234) 115 | baseline <- rnorm(50, 2.5, 1) 116 | followup = baseline + rnorm(50, .5, 1) 117 | 118 | # run paired samples test 119 | t.test(baseline, followup, paired=TRUE) 120 | ``` 121 | 122 | Note that we could also ['melt' the data into long format](#wide-to-long) and 123 | use the `paired=TRUE` argument with a formula: 124 | 125 | ```{r} 126 | long.form.data <- data_frame(baseline=baseline, follow=followup) %>% 127 | reshape2::melt() 128 | 129 | with(long.form.data, t.test(value~variable, paired=TRUE)) 130 | ``` 131 | 132 | ##### One-sample test {-} 133 | 134 | Sometimes you might want to compare a sample mean with a specific value: 135 | 136 | ```{r} 137 | # test if mean of `outcome` variable is different from 2 138 | set.seed(1234) 139 | test.scores <- rnorm(50, 2.5, 1) 140 | t.test(test.scores, mu=2) 141 | ``` 142 | -------------------------------------------------------------------------------- /tidy-data.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: '"Tidy" data' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | library(tufte) 8 | ``` 9 | 10 | ## Tidying data {- #tidyingdata} 11 | 12 | 'Tidying' data means converting it into the format that is most useful for data 13 | analyses, and so we have already covered many of the key techniques: selecting 14 | and filtering data, reshaping and summarising. 15 | 16 | However the ideas behind 'tidying' draw together other related concepts which 17 | link together the way we enter, store and process data: for example the idea of 18 | '[relational data]()' and techniques to join together related datasets. 19 | 20 | #### A philosophy of tidy data {-} 21 | 22 | The chapter on tidying in 'R for data science' is well worth reading for it's 23 | thoughtful explanation of why we want tidy data, and the core techniques to 24 | clean up untidy data: 25 | 26 | 27 | -------------------------------------------------------------------------------- /toc.css: -------------------------------------------------------------------------------- 1 | #TOC ul, 2 | #TOC li, 3 | #TOC span, 4 | #TOC a { 5 | margin: 0; 6 | padding: 0; 7 | position: relative; 8 | } 9 | #TOC { 10 | line-height: 1; 11 | border-radius: 5px 5px 0 0; 12 | background: #141414; 13 | background: linear-gradient(to bottom, #333333 0%, #141414 100%); 14 | border-bottom: 2px solid #0fa1e0; 15 | width: auto; 16 | } 17 | #TOC:after, 18 | #TOC ul:after { 19 | content: ''; 20 | display: block; 21 | clear: both; 22 | } 23 | #TOC a { 24 | background: #141414; 25 | background: linear-gradient(to bottom, #333333 0%, #141414 100%); 26 | color: #ffffff; 27 | display: block; 28 | padding: 19px 20px; 29 | text-decoration: none; 30 | text-shadow: none; 31 | } 32 | #TOC ul { 33 | list-style: none; 34 | } 35 | #TOC > ul > li { 36 | display: inline-block; 37 | float: left; 38 | margin: 0; 39 | } 40 | #TOC > ul > li > a { 41 | color: #ffffff; 42 | } 43 | #TOC > ul > li:hover:after { 44 | content: ''; 45 | display: block; 46 | width: 0; 47 | height: 0; 48 | position: absolute; 49 | left: 50%; 50 | bottom: 0; 51 | border-left: 10px solid transparent; 52 | border-right: 10px solid transparent; 53 | border-bottom: 10px solid #0fa1e0; 54 | margin-left: -10px; 55 | } 56 | #TOC > ul > li:first-child > a { 57 | border-radius: 5px 0 0 0; 58 | } 59 | #TOC.align-right > ul > li:first-child > a, 60 | #TOC.align-center > ul > li:first-child > a { 61 | border-radius: 0; 62 | } 63 | #TOC.align-right > ul > li:last-child > a { 64 | border-radius: 0 5px 0 0; 65 | } 66 | #TOC > ul > li.active > a, 67 | #TOC > ul > li:hover > a { 68 | color: #ffffff; 69 | box-shadow: inset 0 0 3px #000000; 70 | background: #070707; 71 | background: linear-gradient(to bottom, #262626 0%, #070707 100%); 72 | } 73 | #TOC .has-sub { 74 | z-index: 1; 75 | } 76 | #TOC .has-sub:hover > ul { 77 | display: block; 78 | } 79 | #TOC .has-sub ul { 80 | display: none; 81 | position: absolute; 82 | width: 200px; 83 | top: 100%; 84 | left: 0; 85 | } 86 | #TOC .has-sub ul li a { 87 | background: #0fa1e0; 88 | border-bottom: 1px dotted #31b7f1; 89 | filter: none; 90 | display: block; 91 | line-height: 120%; 92 | padding: 10px; 93 | color: #ffffff; 94 | } 95 | #TOC .has-sub ul li:hover a { 96 | background: #0c7fb0; 97 | } 98 | #TOC ul ul li:hover > a { 99 | color: #ffffff; 100 | } 101 | #TOC .has-sub .has-sub:hover > ul { 102 | display: block; 103 | } 104 | #TOC .has-sub .has-sub ul { 105 | display: none; 106 | position: absolute; 107 | left: 100%; 108 | top: 0; 109 | } 110 | #TOC .has-sub .has-sub ul li a { 111 | background: #0c7fb0; 112 | border-bottom: 1px dotted #31b7f1; 113 | } 114 | #TOC .has-sub .has-sub ul li a:hover { 115 | background: #0a6d98; 116 | } 117 | #TOC ul ul li.last > a, 118 | #TOC ul ul li:last-child > a, 119 | #TOC ul ul ul li.last > a, 120 | #TOC ul ul ul li:last-child > a, 121 | #TOC .has-sub ul li:last-child > a, 122 | #TOC .has-sub ul li.last > a { 123 | border-bottom: 0; 124 | } 125 | #TOC ul { 126 | font-size: 1.2rem; 127 | } 128 | -------------------------------------------------------------------------------- /troubles.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Troubleshooting' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | library(tidyverse) 7 | ``` 8 | 9 | # Common problems and troubleshooting {#troubles} 10 | 11 | ### Scaling inputs {- #scaling-regression-inputs} 12 | 13 | Sometimes you might come across error messages like these: 14 | 15 | ``` 16 | Warning messages: 1: Some predictor variables are on very different scales: consider rescaling 17 | 18 | Model is nearly unidentifiable: very large eigenvalue - Rescale variables?; 19 | 20 | Model is nearly unidentifiable: large eigenvalue ratio - Rescale variables? 21 | ``` 22 | 23 | Other similar messages might refer to 'convergence failure', e.g. for `lmer()` 24 | models. 25 | 26 | You should be aware that there are limits to the precision with which R (and 27 | computers in general) can store decimal values. This only tends to matter when 28 | working with very large or very small numbers — but this can crop up when 29 | estimating regression coefficients or (most often) variances that are extremely 30 | close to zero. 31 | 32 | If you have predictors and/or outcomes on very different scales you may also end 33 | up with very small regression coefficients, and this can make it harder for R to 34 | fit your model, or [for you to interpret it](#scaling-regression-inputs). 35 | 36 | #### Troubleshooting 37 | 38 | If you see any of these errors the first step is to 39 | [rescale your inputs](#scaling-regression-inputs) 40 | ([see this section for how](#scaling-regression-inputs)), for example by 41 | dividing or multiplying so that they are in more natural or convenient units. 42 | 43 | Where variances or covariances are very close to zero, try simplifying your 44 | model. For example, if you have multiple random effects in a multilevel model, 45 | [try elimintating some of them, or constraining their covariances](#simplifying-mixed-models). 46 | -------------------------------------------------------------------------------- /writing-a-paper.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Writing a paper' 3 | --- 4 | 5 | ```{r, include=FALSE} 6 | 7 | 8 | ``` 9 | 10 | # Writing a complete paper in RMarkdown {- #writing-paper} 11 | 12 | XXX This section to be a complete example and cover: 13 | 14 | - tidying up the mess and preprocessing raw-data 15 | - table 1 and reporting missing data 16 | - main analysis and figure 1 17 | - reporting models in the text 18 | - tabulating multiple models 19 | --------------------------------------------------------------------------------