Description Usage Arguments Details Value Author(s) References Examples
Functions to coerce or test for non-random objects.
1 2 3 | is.constant(x)
as.constant(x)
|
x |
an object, random variable (rv) or not |
is.constant
returns TRUE
for each component of the argument
object if there is only one simulation (that is, the variable is
"constant").
Note: rv objects that merely have variance zero are not therefore necessarily "true" constants.
as.constant
coerces rv
or rvsummary
objects into
constant strings; NA
is returned for component that is not random.
a logical vector (not rv), TRUE if a component is constant w.p. 1
Jouni Kerman jouni@kerman.com
Kerman, J. and Gelman, A. (2007). Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Statistics and Computing 17:3, 235-244.
See also vignette("rv")
.
1 2 3 4 5 6 7 8 9 10 | is.constant(1) # TRUE
is.constant(as.rv(1)) # TRUE
setnsims(200)
x <- rvbern(prob=0.001)
all(sims(x)==0) # most probably true
is.constant(x) # always FALSE
x <- rvnorm(3)
x[1] <- 1
as.constant(x) # 1, NA, NA
all(is.random(x) & is.na(as.constant(x))) # always TRUE
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.