Skip to contents

Creates new observation of the data given its specific means and shapes. typically applied to a cluster subset of data. ie draw from cluster 'a', then assign to cluster 'b'.

Usage

rnorm_from(
  data,
  n_obs = 1,
  var_coeff = 1,
  method = c("pearson", "kendall", "spearman")
)

Arguments

data

A data.frame or matrix to sample from.

n_obs

Number of new observations to draw. Defaults to 1.

var_coeff

Variance coefficient, closer to 0 make points near the median, above 1 makes more points further away from the median. Defaults to 1.

method

The method of the covariance matrix. Expects "person" (continuous numeric), "kendall" or "spearman" (latter two are ranked based ordinal).

Value

A data.frame, sampled observations given the means and covariance of the data based on with column names kept.

Examples

library(cheem)

sub <- mtcars[mtcars$cyl == 6, ]
## Draw 3 new observations in the shape of 6 cylinder vehicles, with reduced variance.
rnorm_from(data = sub, n_obs = 3, var_coeff = .5)
#>        mpg      cyl     disp       hp     drat       wt     qsec        vs
#> 1 20.31809 5.999999 142.6738 124.1745 4.414789 2.780253 16.25343 0.3117120
#> 2 20.41092 5.999998 163.6461 111.4028 4.482989 2.915600 17.40170 0.4973448
#> 3 19.79153 6.000002 140.9426 125.8661 4.056718 2.957327 16.61406 0.6036859
#>          am     gear     carb
#> 1 0.6882865 4.748623 6.126656
#> 2 0.5026533 4.148876 4.768106
#> 3 0.3963126 4.774050 5.922048