A Guide to Data Analysis in R Commander Viann Nguyen-Feng, M.A. Mark A. Stellma
A Guide to Data Analysis in R Commander Viann Nguyen-Feng, M.A. Mark A. Stellmack, Ph.D. University of Minnesota Copyright © 2016 by Viann Nguyen-Feng and Mark A. Stellmack 2 About the authors Viann Nguyen-Feng received her M.P.H. from Eastern Virginia Medical School, after which she completed a post-graduate epidemiology fellowship and then a M.A. at the University of Minnesota. She is currently pursuing a Ph.D. at the University of Minnesota. Mark A. Stellmack received his Ph.D. in Experimental Psychology from Loyola University of Chicago, specializing in the study of auditory perception. He teaches undergraduate statistics and research methods courses at the University of Minnesota. Please contact the authors with questions, comments, and suggestions: Viann Nguyen-Feng: nguy2174@umn.edu Mark Stellmack: stell006@umn.edu 3 A Guide to Data Analysis in R Commander Table of Contents The Purpose of this Guide .................................................................................................................. 5 Installing R, RStudio, and Rcmdr ..................................................................................................... 6 Running R Commander ....................................................................................................................... 7 Initial data entry .................................................................................................................................... 9 Saving a Comma Separated Variable (CSV) spreadsheet in Excel ................................................... 9 Opening a Comma Separated Variable (CSV) spreadsheet in Rcmdr ......................................... 10 Viewing a data set .......................................................................................................................................... 11 Editing a data set ............................................................................................................................................ 11 Switching between multiple data sets .................................................................................................... 11 Saving and loading a data set .................................................................................................................... 12 BASIC ANALYSES .................................................................................................................................. 15 Descriptive statistics .......................................................................................................................... 15 Mean, standard deviation, standard error of mean, interquartile range, coefficient of variation, skewness, kurtosis, quantiles ............................................................................................... 15 Correlations .......................................................................................................................................... 18 Correlation matrix ......................................................................................................................................... 18 Two-sample t-tests ............................................................................................................................. 21 Between-groups/Independent-groups t-test ...................................................................................... 21 Within-groups/Repeated-measures/Correlated-groups/Paired t-test ..................................... 26 One-Way Analysis of Variance (ANOVA) and Post-Hoc Tests .............................................. 30 Two-Way Analysis of Variance (ANOVA) .................................................................................... 35 Testing main effects and interactions with multi-way ANOVAs ................................................... 35 Graphing interactions with multi-way ANOVAs ................................................................................. 38 Linear regression ................................................................................................................................ 40 Chi-square .............................................................................................................................................. 43 Chi-square using raw data .......................................................................................................................... 43 Chi-square using frequency counts ......................................................................................................... 46 ADVANCED ANALYSES ....................................................................................................................... 49 Descriptive statistics for sub-groups ........................................................................................... 49 Correlation test: Testing the significance of correlations ................................................... 53 Graphs ..................................................................................................................................................... 56 Scatterplot ........................................................................................................................................................ 56 Scatterplot by groups ................................................................................................................................... 59 4 Line graph ......................................................................................................................................................... 61 Bar graph .......................................................................................................................................................... 64 Miscellaneous ....................................................................................................................................... 66 Opening and Entering data ......................................................................................................................... 66 Opening an Excel spreadsheet .................................................................................................................. 66 Entering data directly into Rcmdr ........................................................................................................... 67 Recoding variables ........................................................................................................................................ 70 Combining items ............................................................................................................................................ 73 Converting variables from numeric to factor items .......................................................................... 75 Coding in R ............................................................................................................................................. 77 Deleting data sets ........................................................................................................................................... 77 Labeling points in a scatterplot ................................................................................................................ 79 Repeated-measures ANOVA ....................................................................................................................... 82 Mixed-method ANOVA.................................................................................................................................. 89 Updates ................................................................................................................................................... 93 Updating packages ........................................................................................................................................ 93 RStudio updates ............................................................................................................................................. 93 5 The Purpose of this Guide Our background is in Psychology. We teach introductory statistics and research methods courses, which are typically required for most Psychology majors. Our statistics course teaches the basics of descriptive and inferential statistics and our students perform computations by hand. In our research methods course, students learn to perform the same statistical analyses on a computer. In the past, we used a popular software package for which our university purchased a site- license and which ran on university-owned computers. However, the software is prohibitively expensive to students. As a result, students were able to use the software only on university computers during times when the computers were available. We sought an alternative software package that worked like the more expensive option but that was more affordable and that students could use anytime on their own computers. That led us to the R programming language. R is a free, powerful data-analysis program that performs many complex statistical analyses, but using R requires one to learn the R programming language. R Commander (Rcmdr) is a simple point-and-click interface to the R language that provides easy access to the most common analyses that Psychology students are likely to want to perform. Our goal was not to write a statistics textbook. Thus, this guide does not contain exercises or practice problems. Rather, our goal was to write a guide for users who already have knowledge of basic statistical techniques. This guide provides simple, step-by-step instructions for performing those analyses. This guide assumes that the user has knowledge of statistics at the level of a student who has completed an introductory course, including an understanding of the interpretation of p-values. Rcmdr is somewhat intuitive, but there are enough quirks and hidden data-formatting requirements to bring some analyses grinding to a halt if you do not format things properly. In addition, the Rcmdr output sometimes can be cluttered and difficult to wade through. This guide instructs the user on how to format the data for a particular analysis, what to click on, and where to find the most relevant information in the output. We tried to keep the writing as brief as possible so that this guide would be a useful, quick reference tool. Layouts and instructions may vary depending on your operating system or computer type (e.g., Mac or PC). The instructions were prepared using a Windows platform. Disclaimer: All data presented in this guide are entirely fabricated and perhaps even nonsensical. They are meant to serve an illustrative purpose in understanding the basics of data analysis in Rcmdr. Depending on your operating system, your screen may appear slightly different from the ones in this guide. 6 Installing R, RStudio, and Rcmdr R is a free software package and programming language for performing a wide variety of statistical analyses. RStudio and R Commander are interfaces that make it easier and more convenient to use R. You will only need to follow the instructions on this page once, when you first install R, RStudio, and Rcmdr. You must first download and install R, then download and install RStudio, then you can install R Commander. 1. Go to one of these following websites and follow the instructions to download and install the R software: Windows: http://cran.r-project.org/bin/windows/base/ Macintosh: http://cran.r-project.org/bin/macosx/ 2. After R is downloaded and installed, go to the following website and follow the instructions to download the RStudio software for your operating system: http://www.rstudio.com/products/rstudio/download/ 3. After RStudio is downloaded and installed, launch RStudio. 4. When RStudio opens, at the command prompt (>) in the Console panel, type install.packages("Rcmdr", dependencies=TRUE) and press Enter. Note: R and RStudio are case sensitive! If a pop-up window appears asking you to “Please select a CRAN mirror for use in this session”; select the site closest to you, then click “Ok.” 5. Many messages will appear in the Console window as R Commander is being installed. When the installation is complete, the command prompt (>) will appear again at the bottom of the Console window. 6. To open R Commander, type library(Rcmdr) at the command prompt and press Enter. If a pop-up window appears saying that you need to install another package and asking if you want to do so, click on “YES”. To run R Commander in the future after it is installed, you only need to launch RStudio and type library(Rcmdr) at the command prompt in the Console window. (You will need to click in the Console window before you can type in it.) 7 Running R Commander To run R Commander, you must first launch RStudio (by double-clicking the RStudio icon). The window shown below will open. The panel on the left-hand side of the RStudio window is the “Console”. The “>” in the Console panel is the command prompt. At the command prompt, type library(Rcmdr) and press Enter. (You probably will need to click in the Console window before you can type in it.) 8 When you press enter, Rcmdr will open. Rcmdr looks like this: You can click on commands in the Rcmdr menus to run your analyses. All of your output (the results of your point-and-click commands) will appear in the RStudio “Console” window. The big, white box at the bottom of the R Commander window is the “R Script” box of Rcmdr. You will not need to type anything in the “R Script” box when you are doing basic statistical analyses in Rcmdr. The “R Script” box has two purposes: 1. Script: You can enter R code into this box. This guide does not focus on writing and entering R code, though the end of this guide provides code for you to type in to perform some special functions. Rcmdr also generates code that appears in this box when you point and click commands. Thus, as you click on commands in R Commander, code will appear in the “R Script” box. 2. Messages: Rcmdr will give you “notes,” “warnings,” or “error messages” about the commands that you execute. These messages are generated and displayed by Rcmdr in the “R Script” box as you perform various operations in Rcmdr. “Notes” do not require any action, “warnings” may require some action, and “error messages” definitely require some action in order to have the command run properly. The messages will most likely explicitly tell you what went wrong and, thus, what must be changed in order to have the command run properly. 9 Initial data entry Here, we describe how to open a Comma Separated Variable uploads/Litterature/ the-rcmdr-guide 2 .pdf
Documents similaires










-
30
-
0
-
0
Licence et utilisation
Gratuit pour un usage personnel Attribution requise- Détails
- Publié le Jui 16, 2022
- Catégorie Literature / Litté...
- Langue French
- Taille du fichier 3.2904MB