h_jags_add_dummy: Appending a Dummy Number for Selected Slots in Data

Description Usage Arguments Value Note Examples

View source: R/helpers_jags.R

Description

[Experimental]

A helper function that appends a dummy value to a given slots in Data 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

1
h_jags_add_dummy(object, where, dummy = 0)

Arguments

object

(Data)
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 Data 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# 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"))

0liver0815/onc-crmpack-test documentation built on Feb. 19, 2022, 12:25 a.m.