-
Notifications
You must be signed in to change notification settings - Fork 4
Overview of Analysis in R
This page defines my data analysis goals and provides guidelines for how these are implemented, specifically in R-Studio. It is a description of file structure of data and analysis scripts, as well as my workflow in R-Studio. For a light intro to R-Studio, see Guide to R/R-Studio.
Folders
_original_data - .csv, .xlsx, .emerge files for visual inspection and r.
archive_content - Historical r scripts, coding, and data structures.
Files
.Rproj - General project file (see below).
name_analysis.r - Main analysis file. Processes cleaned data; organized by analyses.
name_data.rda - data file to be used with the analysis.R file.
name_data_structures.R - file used to generate cleaned data structures (.rda files). Dependents: .csv files in _original_data
The main analysis script is meant to accomplish two tasks: statistical analysis and graph generation. The script starts with the read in of globally cleaned data, that is, trial exclusions that should apply accross the board, and column recodings that might be generally useful, as well as restructuring of full data sets (e.g., long vs wide format). You can expect three types of code sections here. Code is grouped in terms of analyses (statistics + graph), which should be navigable via the content menu, and should be executable in isolation (though it doesn't hurt to run all preceding code).
- Open (double-click) the .Rproj file. If it opens in R-Studio, it should set the working directory to the current folder.
- In R-Studio, navigate to the File tab on the bottom-right panel (default position). Open name_analysis.r from here.
- Run the code from this .r script through the library-loading, and data structure loading commands. Something like this:
library("ddply")
library("lmSupport")
# Here are some notes about what this script does.
load("datastructure.rda")A. local recoding or data reshaping for statistics or graphs.
# Let's look at a summary by-subject, of the full data set.
subject_summary = d %>%
ddply(.(subject), summarize, average_accuracy = mean(accuracy)) %>%
mutate(pass_fail = ifelse(average_accuracy > 50, "Pass", "Fail"))B. analysis for statistics.
subject_performance = lmer(average_accuracy~ 1 + (1|subject), data = subject_summary) %>%
summary()C. analysis for graphs.
subject_performance = lmer(average_accuracy~ 1 + (1|subject), data = subject_summary) %>%
summary() %>%
propLaterTable(1,100)D. graphs.
# likely you'll see some lines combining summary statistics into a single table:
for_graph_1 = rbind(model_1, model_2, model_3, model_4)
# and a line that labels the new table for the graph.
for_graph_1$categories = c("Category 1","Category 2","Category 1","Category 2")
# Then code for the graph.
graph_1 = ggplot(data_set, aes(x= x_var, y = y_var, fill = grouping_var)) +
geom_bar(stat="identity", position = "dodge")
# etc.If you see other code in here, it's doing other things. Beware of other code. It's probably old, brittle, and/or half baked.
Home | Overview | Expectations