array-simulate function

Simulate data from array.

Simulate data from array.

Simulate data (slice of) an array: Simulate n observations from the array x conditional on the variables in margin (a vector of indices) takes values given by margin.value

simulateArray(x, nsim = 1, margin, value.margin, seed = NULL) ## S3 method for class 'table' simulate(object, nsim = 1, seed = NULL, margin, value.margin, ...) ## S3 method for class 'xtabs' simulate(object, nsim = 1, seed = NULL, margin, value.margin, ...) ## S3 method for class 'array' simulate(object, nsim = 1, seed = NULL, margin, value.margin, ...)

Arguments

  • x, object: An array.
  • nsim: Number of cases to simulate.
  • margin, value.margin: Specification of slice of array to simulate from.
  • seed: Seed to be used for random number generation.
  • ...: Additional arguments, currently not used.

Returns

A matrix.

Note

The current implementation is fragile in the sense that it is not checked that the input argument x is an array.

Examples

## 2x2 array x <- parray(c("a", "b"), levels=c(2, 2), values=1:4) x <- tabNew(c("a", "b"), levels=c(2, 2), values=1:4) ## Simulate from entire array s <- simulateArray(x, 1000) xtabs(~., as.data.frame(s)) ## Simulate from slice defined by that dimension 1 is fixed at level 2 s <-simulateArray(x, 1000, margin=1, value.margin=2) xtabs(~., as.data.frame(s)) ## 2 x 2 x 2 array x <- parray(c("a", "b", "c"), levels=c(2, 2, 2), values=1:8) ## Simulate from entire array s <-simulateArray(x, 36000) xtabs(~., as.data.frame(s)) ## Simulate from slice defined by that dimension 3 is fixed at level 1 s <-simulateArray(x, 10000, 3, 1) xtabs(~., as.data.frame(s))

Author(s)

Søren Højsgaard, sorenh@math.aau.dk