dclone {dclone} | R Documentation |
Makes clones of R objects, that is values in the object are repeated n times, leaving the original structure of the object intact (in most of the cases).
dclone(x, n.clones=1, ...) ## Default S3 method: dclone(x, n.clones = 1, attrib=TRUE, ...) ## S3 method for class 'ts': dclone(x, n.clones = 1, attrib=TRUE, ...) ## S3 method for class 'dcdim': dclone(x, n.clones = 1, attrib=TRUE, ...) ## S3 method for class 'list': dclone(x, n.clones = 1, multiply = NULL, unchanged = NULL, attrib=TRUE, ...) dcdim(x)
x |
An R object to be cloned, or a cloned object to print. |
n.clones |
Number of clones. |
multiply |
Numeric or character index for list element(s) to be multiplied by n.clones
instead of repetitions (as done by dclone.default ).
|
unchanged |
Numeric or character index for list element(s) to be left unchanged. |
attrib |
Logical, TRUE if attributes are to be attached.
|
... |
Other arguments passed to function. |
dclone
is a generic method to clone objects. It is separate from rep
,
because there are different ways of cloning, depending on the BUGS
code implementation:
(1) Unchanged: no cloning at all (fo e.g. constants).
(2) Repeat: this is the most often used cloning method, repeating the observations as if there were more samples.
(3) Multiply: sometimes it is enough to multiply the numbers (e.g. for Binomial distribution).
(4) Add dimension: under specific circumstances, it is easier to add another dimension for clones,
but othervise repeat the observations (e.g. in case of time series, or for addressing special
indexing conventions in the BUGS
code, see examples for dclone.ts
, dclone.dcdim
and dcdim
).
An object with class attributes "dclone"
plus the original one(s).
Dimensions of the original object might change according to n.clones
.
The function tries to take care of names, sometimes replacing those with the
combination of the original names and an integer for number of clones.
dcdim
sets the class attribute of an object to "dcdim"
, thus
dclone
will clone the object by adding an extra dimension for the clones.
List (i.e. BUGS data objects) are handled differently to enable element specific
determination of the mode of cloning. This can be done via the unchanged
and multiply
arguments, or by setting the behaviour by the dcdim
function.
P\'eter S\'olymos, solymos@ualberta.ca
Lele, S.R., B. Dennis and F. Lutscher, 2007. Data cloning: easy maximum likelihood estimation for complex ecological models using Bayesian Markov chain Monte Carlo methods. Ecology Letters 10, 551–563.
## scalar dclone(4, 2) ## vector (x <- 1:6) dclone(x, 2) ## matrix (m <- matrix(x, 2, 3)) dclone(m, 2) ## data frame (dfr <- as.data.frame(t(m))) dclone(dfr, 2) ## list (l <- list(n = 10, y = 1:10, x = 1:10, p = 1)) dclone(l, 2) dclone(l, 2, attrib = FALSE) dclone(l, 2, multiply = "n", unchanged = "p") ## effect of dcdim l$y <- dcdim(l$y) dclone(l, 2, multiply = "n", unchanged = "p") ## time series z <- as.ts(rnorm(10)) dclone(z, 2)