util_fbs_microstructure: util_fbs_microstructue: Process raw microstructure coding...

View source: R/util_fbs_microstructure.R

util_fbs_microstructureR Documentation

util_fbs_microstructue: Process raw microstructure coding data

Description

This function loads the .txt raw data file from ObserverXT for specified Meal. Cleaning the data involves: 1) separating event log names to get visit, participant, and coder information, 2) selecting relevant data columns, 3) removing all events that are not needed/old/duplicate 4) re-ordering and re-name data columns 5) making wide behavioral data for summary metrics (nbites, bite rate) 6) separating event logs by coder and padding for equal entrees - need to fix mismatched number of bites/sips in a different step 7) creating variable labels, levels, and dictionaries

Usage

util_fbs_microstructure(file_pattern, data_path)

Arguments

file_pattern

string with the pattern to search for to find the raw data file. The pattern must contain respondent and visit number (e.g., for files from parent visit 1, would enter 'Parent_V1').

data_path

(optional) the full path to the directory where the raw Qualtrics database are saved, EXCLUDING the .sav file name (e.g., '.../b-childfoodlab_Shared/Active_Studies/RO1_Brain_Mechanisms_IRB_5357/Participant_Data/untouchedRaw/Qualtrics_Raw/'). If NOT entered, will assume the database is saved in the working directory.

filepattern

string with the pattern to search for to find the raw data file. The pattern must contain meal type ('PS' for portion size; 'v' for baseline/follow-up meals) and portion or visit number (e.g., for portion size 1 it would be 'PS1' and for baseline it would be 'v1').

Details

The databases MUST follow the naming convention: 'PSX_EventLogs_YYY-MM-DD.txt' or 'vX_EventLogs_YYYY-MM-DD'

Value

A list containing 2 data lists: 1) beh_wide contains - data: data.frame summary metrics in wide format by code, dict: data dictionary with variable descriptions 2) event contains - data: event data by coder and time, dict: data dictionary with variable descriptions

Examples

#if in same working directory as data:
ps1_microstructure <- util_fbs_microstructue('PS1')

## Not run: 
#file_pattern must be a string. The following will not run:
ps1_microstructure <- util_fbs_microstructue(PS1)

#file_pattern must have the protion size number ('PS1' ... 'PS4') OR visit number for baseline/follow-up('v1', 'v7'). If just enter 'PS' or 'v', the script will not run because it will return multiple files for different visits. The following will not run:
ps1_microstructure <- util_fbs_microstructue('PS')
ps1_microstructure <- util_fbs_microstructue('v')

## End(Not run)



alainapearce/kellertools documentation built on Feb. 25, 2024, 7:16 a.m.