Creating ParticipantGroup objects

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(synr)

Introduction

To start using synr, you must first convert your data into a ParticipantGroup object. This tutorial explains how to convert raw consistency test data into this object. For more information on synr and ParticipantGroup itself, please see the main tutorial.

synr offers separate methods for converting 'long format' and 'wide format' raw data into ParticipantGroup objects. Brief explanations of the data formats are included at the beginning of each section.

Note that if you have any missing data, e. g. if the response color hex codes for some participants are missing, those must be coded in the data frame as R NA values. If you have used other values to represent missingness, you must first replace those values with NA, e. g. by using the naniar package.

'Long format' data

'Long format' data adhere to the rule that there should only be one column for each variable/type of data. For consistency tests, this means that each trial should have one row in the data frame and there should be only one column for participant color responses and one for trial graphemes/symbols. You might also be familiar with the 'long format' from working with tidy data.

Example data

Here's an example of long formatted consistency test data.

synr_exampledf_long_small

There were three participants. Each participant did 6 trials. Each trial is represented by a row, which holds the participant's ID, the grapheme/symbol used, the participant's response color (as an RGB hex code), and the time it took for the participant to respond after grapheme presentation. Note that response time data are optional - you can still use synr if you don't have those.

Convert data into a ParticipantGroup object

pg <- create_participantgroup(
  raw_df=synr_exampledf_long_small,
  n_trials_per_grapheme=2,
  id_col_name="participant_id",
  symbol_col_name="trial_symbol",
  color_col_name="response_color",
  time_col_name="response_time",
  color_space_spec="Luv"
)

You need to pass in:

If you want, you can also specify the name of a column of response times, if you have those.

'Wide format' data

'Wide format' data roughly adhere to the rule that there should only be one row for each subject/'object of interest'. For consistency tests, this means that each participant has a single row in the data frame, and multiple columns for each trial.

Example data

Here's an example of wide formatted consistency test data.

synr_exampledf_wide_small

There were three participants. Each participant did 6 trials. Each participant is represented by a row. Each trial is represented by three columns, e. g. symbol_1, response_color_1 and response_time_1 for the first trial. Note that response time data are optional - you can still use synr if you don't have those.

Convert data into a ParticipantGroup object

pg <- create_participantgroup_widedata(
  raw_df=synr_exampledf_wide_small,
  n_trials_per_grapheme=2,
  participant_col_name="participant_id",
  symbol_col_regex="symbol",
  color_col_regex="colou*r",
  time_col_regex="response_time",
  color_space_spec="Luv"
)

You need to pass in:

If you want, you can also specify a regular expression for response time columns, if you have those.

Details about regular expression patterns in example

The regular expression patterns, like 'symb' or 'col' must only occur in the corresponding columns. In the example data frame, only names of trial columns with color data have the pattern 'col' in them, so color_col_regex = 'col' would also work. If for instance the participant ID column had been called 'p_id_column", that column name would also fit the 'col' pattern, and hence color_col_regex = 'col' wouldn't work.

You can use as long or short regular expressions as you need. In this example we could for example have used color_col_regex = 'response_color_'.



Try the synr package in your browser

Any scripts or data that you put into this service are public.

synr documentation built on June 22, 2024, 7:25 p.m.