iter_matrix: Genetic algorithm for generating correlated binary data

Description Usage Arguments Details Value Author(s) Examples

View source: R/binary_data.R

Description

Starts the genetic algorithm based on a start matrix with specified marginal probabilities.

Usage

1
iter_matrix(X0, R, T = 1000, e.min = 1e-04, plt = TRUE, perc = TRUE)

Arguments

X0

Start matrix with specified marginal probabilities. Can be generated by start_matrix.

R

Desired correlation matrix the data should have after running the genetic algorithm.

T

Maximum number of iterations after which the genetic algorithm stops.

e.min

Minimum error (RMSE) between the correlation of the iterated data matrix and R.

plt

Boolean parameter that indicates whether to plot e.min versus the iteration step.

perc

Boolean parameter that indicates whether to print the percentage of iteration steps relativ to T.

Details

In each step, the genetic algorithm swaps two randomly selected entries in each column of X0. Thus it can be guaranteed that the marginal probabilities do not change. If the correlation matrix is closer to R than that of x0(t-1), X0(t) replaces X0(t-1).

Value

A list with four entries:

Xt

Final representativ data matrix with specified marginal probabilities and a correlation as close as possible to R

t

Number of performed iteration steps (t <= T)

Rt

Empirical correlation matrix of Xt

RMSE

Final RSME error between desired and achieved correlation matrix

Author(s)

Jochen Kruppa, Klaus Jung

Examples

1
2
3
4
5
6
### Generation of the representive matrix Xt
X0 <- start_matrix(p = c(0.5, 0.6), k = 1000)
Xt <- iter_matrix(X0, R = diag(2), T = 10000, e.min = 0.00001)$Xt

### Drawing of a random sample S of size n = 10
S <- Xt[sample(1:1000, 10, replace = TRUE),]

jkruppa/RepeatedHighDim documentation built on May 19, 2019, 12:45 p.m.