Skip to contents

Functions to get or set the "observed data" of an object.

Usage

obs_data(object, ...) <- value

# S3 method for class 'drift_dm'
obs_data(object, ..., eval_model = FALSE) <- value

obs_data(object, ...)

# S3 method for class 'drift_dm'
obs_data(object, ..., messaging = TRUE)

# S3 method for class 'fits_ids_dm'
obs_data(object, ...)

Arguments

object

an object of type drift_dm or fits_ids_dm (see load_fits_ids).

...

additional arguments passed down to the specific method.

value

a data.frame which provides three columns: (1) RT for the response times, (2) a column for boundary coding according to the model's b_coding(), (3) Cond for specifying the conditions.

eval_model

logical, indicating if the model should be re-evaluated or not when updating the solver settings (see re_evaluate_model). Default is False.

messaging

logical, indicating if messages shall be ushered or not.

Value

For obs_data() a (re-assembled) data.frame of the observed data. A message is ushered to remind the user that the returned data.frame may be sorted differently than expected.

For obs_data<-() the updated drift_dm object.

Details

obs_data() is a generic accessor function, and obs_data<-() is a generic replacement function. The default methods get and set the "observed data". Their behavior, however, may be a bit unexpected.

In drift_dm objects, the observed data are not stored as a data.frame. Instead, any supplied observed data set is disassembled into RTs for the upper and lower boundary and with respect to the different conditions (ensures more speed and easier programming in the depths of the package). Yet, obs_data() returns a data.frame for drift_dm objects. This implies that obs_data() does not merely access the observed data, but re-assembles it. Consequently, a returned data.frame for the observed data is likely sorted differently than the data.frame that was originally set to the model via obs_data<-(). Also, when the originally supplied data set provided more conditions than the model, the unused conditions will not be part of the returned data.frame.

For fits_ids_dm (see load_fits_ids), the observed data are stored as a data.frame in the general fit procedure info. This is the data.frame that obs_data() will return. Thus, the returned data.frame will match with the data.frame that was initially supplied to estimate_model_ids, although with unused conditions being dropped.

In theory, it is possible to update parts of the "observed data". However, because obs_data() returns a re-assembled data.frame for drift_dm objects, great care has to be taken with respect to the ordering of the argument value. A message is ushered to remind the user that the returned data.frame may be sorted differently than expected.

Note

There is only a replacement function for drift_dm objects. This is because replacing the observed data after the model has been fitted (i.e., for a fits_ids_dm object) doesn't make sense.

See also

Examples

# Set some data to a model -------------------------------------------------
my_model <- dmc_dm() # DMC is pre-built and directly available
# synthetic data suitable for DMC; comes with dRiftDM
some_data <- dmc_synth_data
obs_data(my_model) <- some_data

# Extract data from a model ------------------------------------------------
head(obs_data(my_model))
#> Extracting observed data from a model object. Remember that the result may be sorted differently than expect!
#>      RT Error Cond
#> 1 0.349     0 comp
#> 2 0.444     0 comp
#> 3 0.441     0 comp
#> 4 0.572     0 comp
#> 5 0.438     0 comp
#> 6 0.535     0 comp

# Important: ---------------------------------------------------------------
# The returned data.frame may be sorted differently than the one initially
# supplied.
some_data <- some_data[sample(1:nrow(some_data)), ] #' # shuffle the data set
obs_data(my_model) <- some_data
all.equal(obs_data(my_model), some_data)
#> Extracting observed data from a model object. Remember that the result may be sorted differently than expect!
#> [1] "Attributes: < Component “row.names”: Mean relative difference: 0.6525695 >"
#> [2] "Component “RT”: Mean relative difference: 0.210372"                        
#> [3] "Component “Error”: Mean relative difference: 2"                            
#> [4] "Component “Cond”: 286 string mismatches"                                   
# so don't do obs_data(my_model)["Cond"] <- ...

# Addition: ----------------------------------------------------------------
# accessor method also available for fits_ids_dm objects
# (see estimate_model_ids)
# get an exemplary fits_ids_dm object
fits <- get_example_fits_ids()
head(obs_data(fits))
#>   ID        RT Error   Cond
#> 1  1 0.6016572     0   comp
#> 2  1 0.4514293     0   comp
#> 3  1 0.4180971     0   comp
#> 4  1 0.4514365     0 incomp
#> 5  1 0.4013124     0   comp
#> 6  1 0.4347489     0 incomp