array-simulate.Rd
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, ...)
A matrix.
The current implementation is fragile in the sense that it is
not checked that the input argument x
is an array.
## 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))
#> b
#> a 1 2
#> 1 95 297
#> 2 198 410
## 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))
#> b
#> 1 2
#> 340 660
## 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))
#> , , c = 1
#>
#> b
#> a 1 2
#> 1 998 3008
#> 2 1940 4065
#>
#> , , c = 2
#>
#> b
#> a 1 2
#> 1 5044 7015
#> 2 5919 8011
#>
## Simulate from slice defined by that dimension 3 is fixed at level 1
s <-simulateArray(x, 10000, 3, 1)
xtabs(~., as.data.frame(s))
#> b
#> a 1 2
#> 1 949 2994
#> 2 1956 4101