| Title: | Analysis Tools for 'PsyToolkit' |
|---|---|
| Description: | Analyses and reports questionnaire and experiment data exported from 'PsyToolkit'. The package reads downloaded study folders, parses questionnaire structure, optionally merges demographic exports from CloudResearch or Prolific, and produces summary overviews of responses and completion times. It also provides helper functions to extract and aggregate experiment measures and survey variables, and to export results to spreadsheet files for further analysis and archiving. See Stoet (2017) <doi:10.1177/0098628316677643> for the 'PsyToolkit' platform. |
| Authors: | Gijsbert Stoet [cre, aut] (ORCID: <https://orcid.org/0000-0002-7557-483X>) |
| Maintainer: | Gijsbert Stoet <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.1.4 |
| Built: | 2026-06-05 07:03:10 UTC |
| Source: | https://github.com/cran/PsyToolkit |
Functions to read, summarise, and export PsyToolkit questionnaire and experiment data.
Typical workflow
Download PsyToolkit data from your PsyToolkit account (a zip file).
Create your R working directory, and within that, a folder data.
Extract the downloaded PsyToolkit zip file into your new folder data.
Read the data from the folder with psytkReadData.
Summarise the data with psytkReport.
Process data with other functions, such as psytkExtractFromExperiment.
Export data with psytkExport.
Main functions
psytkReadData: Read PsyToolkit data into an R object.
psytkReport: Print a summary report.
psytkExport: Export data to an Excel workbook.
psytkTable: Print formatted tables.
psytkExtractFromExperiment: Extract data for detailed processing.
psytkExtractTail: Extract last line from experiment files.
Other functions
Example
A small example object is included for documentation examples: data(psytkDemo).
This is not required for normal usage.
A small example object illustrating the structure returned by psytkReadData().
An object used in examples.
data(psytkDemo) str(psytkDemo, max.level = 1)data(psytkDemo) str(psytkDemo, max.level = 1)
Exports most of the loaded PsyToolkit data to Excel file.
psytkExport(surveydata , file = "exported_data.xlsx" , labels = FALSE , orderByType = FALSE )psytkExport(surveydata , file = "exported_data.xlsx" , labels = FALSE , orderByType = FALSE )
surveydata |
The PsyToolkit survey data object |
file |
If no filename provided, default exported_data.xlsx will be used |
labels |
Not yet implemented |
orderByType |
Order output by question type instead of order of survey |
No returned value.
## Real workflow (requires your own PsyToolkit data files in myfolder) ## Not run: psytkDemo = psytkReadData( "myfolder" ) ## End(Not run) ## runnable example for CRAN checks: data( psytkDemo ) # or for runnable example tmp_out_file = tempfile(fileext=".xlsx") psytkExport( psytkDemo , tmp_out_file ) unlink( tmp_out_file)## Real workflow (requires your own PsyToolkit data files in myfolder) ## Not run: psytkDemo = psytkReadData( "myfolder" ) ## End(Not run) ## runnable example for CRAN checks: data( psytkDemo ) # or for runnable example tmp_out_file = tempfile(fileext=".xlsx") psytkExport( psytkDemo , tmp_out_file ) unlink( tmp_out_file)
Find out how for each participant how many cases of condition exist
psytkExtractCount(data , names , conditions)psytkExtractCount(data , names , conditions)
data |
data object |
names |
names of conditions |
conditions |
The actual conditions as logical vectors |
A dataframe with for each condition a vector with data for each participant/file.
## Not run: d = psytkReadData("data") stroopCorrect = d$expData.stroopForR[,"V7"] == 1 ## correct key pressed stroopWrong = d$expData.stroopForR[,"V7"] == 2 ## wrong key pressed stroopError = d$expData.stroopForR[,"V7"] != 1 ## wrong key pressed ## or no key at all (timeout) stroopSlow = d$expData.stroopForR[,"V7"] == 3 ## timeout con = d$expData.stroopForR[,"V4"] == 1 inc = d$expData.stroopForR[,"V4"] == 0 realdata = d$expData.stroopForR[,"V1"] == "real" conditionCongruent = con conditionIncongruent = inc basicSelection = stroopCorrect & realdata subsel = realdata stroopTrials = psytkExtractCount( data = d$expData.stroopForR , names = c("congruent","incongruent","all"), conditions = cbind( conditionCongruent & subsel , conditionIncongruent & subsel , realdata & subsel )) ## End(Not run)## Not run: d = psytkReadData("data") stroopCorrect = d$expData.stroopForR[,"V7"] == 1 ## correct key pressed stroopWrong = d$expData.stroopForR[,"V7"] == 2 ## wrong key pressed stroopError = d$expData.stroopForR[,"V7"] != 1 ## wrong key pressed ## or no key at all (timeout) stroopSlow = d$expData.stroopForR[,"V7"] == 3 ## timeout con = d$expData.stroopForR[,"V4"] == 1 inc = d$expData.stroopForR[,"V4"] == 0 realdata = d$expData.stroopForR[,"V1"] == "real" conditionCongruent = con conditionIncongruent = inc basicSelection = stroopCorrect & realdata subsel = realdata stroopTrials = psytkExtractCount( data = d$expData.stroopForR , names = c("congruent","incongruent","all"), conditions = cbind( conditionCongruent & subsel , conditionIncongruent & subsel , realdata & subsel )) ## End(Not run)
Extract the data of one participant from one experiment in the PsyToolkit data object
psytkExtractFromExperiment(dataset , expname , id = 1 , removeID = TRUE)psytkExtractFromExperiment(dataset , expname , id = 1 , removeID = TRUE)
dataset |
The name of the PsyToolkit survey data |
expname |
The name of the experiment |
id |
The id, can either be numerical or UUID |
removeID |
Returned data does not contain participant IDs |
A data frame with the participant's data.
## Not run: ## imagine your data contains an experiment named "Stroop" ## imagine the Stroop data have as 5th column the reaction time ## this is a way to calculate the mean RT of each participant d = psytkReadData("data") meanRTs = numeric( d$n ) for ( i in d$IDcount ){ tmpdata = psytkExtractFromExperiment( d , "Stroop" , id = i ) meanRTs = mean( tmpdata[,5] ) } ## End(Not run)## Not run: ## imagine your data contains an experiment named "Stroop" ## imagine the Stroop data have as 5th column the reaction time ## this is a way to calculate the mean RT of each participant d = psytkReadData("data") meanRTs = numeric( d$n ) for ( i in d$IDcount ){ tmpdata = psytkExtractFromExperiment( d , "Stroop" , id = i ) meanRTs = mean( tmpdata[,5] ) } ## End(Not run)
Apply function to data each participants' experiment data.
psytkExtractNum(data , dependent , names , conditions , f = mean)psytkExtractNum(data , dependent , names , conditions , f = mean)
data |
The experiment data frame |
dependent |
The column in the experiment data of interest |
names |
The names of the conditions |
conditions |
For each name of a condition a vector of logical selecting data |
f |
A function such as mean (default), median, min, max |
Returns a dataframe with one column for each condition.
## Not run: d = psytkReadData("data") stroopCorrect = d$expData.stroopForR[,"V7"] == 1 ## correct key pressed stroopWrong = d$expData.stroopForR[,"V7"] == 2 ## wrong key pressed stroopError = d$expData.stroopForR[,"V7"] != 1 ## wrong key pressed or ## no key at all (timeout) stroopSlow = d$expData.stroopForR[,"V7"] == 3 ## timeout con = d$expData.stroopForR[,"V4"] == 1 inc = d$expData.stroopForR[,"V4"] == 0 realdata = d$expData.stroopForR[,"V1"] == "real" conditionCongruent = con conditionIncongruent = inc basicSelection = stroopCorrect & realdata ## the psytkExtractNum function is part of the PsyToolkit library. It ## extracts from the experiment data for each participant one row. So ## you end with a row of RT for the congruent and incongruent ## condition; you can later use this for the t test. stroopRT = psytkExtractNum( data = d$expData.stroopForR , dependent = 10 , names = c("congruent","incongruent"), conditions = cbind( conditionCongruent & basicSelection , conditionIncongruent & basicSelection )) ## End(Not run)## Not run: d = psytkReadData("data") stroopCorrect = d$expData.stroopForR[,"V7"] == 1 ## correct key pressed stroopWrong = d$expData.stroopForR[,"V7"] == 2 ## wrong key pressed stroopError = d$expData.stroopForR[,"V7"] != 1 ## wrong key pressed or ## no key at all (timeout) stroopSlow = d$expData.stroopForR[,"V7"] == 3 ## timeout con = d$expData.stroopForR[,"V4"] == 1 inc = d$expData.stroopForR[,"V4"] == 0 realdata = d$expData.stroopForR[,"V1"] == "real" conditionCongruent = con conditionIncongruent = inc basicSelection = stroopCorrect & realdata ## the psytkExtractNum function is part of the PsyToolkit library. It ## extracts from the experiment data for each participant one row. So ## you end with a row of RT for the congruent and incongruent ## condition; you can later use this for the t test. stroopRT = psytkExtractNum( data = d$expData.stroopForR , dependent = 10 , names = c("congruent","incongruent"), conditions = cbind( conditionCongruent & basicSelection , conditionIncongruent & basicSelection )) ## End(Not run)
For each participant, calculate a percentage based on conditions.
psytkExtractPerc(data , dependent , names , conditions , f = mean)psytkExtractPerc(data , dependent , names , conditions , f = mean)
data |
The experiment data frame |
dependent |
The column in the experiment data of interest |
names |
The names of the conditions |
conditions |
For each name of a condition a vector of logical selecting data |
f |
A function such as mean (default), median, min, max |
A vector the length of survey IDs in your dataset.
## Not run: d = psytkReadData("data") stroopCorrect = d$expData.stroopForR[,"V7"] == 1 ## correct key pressed stroopWrong = d$expData.stroopForR[,"V7"] == 2 ## wrong key pressed stroopError = d$expData.stroopForR[,"V7"] != 1 ## wrong key pressed ## or no key at all (timeout) stroopSlow = d$expData.stroopForR[,"V7"] == 3 ## timeout con = d$expData.stroopForR[,"V4"] == 1 inc = d$expData.stroopForR[,"V4"] == 0 realdata = d$expData.stroopForR[,"V1"] == "real" conditionCongruent = con conditionIncongruent = inc basicSelection = stroopCorrect & realdata ## the psytkExtractNum function is part of the PsyToolkit library. It ## extracts from the experiment data for each participant one row. So ## you end with a row of RT for the congruent and incongruent ## condition; you can later use this for the t test. stroopRT = psytkExtractNum( data = d$expData.stroopForR , dependent = 10 , names = c("congruent","incongruent"), conditions = cbind( conditionCongruent & basicSelection , conditionIncongruent & basicSelection ) ) ## the psytkExtractPerc function is part of the PsyToolkit library. ## It extracts from the experiment data for each participant one ## row. It calculates the Percentage of Errors (PE) for each ## participant. This is useful for two reasons: 1) You can use it to ## calculate the Stroop effect in error rates. 2) You can use it to ## find out if some participants performed extremely poorly (for ## example at chance level) stroopPE = psytkExtractPerc( data = d$expData.stroopForR , dependent = !stroopCorrect , names = c("congruent","incongruent"), conditions = cbind( conditionCongruent & realdata , conditionIncongruent & realdata ) ) ## End(Not run)## Not run: d = psytkReadData("data") stroopCorrect = d$expData.stroopForR[,"V7"] == 1 ## correct key pressed stroopWrong = d$expData.stroopForR[,"V7"] == 2 ## wrong key pressed stroopError = d$expData.stroopForR[,"V7"] != 1 ## wrong key pressed ## or no key at all (timeout) stroopSlow = d$expData.stroopForR[,"V7"] == 3 ## timeout con = d$expData.stroopForR[,"V4"] == 1 inc = d$expData.stroopForR[,"V4"] == 0 realdata = d$expData.stroopForR[,"V1"] == "real" conditionCongruent = con conditionIncongruent = inc basicSelection = stroopCorrect & realdata ## the psytkExtractNum function is part of the PsyToolkit library. It ## extracts from the experiment data for each participant one row. So ## you end with a row of RT for the congruent and incongruent ## condition; you can later use this for the t test. stroopRT = psytkExtractNum( data = d$expData.stroopForR , dependent = 10 , names = c("congruent","incongruent"), conditions = cbind( conditionCongruent & basicSelection , conditionIncongruent & basicSelection ) ) ## the psytkExtractPerc function is part of the PsyToolkit library. ## It extracts from the experiment data for each participant one ## row. It calculates the Percentage of Errors (PE) for each ## participant. This is useful for two reasons: 1) You can use it to ## calculate the Stroop effect in error rates. 2) You can use it to ## find out if some participants performed extremely poorly (for ## example at chance level) stroopPE = psytkExtractPerc( data = d$expData.stroopForR , dependent = !stroopCorrect , names = c("congruent","incongruent"), conditions = cbind( conditionCongruent & realdata , conditionIncongruent & realdata ) ) ## End(Not run)
Extracts a value from each participants experiment data
psytkExtractTail(data , dependent)psytkExtractTail(data , dependent)
data |
The experiment data (not the survey object) |
dependent |
The column of the table you are interested in. |
A vector of values as long as there are files/participants/sessions.
## Not run: ## assume there is an experiment Stroop and the 5th column of this file ## is the reaction time d = psytkReadData("data") myExpData = d$expData.Stroop speed = psytkExtractTail( myExpData , 5 ) ## End(Not run)## Not run: ## assume there is an experiment Stroop and the 5th column of this file ## is the reaction time d = psytkReadData("data") myExpData = d$expData.Stroop speed = psytkExtractTail( myExpData , 5 ) ## End(Not run)
Parses the survey.txt file in your data file. Rarely needed on its own. Is used by psytkReadData
psytkParseSurvey(datadir = NA , surveyfilename = NA)psytkParseSurvey(datadir = NA , surveyfilename = NA)
datadir |
The folder where you extracted your PsyToolkit data zip file |
surveyfilename |
The name of the survey if not survey.txt |
Returns a survey objects giving data about questions and items in it.
## Not run: mySurvey = psytkParseSurvey( "data" ) ## End(Not run)## Not run: mySurvey = psytkParseSurvey( "data" ) ## End(Not run)
Overview of questionnaire structure
psytkQ( data )psytkQ( data )
data |
The survey data object |
Structure of the survey
## Not run: d = psytkReadData ( "myfolder" ) psytkQ(d) ## End(Not run)## Not run: d = psytkReadData ( "myfolder" ) psytkQ(d) ## End(Not run)
Load PsyToolkit raw data.
psytkReadData(surveyOrDir , psytkAllowRepeatExp = TRUE , verbose = TRUE)psytkReadData(surveyOrDir , psytkAllowRepeatExp = TRUE , verbose = TRUE)
surveyOrDir |
The name of the folder where you unzipped your PsyToolkit downloaded data file |
psytkAllowRepeatExp |
If more than one version of the same experiment available, the last will be used |
verbose |
With TRUE you get detailed information about each datafile. |
This is the start of any workflow for working with PsyToolkit data.
Returns on object holding all the data of the survey, including experiment data if available.
## Not run: d = psytkReadData("myfolder") ## End(Not run)## Not run: d = psytkReadData("myfolder") ## End(Not run)
Read any textfile containing data. Idea for textfiles with unequal row lengths.
psytkReadTable(filename)psytkReadTable(filename)
filename |
The name of the text file to be rad |
The benefit of this specific function over read.table() is that it can
read datafiles with really different numbers of items per row
easily. That can be helpful for reading in experiment data.
This function is rarely needed for end users.
A data frame
## Not run: z = psytkReadTable( "mydata.txt" ) ## End(Not run)## Not run: z = psytkReadTable( "mydata.txt" ) ## End(Not run)
Allows you to remove participant datafiles from a PsyToolkit survey data object.
psytkRemoveData(psytkSurveyData , selection)psytkRemoveData(psytkSurveyData , selection)
psytkSurveyData |
The object holding the PsyToolkit survey data |
selection |
A logical vector as long as the number of participants/files used |
Returns a new object without the removed data. This includes removal from the participant data
## Not run: ## example of removing participant with ID number lower than 10 from all data dataset1 = psytkReadData("data") selection = rep( T , dataset$n ) selection[ d$IDcount < 10 ] = F dataset2 = psytkRemoveData( d , selection ) ## End(Not run)## Not run: ## example of removing participant with ID number lower than 10 from all data dataset1 = psytkReadData("data") selection = rep( T , dataset$n ) selection[ d$IDcount < 10 ] = F dataset2 = psytkRemoveData( d , selection ) ## End(Not run)
Creates a textual summary report for PsyToolkit questionnaire data.
psytkReport(psytkSurveyData, textbox = FALSE, question = TRUE , print = TRUE )psytkReport(psytkSurveyData, textbox = FALSE, question = TRUE , print = TRUE )
psytkSurveyData |
A PsyToolkit survey data object (typically returned by |
textbox |
Logical; whether to include summaries for textbox items. Optional, because these can sometimes be long. |
question |
Logical; whether to include question text from q: lines when available. |
print |
Logical; whether or not the report is shown in terminal. |
Returns a report object, which can be shown with function print.
## Real workflow (requires your own PsyToolkit data files in myfolder) ## Not run: d = psytkReadData( "myfolder" ) ## End(Not run) ## runnable example for CRAN checks: data(psytkDemo) # or for runnable example myReport = psytkReport( psytkDemo ) # this will show the report in the terminal print( myReport ) # you can print the report later as well## Real workflow (requires your own PsyToolkit data files in myfolder) ## Not run: d = psytkReadData( "myfolder" ) ## End(Not run) ## runnable example for CRAN checks: data(psytkDemo) # or for runnable example myReport = psytkReport( psytkDemo ) # this will show the report in the terminal print( myReport ) # you can print the report later as well
Present R data frame or R matrix in a nice table for R terminal output
psytkTable(x, header = NULL , align = "L" , padding=2 , wrap = 20)psytkTable(x, header = NULL , align = "L" , padding=2 , wrap = 20)
x |
A data frame or matrix with some data. |
header |
A header above the content of the table. |
align |
L, C, or R for left, center, or right alignment for all or vector of each column |
padding |
Spacing between columns, default is 2 |
wrap |
Wrap cells if they have more than 20 characters |
This function simply outputs to terminal screen.
## Not run: x = data.frame( items=1:3,names=c("John","Claudia","Mel") ) psytkTable( x , header=TRUE ) ## End(Not run)## Not run: x = data.frame( items=1:3,names=c("John","Claudia","Mel") ) psytkTable( x , header=TRUE ) ## End(Not run)