-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSPSS.Rmd
255 lines (211 loc) · 8.86 KB
/
SPSS.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
---
title: "SPSS"
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
echo = TRUE,
error = TRUE,
comment = "")
```
# When to use `SPSS` {#whenSPSS}
We use [R](R.html) for almost all data analysis.
However, [R](R.html) is code-based and has a steep learning curve.
As a result, undergraduate students in the lab most often use `SPSS` or [`jamovi`](jamovi.html) 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.html) have a point-and-click interface.
# Creating a `SPSS` Syntax File to Import a `.csv` Data File {#import}
A `.csv` file is a "comma-separated values" file—a file whose values are separated by commas.
The lab will provide you with a `.csv` in your member user folder.
You will then need to create a `SPSS` syntax file to import and save the data into `SPSS` format.
This data file imports the data and only needs to be run when there's a new data set.
1. Open `SPSS` in the search bar
1. Go to file, open, data, then select .csv data
- You might have to change th file type to '.csv' instead of the default '.sav.' in order for the desired files to show up
1. Navigate to the desired .csv file
1. Select data file and select paste
1. Once the data preview opens, select paste again
1. A `SPSS` syntax file will open, select save as and move the file to the desired location
- save file as: `import.sps`
1. Open the syntax file and make sure lab path is saved as the absolute file path in the (`/FILE=`) field (**not** a mapped network drive like `R:`)
- `\\lc-rs-store24.hpc.uiowa.edu\lss_itpetersen\Lab\Members\HAWKID\Thesis\Data\srs_idWave.csv`
1. To run your script, select CTRL A and press the green play button to run the script
1. In the import script, `SPSS` will automatically determine the type of variable each should be, but it does not always classify them correctly.
- For numeric variables used in analysis, use the following command to change the variable to numeric
- e.g., (`tcid AUTO`) to (`tcid F4.2`)
1. At this point, the data file should appear.
Next, save the data in `SPSS` format (`.sav`) with the below steps:
- On the open data file, select `save as` and `paste`
- This will copy and paste the syntax at the **end of the syntax file** in the import script.
The completed import script will now read the `.csv` file and convert it to an `SPSS` data file (`.sav`).
- At this point, you can proceed [here](#analysis) to start your analysis script!
Example (you will need to update the filepath to your particular filepath):
```
GET DATA /TYPE=TXT
/FILE="\\lc-rs-store24.hpc.uiowa.edu\lss_itpetersen\Lab\Members\HAWKID\Thesis\Data\srs_idWave.csv"
/ENCODING='UTF8'
/DELIMITERS=","
/QUALIFIER='"'
/ARRANGEMENT=DELIMITED
/FIRSTCASE=2
/DATATYPEMIN PERCENTAGE=95.0
/VARIABLES=
tcid AUTO
wave AUTO
tc_sex AUTO
tc_ageLV1 F4.2
/MAP.
RESTORE.
CACHE.
EXECUTE.
SAVE OUTFILE='\\lc-rs-store24.hpc.uiowa.edu\lss_itpetersen\Lab\Members\HAWKID\Thesis\Data\srs_idWave.sav'
/COMPRESSED.
```
# Data Management {#dataManagement}
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.
## Average Across Variables {#averageVars}
```
COMPUTE cbcl_externalizingPOM_Average = MEAN(cbcl_externalizingPOM_Father,cbcl_externalizingPOM_Mother,cbcl_externalizingPOM_Secondary).
COMPUTE cbq_inhibitoryControl_Average = MEAN(cbq_inhibitoryControl_Father,cbq_inhibitoryControl_Mother,cbq_inhibitoryControl_Secondary).
EXECUTE.
```
## Rename Variables {#renameVars}
```
RENAME VARIABLES (ses_hollingsheadSES = SES).
```
## Mean-Center Variables {#meanCenter}
```
COMPUTE ses_hollingsheadSES_mc = ses_hollingsheadSES - mean_ses.
COMPUTE adi_nationalRank_mc = adi_nationalRank - mean_adiN.
EXECUTE.
```
## Compute Interaction Terms {#interaction}
```
COMPUTE ses_adi_interaction = ses_hollingsheadSES_mc * adi_nationalRank_mc.
EXECUTE.
```
## Save Data File {#saveData}
```
SAVE OUTFILE='\\lc-rs-store24.hpc.uiowa.edu\lss_itpetersen\Lab\Members\HAWKID\Thesis\Data\srs_idWave.sav'
/COMPRESSED.
```
# Creating a `SPSS` Syntax File for Analysis {#analysis}
1. To create a new syntax file, select file then new then syntax
- Save file as: `descriptives.sps`
1. In your syntax file, create comments for your different types of analyses.
- e.g., frequencies, descriptives, correlations
1. In your new data file, select an analysis and choose paste.
In your despriptives syntax file, the analysis should now be added. For each subsequent analysis, select paste to add it to the descriptives file under the appropriate syntax.
1. Create a new `SPSS` syntax file for your analysis. In this syntax file, add your analysis
- e.g., regressions
## Frequencies {#frequencies}
```
FREQUENCIES VARIABLES=tc_sex tc_hispanic tc_race tc_ethnicity
/ORDER=ANALYSIS.
```
## Descriptives {#descriptives}
```
DESCRIPTIVES VARIABLES=ICsim IClim IChg ICcbq ses_hollingsheadSES ADINat EXTBx
/STATISTICS=MEAN STDDEV MIN MAX KURTOSIS SKEWNESS.
```
## Histograms {#histograms}
```
GRAPH
/HISTOGRAM=ses_hollingsheadSES.
```
## Correlations {#correlations}
```
CORRELATIONS
/VARIABLES=tc_ageLV1 ses_hollingsheadParent cbq_inhibitoryControl_Average
lim_scoreExcludingPreferencePOM hg_scorePOM sim_goXnoGoPOM cbcl_externalizingPOM_Average
/PRINT=TWOTAIL NOSIG FULL
/MISSING=PAIRWISE.
```
## Multiple Regression {#multipleRegression}
```
REGRESSION
/MISSING PAIRWISE
/STATISTICS COEFF OUTS R ANOVA
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT outcome
/METHOD=ENTER predictor1 predictor2 predictor3.
```
## Mediation {#mediation}
First, download and run the [`PROCESS` macro](https://www.processmacro.org/download.html).
Below is the syntax for a model without covariates—replace `outcome` with name of outcome variable, `predictor` with name of predictor variable, and `mediator` with name of mediating variable:
```
PROCESS
y=outcome
/x=predictor
/m=mediator1 mediator2 mediator3
/model=4
/total=1
/effsize=1
/stand=1
/boot=10000
.
```
Model with covariates (p. 126):
```
PROCESS
y=outcome
/x=predictor
/m=mediator1 mediator2 mediator3
/cov=covariate1 covariate2 covariate3
/model=4
/total=1
/effsize=1
/stand=1
/boot=10000
.
```
## Moderation {#moderation}
1. Calculate means of the predictor and moderator
```
aggregate outfile * mode addvariables
/predictor_mean = mean(predictor).
aggregate outfile * mode addvariables
/moderator_mean = mean(moderator).
```
1. Mean-center the predictor and moderator
```
compute predictor_MC = predictor - predictor_mean.
compute moderator_MC = moderator - moderator_mean.
execute.
```
1. Verify that predictor and moderator are mean-centered (i.e., have a mean of zero)
```
DESCRIPTIVES VARIABLES=predictor moderator predictor_MC moderator_MC
/STATISTICS=MEAN STDDEV MIN MAX.
```
1. Create the interaction terms
```
compute predictorXmoderator = predictor_MC * moderator_MC.
execute.
```
1. Run moderated multiple regression model
```
REGRESSION
/MISSING PAIRWISE
/STATISTICS COEFF OUTS R ANOVA
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT outcome
/METHOD=ENTER predictor_MC moderator_MC predictorXmoderator covariate1 covariate2.
```
1. Create plot of interaction
- see McCabe et al. (2018) and following links:
- https://github.com/connorjmccabe/InterActive
- https://connorjmccabe.shinyapps.io/interactive/ (archived at https://perma.cc/93G6-ALDP)
# Best Practices {#bestPractices}
- Use `SPSS` syntax files (`.sps`) for performing all commands, including [importing data](#import), computing variables, recoding variables, running analyses, etc.
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.
This is important so you do not have to remember all of the steps you followed to generate the analysis.
This also allows you to quickly re-run the analysis if the data file is updated due to the collection of more data.
If you are unsure what `SPSS` command is needed, run the command via "point and click" in the interface; however, instead of clicking "OK", click "Paste".
This will paste the syntax that is used to run the command into a syntax file.
- Have one syntax file for importing data, computing composites, recoding variables, and saving data (e.g., `import.sps`).
- Have a separate syntax file for generating frequencies, descriptive statistics, and correlation matrices (e.g., `descriptives.sps`).
- Have a separate syntax file for running analyses (e.g., `analyses.sps`).
- Comment your syntax frequently
- to comment use the following convention:
- `*type comment.`
- Save your syntax frequently