mimic {anscombiser}R Documentation

Modify a dataset to mimic another dataset

Description

Modifies a dataset x so that it shares sample summary statistics with another dataset x2. '

Usage

mimic(x, x2, ...)

Arguments

x, x2

Numeric matrices or data frames. Each column contains observations on a different variable. Missing observations are not allowed. get_stats(x2) sets the target summary statistics. If x2 is missing then set_stats is called with d = ncol(x) and any additional arguments supplied via ....

...

Additional arguments to be passed to set_stats.

Details

The input dataset x is modified by shifting, scaling and rotating it so that its sample mean and covariance matrix match those of x2.

Value

A dataset with the same format as x. The returned dataset has the following summary statistics in common with x2.

See Also

anscombise modifies a dataset so that it shares sample summary statistics with Anscombe's quartet.

Examples

### 2D examples

# The UK and a dinosaur
got_maps <- requireNamespace("maps", quietly = TRUE)
got_datasauRus <- requireNamespace("datasauRus", quietly = TRUE)
if (got_maps && got_datasauRus) {
  library(maps)
  library(datasauRus)
  dino <- datasaurus_dozen_wide[, c("dino_x", "dino_y")]
  UK <- mapdata("UK")
  new_UK <- mimic(UK, dino)
  plot(new_UK)
}

# Trump and a dinosaur
if (got_datasauRus) {
  library(datasauRus)
  dino <- datasaurus_dozen_wide[, c("dino_x", "dino_y")]
  new_dino <- mimic(dino, trump)
  plot(new_dino)
}

## Examples of passing summary statistics

# The default is zero mean, unit variance and no correlation
new_faithful <- mimic(faithful)
plot(new_faithful)

# Change the correlation
mat <- matrix(c(1, -0.9, -0.9, 1), 2, 2)
new_faithful <- mimic(faithful, correlation = mat)
plot(new_faithful)

### A 3D example

new_randu <- mimic(datasets::randu, datasets::trees)
# The samples summary statistics are equal
get_stats(new_randu)
get_stats(datasets::trees)

[Package anscombiser version 1.0.0 Index]