You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: R.qmd
+30-30Lines changed: 30 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ output:
15
15
16
16
— [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>)
17
17
18
-
# Learning `R` {#learn}
18
+
# Learning `R` {#sec-learn}
19
19
20
20
## Base R
21
21
@@ -63,7 +63,7 @@ The following are resources for learning `tidyverse`, which is a collection of `
63
63
64
64
-<https://www.linkedin.com/learning/learning-the-r-tidyverse/welcome?u=42459020> (archived at <https://perma.cc/TD56-FX8R>)
65
65
66
-
## Getting Help/Questions {#questions}
66
+
## Getting Help/Questions {#sec-questions}
67
67
68
68
If you have `R` questions, you can ask them in a number of places:
69
69
@@ -90,7 +90,7 @@ Here are guidelines on providing a minimal, reproducible example: <https://stack
90
90
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>).
91
91
Provide a `reprex` whenever possible: <https://reprex.tidyverse.org>.
92
92
93
-
# Initial Set Up {#setup}
93
+
# Initial Set Up {#sec-setup}
94
94
95
95
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.).
96
96
@@ -137,7 +137,7 @@ To do this, perform the following steps:
137
137
If the `Rprofile.site` and `.Rprofile` files are correctly set up, they should pre-populate your `path` location when you open R.
138
138
If the contents of the `Global Environment` in `RStudio` are empty, your `Rprofile.site` and/or `.Rprofile` files are not set up correctly.
139
139
- 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:
141
141
- With RStudio running, choose `Tools → Global Options` from the menus.
142
142
- In the Options dialog, change the value for `Save workspace to .RData on exit` to `Never`.
143
143
- Click `OK`.
@@ -176,16 +176,16 @@ In general, RAs should not have an API token.
176
176
1. For antialiased plots in `RStudio`, change the Graphics backend to `Cairo`:
177
177
`Tools → Global Options → Graphics`
178
178
179
-
# Lab Package {#petersenlab}
179
+
# Lab Package {#sec-petersenlab}
180
180
181
181
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).
183
183
184
-
# Install Packages {#installPackages}
184
+
# Install Packages {#sec-installPackages}
185
185
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).
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):
200
200
201
201
```{r}
202
202
#| eval: false
203
203
204
204
update.packages(checkBuilt = TRUE, type = "source")
205
205
```
206
206
207
-
# Update `R` {#updateR}
207
+
# Update `R` {#sec-updateR}
208
208
209
209
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>)
210
210
211
211
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)
213
213
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]:
214
214
- Copy installed packages in the "Library" folder to the "Library" folder in the new installation
215
215
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>
In the Properties window, go to the Compatibility tab.
222
222
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))
224
224
1. Open the new `R` version and run `update.packages(checkBuilt = TRUE, ask = FALSE)`, and install any necessary packages
225
225
1. Close R
226
226
1. Delete anything left of the old installation
227
227
228
-
# Style Guide and Best Practices {#bestPractices}
228
+
# Style Guide and Best Practices {#sec-bestPractices}
229
229
230
230
## Create `Rstudio Project`
231
231
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.
233
233
This helps keep your project files organized.
234
234
235
235
## Use `R` Notebooks for "Computational Notebooks"
236
236
237
237
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.
239
239
240
240
## Separate sections in code
241
241
@@ -259,7 +259,7 @@ To create computational notebooks see the `Markdown` section on [computational n
259
259
It is important to comment code frequently and clearly.
260
260
You want you (and others) to easily be able to understand your code if you come back to it several years later!
261
261
262
-
## Don't save your workspace image {#dontSaveWorkspace}
262
+
## Don't save your workspace image {#sec-dontSaveWorkspace}
263
263
264
264
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>).
265
265
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.
@@ -359,11 +359,11 @@ pandoc version 1.12.3 or higher is required and was not found.
359
359
360
360
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>)
361
361
362
-
# Using R Script to Commit and Push Changes {#gitPush}
362
+
# Using R Script to Commit and Push Changes {#sec-gitPush}
363
363
364
364
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.
365
365
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)
367
367
368
368
1. Install and/or load `git2r` package
369
369
```r
@@ -437,7 +437,7 @@ The instructions to download and configure `git` software can be found [here](gi
437
437
- Using a [Personal Access Token](https://docs.gitlab.com/user/profile/personal_access_tokens/)
438
438
- Using an [SSH key](https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key)
439
439
- 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
441
441
- Using the encrypted credential and encryption key:
442
442
443
443
```r
@@ -457,7 +457,7 @@ The instructions to download and configure `git` software can be found [here](gi
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.
820
820
In addition, particular errors/warnings/issues are included below:
821
821
822
822
## General Troubleshooting Tips
@@ -860,7 +860,7 @@ Code can be wrapped in `try()` statements so that if an error occurs, the script
860
860
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.
861
861
862
862
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.
864
864
865
865
## Warning: `PACKAGENAME` package in `FILEPATH` library will not be updated
Copy file name to clipboardExpand all lines: SPSS.qmd
+20-20Lines changed: 20 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,13 @@
2
2
title: "SPSS"
3
3
---
4
4
5
-
# When to use `SPSS` {#whenSPSS}
5
+
# When to use `SPSS` {#sec-whenSPSS}
6
6
7
7
We use [R](R.qmd) for almost all data analysis.
8
8
However, [R](R.qmd) is code-based and has a steep learning curve.
9
9
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.
10
10
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}
12
12
13
13
A `.csv` file is a "comma-separated values" file—a file whose values are separated by commas.
14
14
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:
34
34
- On the open data file, select `save as` and `paste`
35
35
- This will copy and paste the syntax at the **end of the syntax file** in the import script.
36
36
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!
38
38
39
39
Example (you will need to update the filepath to your particular filepath):
40
40
@@ -61,53 +61,53 @@ SAVE OUTFILE='\\lc-rs-store24.hpc.uiowa.edu\lss_itpetersen\Lab\Members\HAWKID\Th
61
61
/COMPRESSED.
62
62
```
63
63
64
-
# Data Management {#dataManagement}
64
+
# Data Management {#sec-dataManagement}
65
65
66
66
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.
67
67
68
-
# Recode Variables {#recode}
68
+
# Recode Variables {#sec-recode}
69
69
70
70
<https://stats.oarc.ucla.edu/spss/modules/creating-and-recoding-variables/> (archived at <https://perma.cc/YJ2H-SRZM>)
71
71
72
72
<https://wlm.userweb.mwn.de/SPSS/wlmsreco.htm> (archived at <https://perma.cc/G4FN-PYPV>)
/STATISTICS=MEAN STDDEV MIN MAX KURTOSIS SKEWNESS.
133
133
```
134
134
135
-
## Histograms {#histograms}
135
+
## Histograms {#sec-histograms}
136
136
137
137
```
138
138
GRAPH
139
139
/HISTOGRAM=ses_hollingsheadSES.
140
140
```
141
141
142
-
## Correlations {#correlations}
142
+
## Correlations {#sec-correlations}
143
143
144
144
```
145
145
CORRELATIONS
@@ -149,7 +149,7 @@ CORRELATIONS
149
149
/MISSING=PAIRWISE.
150
150
```
151
151
152
-
## Multiple Regression {#multipleRegression}
152
+
## Multiple Regression {#sec-multipleRegression}
153
153
154
154
```
155
155
REGRESSION
@@ -161,7 +161,7 @@ REGRESSION
161
161
/METHOD=ENTER predictor1 predictor2 predictor3.
162
162
```
163
163
164
-
## Mediation {#mediation}
164
+
## Mediation {#sec-mediation}
165
165
166
166
First, download and run the [`PROCESS` macro](https://www.processmacro.org/download.html).
167
167
@@ -196,7 +196,7 @@ PROCESS
196
196
.
197
197
```
198
198
199
-
## Moderation {#moderation}
199
+
## Moderation {#sec-moderation}
200
200
201
201
1. Calculate means of the predictor and moderator
202
202
```
@@ -237,9 +237,9 @@ PROCESS
237
237
-<https://github.com/connorjmccabe/InterActive>
238
238
-<https://connorjmccabe.shinyapps.io/interactive/> (archived at <https://perma.cc/93G6-ALDP>)
239
239
240
-
# Best Practices {#bestPractices}
240
+
# Best Practices {#sec-bestPractices}
241
241
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.
243
243
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.
244
244
This is important so you do not have to remember all of the steps you followed to generate the analysis.
245
245
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