Giter Club home page Giter Club logo

r_templates's Introduction

This repo contains R templates for many of the core statistical analyses conducted by the Group Processes and Leadership Lab at the University of Alberta, which is directed by Dr. David Rast, III.

These R templates cover a lot of basic (read: typical) social psychology data analyses. Walks the user through importing data, cleaning data, running psychometric analyses, then finally analyzing the data using ANOVA or regression with appropriate interaction probing techniques.

Templates are numbered sequentially, but are only meant to assist the user through analyses in a logical and structured manner. The sequential order does not imply the user to go through each template in sequence, again these are starting blocks for users. For instance, if one's data are already 'tidy' then skip the '01_dataset_prep_and_cleaning.R' script.

We've tried to automate as much as possible to keep user errors to a minimum. We've also tried to keep as much as possible of the data output in R. For instance, figures and tables are created in APA format then automatically saved to your PC.

We've commented eavily throughout each script to help new users along where possible or to explain what a command does. As a side purpose, these templates were also written to help guide new R users through the stages of data analyses, especially those coming from SPSS. Many comments or functions are specifically for new users and people switching from SPSS.

NB: although we wrote these scripts, sections or entire parts might be modified from existing code posted online (e.g., Stack overflow, R blogs) or based on feedback/workshops from colleagues (e.g., Chris Aberson at HSU). We tried to cite these online sources where applicable by providing the link to the source material.

The GPL Lab regularly updates the code and adds new templates as we run new analyses or find new methods/packages to simplify the analyses/code.

If you have a template you want to add, feel free to send it to me. If we want to add it after reviewing/testing it, we will put it into our preferred (opinioned) format then upload it and attribute it to you.

r_templates's People

Contributors

davidrast3 avatar kmkincaid avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

r_templates's Issues

12-3way_simple_effects script

Calculation of the simple effects is not working. This seems to be an attempt to calculate relative variance, as per partial eta, but the numbers are not matching up in the model I have. My model, as pasted below (this is moderation1) cannot calculate the etasq because (5,3) does not exist.
Value df SS F p
Unequal 0.2484115 1 1.216679 0.3168459 0.5743497
Equal -0.4111375 1 3.328362 0.8667674 0.3533478
Residuals . NA 150 575.995752 NA NA

create interaction model of interest

modinter <- na.omit(model1)

examine simple effects

(moderation1 <- testInteractions(modinter, fixed = c("iv2", "iv3"), across="iv1", adjustment="none"))

etasqiv1.l_l <- (moderation1[1,3]) / ((moderation1[1,3]) + (moderation1[5,3])) # eta-squared iv2-l, iv3-l, across iv3
etasqiv1.h_l <- (moderation1[2,3]) / ((moderation1[2,3]) + (moderation1[5,3])) # eta-squared iv2-h, iv3-l, across iv3
etasqiv1.l_h <- (moderation1[3,3]) / ((moderation1[3,3]) + (moderation1[5,3])) # eta-squared iv2-l, iv3-h, across iv3
etasqiv1.h_h <- (moderation1[4,3]) / ((moderation1[4,3]) + (moderation1[5,3])) # eta-squared iv2-h, iv3-h, across iv3

11-2way_simple_effects script

In the section with the correlation matrix instead of having iv1, you have iv1_num. I did not convert my IVs to numerics and they still ran. If you want people to convert their variables so the function works, please explicitly add instructions for how people can convert their variables.

dat3 = na.omit(dat %>%
dplyr::select(iv1_num, iv2, dv) %>%
rename(NEW_NAME_IV1 = iv1_num, # relabel whatever you want your variables to be named in the manuscript, cannot contain spaces though
NEW_NAME_IV2 = iv2,
NEW_NAME_DV = dv))

11-2way_simple_effects script

The following code works, as long as the DV actually had the parameters 1-9. As I was testing it with data between -1 and 1, the graph didn't load any data until I changed the y-limits/y-breakdown. Consider having the user input these values into an object and putting the object in the code.

(figure1 = ggplot(dat1, aes(x = iv1, y = mean, group = iv2)) +
geom_bar(stat = "identity", position = "dodge", aes(fill = iv2)) +
geom_errorbar(limits, position=dodge, width=0.25) +
apatheme +
coord_cartesian(ylim=c(-1,1)) + # this is the range of the y-axis
scale_y_continuous(breaks=seq(-1,1,.5)) + # this is the increment ticks on the y-axis
ylab('dv') +
xlab('iv1') +
scale_fill_grey())

12-3way_simple_effects script

This is supposed to test a 3-way model, but on line 64 the function only requires two IVs instead of three. See below taken from the 3way script

aov_models <- dat %>%
dplyr::select(starts_with("avg_")) %>% # this line tells the map() only use your DVs (all start "avg_" in my datasets)
map(~Anova(lm(. ~ iv1 * iv2, data = dat), type = 3))

aov_models

99990-ggplot2_2way_SE.R

It feels like I'm looking at part of a script. The figure code requires objects such as y_axis_low, y_axis_high, and y_increment, but I do not see these objects being defined in the script.

Also, why is calling figure_1 and the code for saving the figure commented out?

12-3way_simple_effects

On line 75 you have a mis-type, only need 1 DV:

linear model to dive into any significant 2-ways

model1 <- lm(dv ~ dv ~ iv1 * iv2 * iv3, data=dat)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.