Draw new samples from the supplied data given its mean and covariances.
Source:R/0_util.r
rnorm_from.Rd
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.
See also
Other cheem utility:
as_logical_index()
,
color_scale_of()
,
contains_nonnumeric()
,
is_discrete()
,
is_diverging()
,
linear_tform()
,
logistic_tform()
,
problem_type()
,
sug_basis()
,
sug_manip_var()
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 18.41074 6.000000 199.0478 93.66847 2.057689 4.028930 21.68524 2.473926
#> 2 18.84409 6.000003 189.1925 96.99392 4.261473 3.610279 19.92308 1.418200
#> 3 18.48890 6.000000 174.8186 106.23930 3.894288 3.634944 19.44345 1.507565
#> am gear carb
#> 1 -1.4739273 3.015124 0.4419826
#> 2 -0.4181972 3.356904 2.6448460
#> 3 -0.5075606 3.752005 3.3164584