How to do a t-test or ANOVA for many variables at once in R and communicate the results in a better way. March, 2020. Library Catalog: www.r-bloggers.com
How to do a t-test or ANOVA for many variables at once in R and communicate the results in a better way [link]Paper  abstract   bibtex   
Introduction Perform multiple tests at once Concise and easily interpretable results T-test ANOVA To go even further Photo by Teemu Paananen Introduction As part of my teaching assistant position in a Belgian university, students often ask me for some help in their statistical analyses for their master’s thesis. A frequent question is how to compare groups of patients in terms of several quantitative continuous variables. Most of us know that: To compare two groups, a Student’s t-test should be used1 To compare three groups or more, an ANOVA should be performed These two tests are quite basic and have been extensively documented online and in statistical textbooks so the difficulty is not in how to perform these tests. In the past, I used to do the analyses by following these 3 steps: Draw boxplots illustrating the distributions by group (with the boxplot() function or thanks to the \esquisse\ R Studio addin if I wanted to use the \ggplot2\ package) Perform a t-test or an ANOVA depending on the number of groups to compare (with the t.test() and oneway.test() functions for t-test and ANOVA, respectively) Repeat steps 1 and 2 for each variable This was feasible as long as there were only a couple of variables to test. Nonetheless, most students came to me asking to perform these kind of tests not on one or two variables, but on multiples variables (sometimes up to around 100 variables!). So when there were many variables to test, I quickly realized that I was wasting my time and that there must be a more efficient way to do the job. Perform multiple tests at once I thus wrote a piece of code that automated the process, by drawing boxplots and performing the tests on several variables at once. Below is the code I used, illustrating the process with the iris dataset. The Species variable has 3 levels, so let’s remove one, and then draw a boxplot and apply a t-test on all 4 continuous variables at once. Note that the continuous variables that we would like to test are variables 1 to 4 in the iris dataset. dat
@misc{noauthor_how_2020,
	title = {How to do a t-test or {ANOVA} for many variables at once in {R} and communicate the results in a better way},
	url = {https://www.r-bloggers.com/how-to-do-a-t-test-or-anova-for-many-variables-at-once-in-r-and-communicate-the-results-in-a-better-way/},
	abstract = {Introduction Perform multiple tests at once  Concise and easily interpretable results T-test ANOVA   To go even further     Photo by Teemu Paananen   Introduction As part of my teaching assistant position in a Belgian university, students often ask me for some help in their statistical analyses for their master’s thesis. A frequent question is how to compare groups of patients in terms of several quantitative continuous variables. Most of us know that:  To compare two groups, a Student’s t-test should be used1  To compare three groups or more, an ANOVA should be performed  These two tests are quite basic and have been extensively documented online and in statistical textbooks so the difficulty is not in how to perform these tests. In the past, I used to do the analyses by following these 3 steps:  Draw boxplots illustrating the distributions by group (with the boxplot() function or thanks to the \{esquisse\} R Studio addin if I wanted to use the \{ggplot2\} package) Perform a t-test or an ANOVA depending on the number of groups to compare (with the t.test() and oneway.test() functions for t-test and ANOVA, respectively) Repeat steps 1 and 2 for each variable  This was feasible as long as there were only a couple of variables to test. Nonetheless, most students came to me asking to perform these kind of tests not on one or two variables, but on multiples variables (sometimes up to around 100 variables!). So when there were many variables to test, I quickly realized that I was wasting my time and that there must be a more efficient way to do the job.   Perform multiple tests at once I thus wrote a piece of code that automated the process, by drawing boxplots and performing the tests on several variables at once. Below is the code I used, illustrating the process with the iris dataset. The Species variable has 3 levels, so let’s remove one, and then draw a boxplot and apply a t-test on all 4 continuous variables at once. Note that the continuous variables that we would like to test are variables 1 to 4 in the iris dataset. dat},
	language = {en-US},
	urldate = {2020-03-21},
	journal = {R-bloggers},
	month = mar,
	year = {2020},
	note = {Library Catalog: www.r-bloggers.com},
}

Downloads: 0