Chapter 12 Tutorials and Links
12.1 R and RMarkdown
- Big Book of R – A collection of every book using R!
12.1.1 Beginners
- R for Data Science
- YaRrr! The Pirate’s Guide to R – this one is great for undergraduates
- Learning Statistics with R
- Cookbook for R
- R for Psychological Science
12.1.2 Cheatsheets
All cheatsheets can be downloaded here.
Especially useful cheatsheets include:
- RMarkdown Reference
- Data Viz
- Transformation
- Iteration
- Purrr
- Stringr
12.1.3 Data Visualization
- How to make better spaghetti plots
- DiagrammR – flowcharts and diagrams
- DAG models
- Twitter thread of tutorials by @CedScherer
12.1.4 Markdown
RMarkdown: The Definitive Guide
- See the section on Websites
Advanced R Markdown (customization and extensions) – lots of useful tips in here, once you’re familiar with Markdown.
12.1.5 Using Zotero with RMarkdown
- Download and install Zotero.
- Download and install the Better BibTex add-on.
- Open Zotero, and go to Preference.
- Under the Export tab, make sure Default Format is “Better BibTex Citation Key Quick Copy.”
- Under the Better BibTex tab, make sure the Citation key format is something you’ll find useful. (I recommend
[auth:lower][veryshorttitle:lower:alphanum][year]
).
- At this point, you can choose to export your Zotero library to a .bib file, save it to the working directory of your RMarkdown file, and make sure the bibliography line is pointing to that file. Once that’s done, you can simply drag from Zotero to your RMarkdown file, to create in-line citations, and the references section at the end will be created for you.
OR, you can install the citr
package, which works with your Zotero library, so you don’t need to create a new .bib file manually for each paper. Seems really convenient! (More information here.)
12.1.8 Text Analysis
- Text mining Twitter with TidyText – includes n-gram network plot
- Word vectors with tidy data principles
12.1.11 Making tables
- Awesome tables with kable (PDF)
- Awesome tables with kable (HTML)
gt
package- The
tableby
package is excellent for descriptive statistics, as it can calculate central tendency/variability for continuous variables and counts for categorical variables and integrate them into a single table. If you want descriptives by group (e.g., a treatment/control or by gender), it will also calculate those and statistical tests (\(t\) and \(\chi^s\) both!). - The
modelsummary
package seems very useful and customizable. May also work with all outputs from Markdown and Quarto, unlike sjPlot.
12.1.12 Reproducibility
- 8 things to make research more findable
- Ensure that the correct versions of packages are loaded using the
groundhog
package.
12.1.13 US Census API
This is a short tutorial on using the US Census API in word.
You’ll need the following:
* an API key. You can request one at https://api.census.gov/data/key_signup.html.
* the R package censusapi
Your key is used to access the API when working in R. It’s not recommended that you share your key with anyone, nor is anyone allowed to use your key to access the API. For that reason, we recommend creating an R script (census-api-key.R
) inside your project folder that assigns your key to an object. This script only needs to contain a single line of code:
= "Your Key Here" census_key
Do not share this script with anyone. If using GitHub, add the path to this script to the .gitignore file. You can see the .gitignore for this project as an example.
To use the API, load the censusapi
package and source the key script. Then add the key to your R environment.
library(censusapi)
source("census-api-key.R")
Sys.setenv(CENSUS_KEY=census_key)
There are many datasets in the API. You can see them by running the code:
<- listCensusApis() apis
You can View()
this object to sort through the datsets. The set of datasets most useful for linking with SAPA data are those from the American Community Survey, especially the 5-year surveys. Look for datasets with acs
in the name or acs5
for the 5-year files specifically. If there are surveys in multiple years, you’ll need to know which year (vintage) you would like data from.
You can see the variables available in a survey using the listCensusMetadata
function.
= listCensusMetadata(
vars name = "acs/acs5",
vintage = 2019,
type = "variables"
)head(vars)
name | label | concept | predicateType | group | limit | predicateOnly | hasGeoCollectionSupport | attributes | required |
---|---|---|---|---|---|---|---|---|---|
for | Census API FIPS ‘for’ clause | Census API Geography Specification | fips-for | N/A | 0 | TRUE | NA | NA | NA |
in | Census API FIPS ‘in’ clause | Census API Geography Specification | fips-in | N/A | 0 | TRUE | NA | NA | NA |
ucgid | Uniform Census Geography Identifier clause | Census API Geography Specification | ucgid | N/A | 0 | TRUE | TRUE | NA | NA |
B24022_060E | Estimate!!Total:!!Female:!!Service occupations:!!Food preparation and serving related occupations | SEX BY OCCUPATION AND MEDIAN EARNINGS IN THE PAST 12 MONTHS (IN 2019 INFLATION-ADJUSTED DOLLARS) FOR THE FULL-TIME, YEAR-ROUND CIVILIAN EMPLOYED POPULATION 16 YEARS AND OVER | int | B24022 | 0 | NA | NA | B24022_060EA,B24022_060M,B24022_060MA | NA |
B19001B_014E | Estimate!!Total:!!$100,000 to $124,999 | HOUSEHOLD INCOME IN THE PAST 12 MONTHS (IN 2019 INFLATION-ADJUSTED DOLLARS) (BLACK OR AFRICAN AMERICAN ALONE HOUSEHOLDER) | int | B19001B | 0 | NA | NA | B19001B_014EA,B19001B_014M,B19001B_014MA | NA |
B07007PR_019E | Estimate!!Total:!!Moved from different municipio:!!Foreign born:!!Naturalized U.S. citizen | GEOGRAPHICAL MOBILITY IN THE PAST YEAR BY CITIZENSHIP STATUS FOR CURRENT RESIDENCE IN PUERTO RICO | int | B07007PR | 0 | NA | NA | B07007PR_019EA,B07007PR_019M,B07007PR_019MA | NA |
You’ll also need to know the geography you’re collecting from. You can see the available geographies with similar code:
= listCensusMetadata(
geo name = "acs/acs5",
vintage = 2019,
type = "geography"
)head(geo)
name | geoLevelDisplay | referenceDate | requires | wildcard | optionalWithWCFor |
---|---|---|---|---|---|
us | 010 | 2019-01-01 | NULL | NULL | NA |
region | 020 | 2019-01-01 | NULL | NULL | NA |
division | 030 | 2019-01-01 | NULL | NULL | NA |
state | 040 | 2019-01-01 | NULL | NULL | NA |
county | 050 | 2019-01-01 | state | state | state |
county subdivision | 060 | 2019-01-01 | state , county | county | county |
To match with SAPA data, you’ll want to use the ZCTA or zip code tabulation area geography. Then use the getCensus
function to import data using the API. For example, if I wanted to extract the total number of households and people in each ZCTA to match with SAPA, I would use the following:
<- getCensus(
uscensus name = "acs/acs5/profile",
vars = c("NAME",
"DP02_0001E", # number of households
"DP05_0001E" # number of persons
), region = "zip code tabulation area", regionin = "state:*",
vintage = 2019)
See more in the censusapi
vignette.
12.2 Writing
- Dan Simons – writing guide
- EJ Wagenmakers – Teaching graduate students how to write clearly
- Writing Workshop – includes both tips on how to write (content), as well as the practice of writing regularly. This book also provide the foundation for starting a writing group.
- Practical Typography
12.2.2 Finding articles
- CrossRef – get DOI’s quickly
- Connected Papers – find other articles related to a specific research article
12.3 Survey Building
12.3.1 Qualtrics
Did you create a matrix but wish they were separate questions? Turn on the Carousel presentation.
If you’re using a screener, you can set up a Contact List Trigger.
Building a daily diary or ESM study? These may be helpful:
- Automated email distribution of Qualtrics surveys (specific to daily diary)
- Use Contact List Triggers to update embedded data (e.g., how many times someone has taken the survey, etc)
- See this article by Cui and colleagues.
12.6 Statistics
12.6.2 Generalized Linear Model
- Logistic regression is not fucked
- Melt the clock: tidy time series analysis
- Causal Inference: What If by Miguel A. Hernán & James M. Robins – Chapter titles: A defintion of causal effect, Randomized experiments, Observational studies, Effect modification, Interaction, Graphical representation of causal effects, Confounding, Selection bias, Measurement bias, Random variability, Why model, IP weighting and marginal structural models, Standardization and the parametric g-function, G-estimation of structural nested models, Outcome regression and propensity scores, Instrumental variable estimation, Causal survival analysis, Variable selection for causal inference, Time-varying treatments, Treatment-confounder feedback, G-methods for time-varying treatments, Target trial emulation
12.6.8 Longitudinal data analysis
- Personality Development Collaborative – also includes links to datasets that may be useful.
12.6.9 Item response theory
- Edwards (2009) – An Introduction to Item Response Theory Using the Need for Cognition Scale
- I would recommend starting with this article. The journal is aimed at graduate student seminars, so it will be more targeted to general understanding and application among psychologists, rather than to quantitative psychologists. This covers the two-parameter model and the graded response model.
- da Rocha et al. (2013) – An introduction to Rasch analysis for Psychiatric practice and research
- This one will be similar to the Edwards article in terms of being aimed at a more general audience. This article will cover a third type of IRT model: the Rasch model.
- Cook et al. (2005) – Dynamic Assessment of Health Outcomes: Time to Let the CAT Out of the Bag?
- This is less about the practice of IRT itself but more an intro into some of the potential broader application, especially in medical and educational settings.
- mirt vignette
- This will walk through how to use the mirt package in R. I believe mirt can do all three types of models described above.
- Check out the 6-video series by Karon Cook.
12.7 Graduate School
- The Illustrated Guide to a Ph.D.
- Raul Pacheco’s resources – a good collection of tips for everything from time management, to how to read and write, to using social media.
- Escaping the hamster wheel by Elliot Berkman
12.8 Life
Note that being a GE and having a research fellowship are considered different forms of compensation. Here’s a guide to preparing your (2019) federal taxes.
Diverse careers among applied psychologists – contact list of psychologists working outside of academia
Writing up your experiences on a resume (H/T: Jin Goh) ## Applying to graduate school
Psych Research List – Lists of internships, virtual grad program information sessions, jobs, resources for applying to grad programs, etc.
Application Statement Feedback Program – A service providing feedback on research statements for those applying to Psychology graduate programs.