Skip to content

Commit f20408a

Browse files
20260103 - clean up section headers and cross-references
1 parent 3d7ee76 commit f20408a

25 files changed

+400
-402
lines changed

R.qmd

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ output:
1515
1616
[Evelyn Hall and Simon 'Yoda' Blomberg, R-help April 2005](https://www.brodrigues.co/blog/2022-06-02-arcane/) (archived at <https://perma.cc/KY9N-2FTT>)
1717

18-
# Learning `R` {#learn}
18+
# Learning `R` {#sec-learn}
1919

2020
## Base R
2121

@@ -63,7 +63,7 @@ The following are resources for learning `tidyverse`, which is a collection of `
6363

6464
- <https://www.linkedin.com/learning/learning-the-r-tidyverse/welcome?u=42459020> (archived at <https://perma.cc/TD56-FX8R>)
6565

66-
## Getting Help/Questions {#questions}
66+
## Getting Help/Questions {#sec-questions}
6767

6868
If you have `R` questions, you can ask them in a number of places:
6969

@@ -90,7 +90,7 @@ Here are guidelines on providing a minimal, reproducible example: <https://stack
9090
Here are a good example and guidelines for providing a minimal, reproducible example in `R`: <https://stackoverflow.com/a/5963610> (archived at <https://perma.cc/PC9L-DQZG>).
9191
Provide a `reprex` whenever possible: <https://reprex.tidyverse.org>.
9292

93-
# Initial Set Up {#setup}
93+
# Initial Set Up {#sec-setup}
9494

9595
Note: many of these initial setup steps described below are not necessary for general use; many of these steps are necessary only for using lab-related repositories (e.g., to gain API access to export data from `REDCap`, to use absolute paths rather than relative paths so repos can communicate with each other, etc.).
9696

@@ -137,7 +137,7 @@ To do this, perform the following steps:
137137
If the `Rprofile.site` and `.Rprofile` files are correctly set up, they should pre-populate your `path` location when you open R.
138138
If the contents of the `Global Environment` in `RStudio` are empty, your `Rprofile.site` and/or `.Rprofile` files are not set up correctly.
139139
- If you get this error (`Error: could not find function "install.packages"`), run the following line manually and then restart `RStudio` after the package finishes installing: `install.packages("fortunes")`
140-
1. For [reproducibility purposes](#dontSaveWorkspace), prevent `R`/`RStudio` from saving your workspaces automatically using the following steps:
140+
1. For [reproducibility purposes](#sec-dontSaveWorkspace), prevent `R`/`RStudio` from saving your workspaces automatically using the following steps:
141141
- With RStudio running, choose `Tools → Global Options` from the menus.
142142
- In the Options dialog, change the value for `Save workspace to .RData on exit` to `Never`.
143143
- Click `OK`.
@@ -176,16 +176,16 @@ In general, RAs should not have an API token.
176176
1. For antialiased plots in `RStudio`, change the Graphics backend to `Cairo`:
177177
`Tools → Global Options → Graphics`
178178

179-
# Lab Package {#petersenlab}
179+
# Lab Package {#sec-petersenlab}
180180

181181
The [`petersenlab` package](https://devpsylab.github.io/petersenlab) is here: <https://devpsylab.github.io/petersenlab>.
182-
To install the [`petersenlab` package](https://devpsylab.github.io/petersenlab), see instructions [here](dataManagement.qmd#labFunctions).
182+
To install the [`petersenlab` package](https://devpsylab.github.io/petersenlab), see instructions [here](dataManagement.qmd#sec-labFunctions).
183183

184-
# Install Packages {#installPackages}
184+
# Install Packages {#sec-installPackages}
185185

186-
To install and load `R` packages, see the instructions [here](dataManagement.qmd#loadInstallPackages).
186+
To install and load `R` packages, see the instructions [here](dataManagement.qmd#sec-loadInstallPackages).
187187

188-
# Update Packages {#updatePackages}
188+
# Update Packages {#sec-updatePackages}
189189

190190
To update packages, use the following code:
191191

@@ -196,20 +196,20 @@ update.packages(checkBuilt = TRUE)
196196
```
197197

198198
One indication that the packages might not be updating to the latest version is seeing the same packages showing as needing an update after having run the `update.packages()` function.
199-
If this does not update the package(s) to the latest version, you may need to install the latest version of the package(s) from source (see the section on "[Initial Set Up](#setup)" of `R` for the software needed to install R packages from source):
199+
If this does not update the package(s) to the latest version, you may need to install the latest version of the package(s) from source (see the section on "[Initial Set Up](#sec-setup)" of `R` for the software needed to install R packages from source):
200200

201201
```{r}
202202
#| eval: false
203203
204204
update.packages(checkBuilt = TRUE, type = "source")
205205
```
206206

207-
# Update `R` {#updateR}
207+
# Update `R` {#sec-updateR}
208208

209209
Instructions adapted from: <https://mirror.las.iastate.edu/CRAN/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f> (archived at <https://perma.cc/W5QW-MA6Q>)
210210

211211
1. Uninstall `R`
212-
1. Install the new `R` version into a directory that contains no spaces (see Step 2 in the [Initial Set Up](#setup) section above)
212+
1. Install the new `R` version into a directory that contains no spaces (see Step 2 in the [Initial Set Up](#sec-setup) section above)
213213
1. [You only need to do this step if you installed packages in the R-version-specific "Library" folder rather than the common/shared "Packages" folder—that is, you don't need to do this step if you used the lab's `Rprofile.site` file, as described above, which installs packages to the common/shared "Packages" folder]:
214214
- Copy installed packages in the "Library" folder to the "Library" folder in the new installation
215215
1. In new `R` version folder, copy the current `Rprofile.site` file as a backup (`Rprofile_BACKUP.site`) and overwrite the original file with the lab's version of `Rprofile.site` from here: <https://research-git.uiowa.edu/PetersenLab/R-InitialSetup/-/blob/master/R%20Setup%20Files/Rprofile.site>
@@ -220,22 +220,22 @@ Instructions adapted from: <https://mirror.las.iastate.edu/CRAN/bin/windows/base
220220
Then, click or tap on "Properties".
221221
In the Properties window, go to the Compatibility tab.
222222
At the bottom of the window, check the box next to the "Run this program as an administrator" option, and then click or tap on Apply or OK.
223-
1. Make sure you have the latest version of the tools necessary to compile packages from source (i.e., Rtools for Windows or `R` Compiler Tools for Rcpp on MacOS; see the instructions in the section on [initial set up](#setup))
223+
1. Make sure you have the latest version of the tools necessary to compile packages from source (i.e., Rtools for Windows or `R` Compiler Tools for Rcpp on MacOS; see the instructions in the section on [initial set up](#sec-setup))
224224
1. Open the new `R` version and run `update.packages(checkBuilt = TRUE, ask = FALSE)`, and install any necessary packages
225225
1. Close R
226226
1. Delete anything left of the old installation
227227

228-
# Style Guide and Best Practices {#bestPractices}
228+
# Style Guide and Best Practices {#sec-bestPractices}
229229

230230
## Create `Rstudio Project`
231231

232-
For each data analysis project (i.e., each [`GitLab`/`GitHub`](#git) repo), create an RStudio Project.
232+
For each data analysis project (i.e., each [`GitLab`/`GitHub`](#sec-git) repo), create an RStudio Project.
233233
This helps keep your project files organized.
234234

235235
## Use `R` Notebooks for "Computational Notebooks"
236236

237237
Using `R` Notebooks for "Computational Notebooks" is helpful for reproducible code that can be shared with others.
238-
To create computational notebooks see the `Markdown` section on [computational notebooks](markdown.qmd#computationalNotebook) in the Data Analysis guides.
238+
To create computational notebooks see the `Markdown` section on [computational notebooks](markdown.qmd#sec-computationalNotebook) in the Data Analysis guides.
239239

240240
## Separate sections in code
241241

@@ -259,7 +259,7 @@ To create computational notebooks see the `Markdown` section on [computational n
259259
It is important to comment code frequently and clearly.
260260
You want you (and others) to easily be able to understand your code if you come back to it several years later!
261261

262-
## Don't save your workspace image {#dontSaveWorkspace}
262+
## Don't save your workspace image {#sec-dontSaveWorkspace}
263263

264264
For reproducibility purposes, it is important [**not** to save your workspace image](https://www.r-bloggers.com/2017/04/using-r-dont-save-your-workspace/) (archived at <https://perma.cc/9SCZ-L4DE>).
265265
It is best practices to begin `R` each session with a clean workspace.
@@ -311,10 +311,10 @@ However, do make sure to save your `R` scripts before exiting Rstudio.
311311
- [Hierarchical Linear Modeling](hlm.qmd)
312312
- [Item Response Theory](irt.qmd)
313313
- [Longitudinal Data Analysis](lda.qmd)
314-
- [Mediation](sem.qmd#mediation)
315-
- [Moderation/Interaction](regression.qmd#moderation)
314+
- [Mediation](sem.qmd#sec-mediation)
315+
- [Moderation/Interaction](regression.qmd#sec-moderation)
316316
- [Multiple Imputation](multipleImputation.qmd)
317-
- [Principal Component Analysis](pca.hqmdtml)
317+
- [Principal Component Analysis](pca.qmd)
318318
- [Regression](regression.qmd)
319319
- [Structural Equation Modeling](sem.qmd)
320320

@@ -359,11 +359,11 @@ pandoc version 1.12.3 or higher is required and was not found.
359359

360360
The solution to this problem [can be found at this link](https://stackoverflow.com/questions/28432607/pandoc-version-1-12-3-or-higher-is-required-and-was-not-found-r-shiny) (archived at <https://perma.cc/YX57-BPRS>)
361361

362-
# Using R Script to Commit and Push Changes {#gitPush}
362+
# Using R Script to Commit and Push Changes {#sec-gitPush}
363363

364364
When using R to perform such actions as rendering sites and processing data, it can be useful to include code that commits and pushes relevant changes into the appropriate `git` repository.
365365
The steps below assume that you have `Git` and the `GitHub` desktop app installed.
366-
The instructions to download and configure `git` software can be found [here](git.Rmd#toBegin)
366+
The instructions to download and configure `git` software can be found [here](git.Rmd#sec-toBegin)
367367

368368
1. Install and/or load `git2r` package
369369
```r
@@ -437,7 +437,7 @@ The instructions to download and configure `git` software can be found [here](gi
437437
- Using a [Personal Access Token](https://docs.gitlab.com/user/profile/personal_access_tokens/)
438438
- Using an [SSH key](https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key)
439439
- Encrypting credential information and storing the encrypted credential file somewhere accessible for use
440-
- See [here](https://research-git.uiowa.edu/PetersenLab/R-InitialSetup/-/blob/master/REDCap%20Credentials/Encrypt%20REDCap%20Token.R) for an exmaple of encryption and key creation
440+
- See [here](https://research-git.uiowa.edu/PetersenLab/R-InitialSetup/-/blob/master/REDCap%20Credentials/Encrypt%20REDCap%20Token.R) for an example of encryption and key creation
441441
- Using the encrypted credential and encryption key:
442442

443443
```r
@@ -457,7 +457,7 @@ The instructions to download and configure `git` software can be found [here](gi
457457
push(repo, credentials = cred_user_pass("insertUsername", myPassword))
458458
```
459459

460-
# Using `try()` Statements {#try}
460+
# Using `try()` Statements {#sec-try}
461461

462462
[`try()` statements](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/try) can be very useful in cases where you would like code to continue running even if a certain line errors out.
463463
If the code inside of the statement results in an error, the `try()` statement will allow R to simply jump to the next line of code, rather than halting the entire process.
@@ -606,7 +606,7 @@ usethis::use_version()
606606

607607
1. Then, check the package: Ctrl-Shift-E
608608

609-
1. Then, run [`R CMD check`](#rCmdCheck)
609+
1. Then, run [`R CMD check`](#sec-rCmdCheck)
610610

611611
1. Then, install the package:
612612

@@ -633,7 +633,7 @@ or:
633633
install.packages("NAME_OF_PACKAGE")
634634
```
635635

636-
## `R CMD check` {#rCmdCheck}
636+
## `R CMD check` {#sec-rCmdCheck}
637637

638638
1. Build the source package (`.tar.gz` file)
639639
- Click on the "Build" tab in the top-right pane of RStudio, and then click "Build Source Package", or run the following code in the `R` console:
@@ -672,7 +672,7 @@ devtools::build(pkg = "D:/Documents/GitHub/petersenlab")
672672

673673
1. Then, delete the created folder whose name begins with ".Rd2pdf..."
674674

675-
1. In the R Console, build the source package in `R` (or using the instructions described [above](#rCmdCheck)):
675+
1. In the R Console, build the source package in `R` (or using the instructions described [above](#sec-rCmdCheck)):
676676

677677
```{r}
678678
#| eval: false
@@ -812,11 +812,11 @@ Unofficial documentation:
812812
813813
- <https://usethis.r-lib.org/reference/licenses.html>
814814
815-
# Troubleshooting {#troubleshootingR}
815+
# Troubleshooting {#sec-troubleshootingR}
816816
817817
To troubleshoot `R` issues, be resourceful.
818818
Try googling the error message or issue you are experiencing.
819-
See [here](#questions) for a list of places you can pose `R`-related questions for help.
819+
See [here](#sec-questions) for a list of places you can pose `R`-related questions for help.
820820
In addition, particular errors/warnings/issues are included below:
821821
822822
## General Troubleshooting Tips
@@ -860,7 +860,7 @@ Code can be wrapped in `try()` statements so that if an error occurs, the script
860860
These `try()` statements are particularly useful when rendering a site; if they are not used, a single error will halt the entire process. `try()` statements allow the code to continue running in spite of a line or two erroring out.
861861
862862
If you have already incorporated `try()` statements and are still experiencing fatal errors in code, check to make sure that the smallest possible "unit" of code is wrapped in `try()` statements, rather than large sections of code.
863-
See [here](#try) for more information.
863+
See [here](#sec-try) for more information.
864864
865865
## Warning: `PACKAGENAME` package in `FILEPATH` library will not be updated
866866

SPSS.qmd

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: "SPSS"
33
---
44

5-
# When to use `SPSS` {#whenSPSS}
5+
# When to use `SPSS` {#sec-whenSPSS}
66

77
We use [R](R.qmd) for almost all data analysis.
88
However, [R](R.qmd) is code-based and has a steep learning curve.
99
As a result, undergraduate students in the lab most often use `SPSS` or [`jamovi`](jamovi.qmd) for their research projects (e.g., [Honors projects](https://devpsylab.github.io/LabWiki/honors.html) and [SROP projects](https://devpsylab.github.io/LabWiki/expectations-SROP.html)), because `SPSS` and [`jamovi`](jamovi.qmd) have a point-and-click interface.
1010

11-
# Creating a `SPSS` Syntax File to Import a `.csv` Data File {#import}
11+
# Creating a `SPSS` Syntax File to Import a `.csv` Data File {#sec-import}
1212

1313
A `.csv` file is a "comma-separated values" file—a file whose values are separated by commas.
1414
The lab will provide you with a `.csv` in your member user folder.
@@ -34,7 +34,7 @@ Next, save the data in `SPSS` format (`.sav`) with the below steps:
3434
- On the open data file, select `save as` and `paste`
3535
- This will copy and paste the syntax at the **end of the syntax file** in the import script.
3636
The completed import script will now read the `.csv` file and convert it to an `SPSS` data file (`.sav`).
37-
- At this point, you can proceed [here](#analysis) to start your analysis script!
37+
- At this point, you can proceed [here](#sec-analysis) to start your analysis script!
3838

3939
Example (you will need to update the filepath to your particular filepath):
4040

@@ -61,53 +61,53 @@ SAVE OUTFILE='\\lc-rs-store24.hpc.uiowa.edu\lss_itpetersen\Lab\Members\HAWKID\Th
6161
/COMPRESSED.
6262
```
6363

64-
# Data Management {#dataManagement}
64+
# Data Management {#sec-dataManagement}
6565

6666
Add any data management/transformations at the end of your `import.sps` file (after importing your data), so you re-run the transformations each time you update the data file.
6767

68-
# Recode Variables {#recode}
68+
# Recode Variables {#sec-recode}
6969

7070
<https://stats.oarc.ucla.edu/spss/modules/creating-and-recoding-variables/> (archived at <https://perma.cc/YJ2H-SRZM>)
7171

7272
<https://wlm.userweb.mwn.de/SPSS/wlmsreco.htm> (archived at <https://perma.cc/G4FN-PYPV>)
7373

74-
## Average Across Variables {#averageVars}
74+
## Average Across Variables {#sec-averageVars}
7575

7676
```
7777
COMPUTE cbcl_externalizingPOM_Average = MEAN(cbcl_externalizingPOM_Father,cbcl_externalizingPOM_Mother,cbcl_externalizingPOM_Secondary).
7878
COMPUTE cbq_inhibitoryControl_Average = MEAN(cbq_inhibitoryControl_Father,cbq_inhibitoryControl_Mother,cbq_inhibitoryControl_Secondary).
7979
EXECUTE.
8080
```
8181

82-
## Rename Variables {#renameVars}
82+
## Rename Variables {#sec-renameVars}
8383

8484
```
8585
RENAME VARIABLES (ses_hollingsheadSES = SES).
8686
```
8787

88-
## Mean-Center Variables {#meanCenter}
88+
## Mean-Center Variables {#sec-meanCenter}
8989

9090
```
9191
COMPUTE ses_hollingsheadSES_mc = ses_hollingsheadSES - mean_ses.
9292
COMPUTE adi_nationalRank_mc = adi_nationalRank - mean_adiN.
9393
EXECUTE.
9494
```
9595

96-
## Compute Interaction Terms {#interaction}
96+
## Compute Interaction Terms {#sec-interaction}
9797

9898
```
9999
COMPUTE ses_adi_interaction = ses_hollingsheadSES_mc * adi_nationalRank_mc.
100100
EXECUTE.
101101
```
102102

103-
## Save Data File {#saveData}
103+
## Save Data File {#sec-saveData}
104104

105105
```
106106
SAVE OUTFILE='\\lc-rs-store24.hpc.uiowa.edu\lss_itpetersen\Lab\Members\HAWKID\Thesis\Data\srs_idWave.sav'
107107
/COMPRESSED.
108108
```
109109

110-
# Creating a `SPSS` Syntax File for Analysis {#analysis}
110+
# Creating a `SPSS` Syntax File for Analysis {#sec-analysis}
111111

112112
1. To create a new syntax file, select file then new then syntax
113113
- Save file as: `descriptives.sps`
@@ -118,28 +118,28 @@ In your despriptives syntax file, the analysis should now be added. For each sub
118118
1. Create a new `SPSS` syntax file for your analysis. In this syntax file, add your analysis
119119
- e.g., regressions
120120

121-
## Frequencies {#frequencies}
121+
## Frequencies {#sec-frequencies}
122122

123123
```
124124
FREQUENCIES VARIABLES=tc_sex tc_hispanic tc_race tc_ethnicity
125125
/ORDER=ANALYSIS.
126126
```
127127

128-
## Descriptives {#descriptives}
128+
## Descriptives {#sec-descriptives}
129129

130130
```
131131
DESCRIPTIVES VARIABLES=ICsim IClim IChg ICcbq ses_hollingsheadSES ADINat EXTBx
132132
/STATISTICS=MEAN STDDEV MIN MAX KURTOSIS SKEWNESS.
133133
```
134134

135-
## Histograms {#histograms}
135+
## Histograms {#sec-histograms}
136136

137137
```
138138
GRAPH
139139
/HISTOGRAM=ses_hollingsheadSES.
140140
```
141141

142-
## Correlations {#correlations}
142+
## Correlations {#sec-correlations}
143143

144144
```
145145
CORRELATIONS
@@ -149,7 +149,7 @@ CORRELATIONS
149149
/MISSING=PAIRWISE.
150150
```
151151

152-
## Multiple Regression {#multipleRegression}
152+
## Multiple Regression {#sec-multipleRegression}
153153

154154
```
155155
REGRESSION
@@ -161,7 +161,7 @@ REGRESSION
161161
/METHOD=ENTER predictor1 predictor2 predictor3.
162162
```
163163

164-
## Mediation {#mediation}
164+
## Mediation {#sec-mediation}
165165

166166
First, download and run the [`PROCESS` macro](https://www.processmacro.org/download.html).
167167

@@ -196,7 +196,7 @@ PROCESS
196196
.
197197
```
198198

199-
## Moderation {#moderation}
199+
## Moderation {#sec-moderation}
200200

201201
1. Calculate means of the predictor and moderator
202202
```
@@ -237,9 +237,9 @@ PROCESS
237237
- <https://github.com/connorjmccabe/InterActive>
238238
- <https://connorjmccabe.shinyapps.io/interactive/> (archived at <https://perma.cc/93G6-ALDP>)
239239

240-
# Best Practices {#bestPractices}
240+
# Best Practices {#sec-bestPractices}
241241

242-
- Use `SPSS` syntax files (`.sps`) for performing all commands, including [importing data](#import), computing variables, recoding variables, running analyses, etc.
242+
- Use `SPSS` syntax files (`.sps`) for performing all commands, including [importing data](#sec-import), computing variables, recoding variables, running analyses, etc.
243243
The benefit of using `SPSS` syntax files (and code-based files, more generally) is that they allow you to reproduce your findings again with the same data file.
244244
This is important so you do not have to remember all of the steps you followed to generate the analysis.
245245
This also allows you to quickly re-run the analysis if the data file is updated due to the collection of more data.

0 commit comments

Comments
 (0)