Create Data with Identical Statistics
Creates data with identical statistics (metamers) using an iterative
algorithm proposed by Matejka & Fitzmaurice (2017) <DOI:10.1145/3025453.3025912>.
Implements the algorithm proposed by Matejka & Fitzmaurice (2017) to create metamers (datasets with identical statistical properties but very different graphs).
In colour theory, metamers) are colours that have very different wavelength distribution but are perceived as equal by out visual system. This happens because out eyes essentially summarise a continuous distribution of wavelength by just 3 numbers: the amount that each type of cone cell is exited. Colour metamerism is how artists can reproduce so many colours with a few pigments, or how PC monitors use only 3 lights to show colourful pictures.
Statistical transformations such as mean, standard deviation and correlation behave very similarly in that they summarise data with just a few numbers for the benefit of our limited cognitive capacity. Thus, statistical metamers are sets of data that share some statistical properties.
This article explores statistical metamerism in more detail.
You can install metamer with:
or install the development version with:
# install.packages("devtools") devtools::install_github("eliocamp/metamer")
You can construct metamers from a starting dataset and a vector of statistical properties to remain constant (by default, up to 2 significant figures).
library(metamer) # Start with the datasaurus # install.packages("datasauRus") start <- subset(datasauRus::datasaurus_dozen, dataset == "dino") start$dataset <- NULL # And we want to preserve means and correlation mean_cor <- delayed_with(mean(x), mean(y), cor(x, y)) N <- 20000 set.seed(42) # To make results reproducible metamers <- metamerize(start, preserve = mean_cor, N = N) print(metamers) #> List of 12791 metamers
We found 12791 metamers. Let’s see the final one, with the starting dataset as background.
library(ggplot2) ggplot(metamers[[length(metamers)]], aes(x, y)) + geom_point(data = start, color = "red", alpha = 0.5, size = 0.4) + geom_point()
We can check that the statistical properties have been preserved up to 2 significant figures:
cbind(dino = signif(mean_cor(start), 2), last = signif(mean_cor(metamers[[length(metamers)]]), 2)) #> dino last #> [1,] 54.000 54.000 #> [2,] 48.000 48.000 #> [3,] -0.064 -0.064
However, a semi random cloud of points is not that interesting, so we
can specify a minimizing function so that the result is similar to
metamerize will start from the last metamer of the
previous run if the
data argument is a list of metamers and append the
target1 <- subset(datasauRus::datasaurus_dozen, dataset == "x_shape") target1$dataset <- NULL
metamers <- metamerize(metamers, minimize = mean_dist_to(target1), N = N)
Now the result is a bit more impressive.
ggplot(metamers[[length(metamers)]], aes(x, y)) + geom_point(data = start, color = "red", alpha = 0.5, size = 0.4) + geom_point()
We can animate the whole thing. Since 19552 metamers is overkill, first we keep only 200 of them.
library(gganimate) metamers_anim <- trim(metamers, 30*2) ggplot(as.data.frame(metamers_anim), aes(x, y)) + geom_point() + transition_manual(.metamer) #> nframes and fps adjusted to match transition
You can freehand your own starting or target data with the
utility, that will open a shiny interface. You might need to install
Metamerizing operations can be chained while changing the minimizing function.
library(magrittr) target2 <- subset(datasauRus::datasaurus_dozen, dataset == "star") target2$dataset <- NULL metamers <- metamerize(start, preserve = mean_cor, minimize = mean_dist_to(target1), N = N) %>% set_minimize(mean_dist_to(target2)) %>% metamerize(N = N) %>% set_minimize(mean_dist_to(start)) %>% metamerize(N = N)
And the full sequence
trim(metamers, 30*3) %>% as.data.frame() %>% ggplot(aes(x, y)) + geom_point() + transition_manual(.metamer)
Functions in metamer
|mean_dist_to||Mean minimum distance|
|mean_self_proximity||Inverse of the mean self distance|
|metamer-package||metamer: Create Data with Identical Statistics|
|delayed_with||Apply expressions to data.frames|
|densify||Increase resolution of data|
|set_minimize||Set metamer_list attributes|
|trim||Trim a metamer_list|
Last month downloads
|Packaged||2019-09-18 18:26:00 UTC; elio|
|Date/Publication||2019-09-18 18:40:02 UTC|
Include our badge in your README