h_jags_add_dummy: Appending a Dummy Number for Selected Slots in Data

View source: R/helpers_jags.R

h_jags_add_dummyR Documentation

Appending a Dummy Number for Selected Slots in Data

Description

[Experimental]

A helper function that appends a dummy value to a given slots in GeneralData class object, if and only if the total number of observations (as indicated by object@nObs) equals to 1. Otherwise, the object is not changed.

Usage

h_jags_add_dummy(object, where, dummy = 0)

Arguments

object

(GeneralData)
object into which dummy values will be added.

where

(character)
names of slots in object to which a dummy number will be appended.

dummy

(number)
a dummy number that will be appended to selected slots in object. Default to 0.

Value

A GeneralData object with slots updated with dummy number.

Note

The main motivation behind this function is related to the JAGS. If there is only one observation, the data is not passed correctly to JAGS, i.e. e.g. x and y are treated like scalars in the data file. Therefore it is necessary to add dummy values to the vectors in this case As we don't change the number of observations (nObs), this addition of zeros doesn't affect the results of JAGS computations.

Examples

# Create some data of class 'Data'
my_data <- Data(
  x = 0.1,
  y = 0,
  doseGrid = c(0.1, 0.5)
)

my_data_2 <- Data(
  x = c(0.1, 0.5),
  y = c(0, 1),
  doseGrid = c(0.1, 0.5)
)

# Append dummy to `x` and `y`.
h_jags_add_dummy(my_data, where = c("x", "y"))

# Append dummy to `x` and `y`. No effect as `my_data_2@nObs != 1`.
h_jags_add_dummy(my_data_2, where = c("x", "y"))

Roche/crmPack documentation built on April 30, 2024, 3:19 p.m.