Learn R Programming

binaryRL (version 0.8.9)

rpl_e: Step 4: Replaying the experiment with optimal parameters

Description

This function takes the optimal parameters generated by `fit_p` and applies them back to each subject's data to generate a new column, `Rob_Choose`. This allows users to analyze whether the reinforcement learning model can reproduce the original experimental effects observed in the data.

Usage

rpl_e(
  data,
  id = NULL,
  result,
  model,
  model_name,
  param_prefix,
  n_trials = NULL
)

Value

A list, where each element is a data.frame representing one subject's results. Each data.frame includes the value update history for each option, the learning rate (eta), discount rate (gamma), and other relevant information used in each update.

Arguments

data

[data.frame] This data should include the following mandatory columns:

  • "sub"

  • "time_line" (e.g., "Block", "Trial")

  • "L_choice"

  • "R_choice"

  • "L_reward"

  • "R_reward"

  • "sub_choose"

id

[vector] Participant IDs for subjects who need to replay the experiment.

result

[data.frame] Output data generated by the `fit_p()` function. Each row represents model fit results for a subject.

model

[function] A model function to be applied in evaluating the experimental effect.

model_name

[character] A character string specifying the name of the model to extract from the result.

param_prefix

[character] A prefix string used to identify parameter columns in the `result` data (e.g., "param_").

n_trials

[integer] Number of total trials in the experimental task.