Simulate (un)clustered data assuming multivariate non-normal distributions
Source:R/utils.R
sim_clust.Rd
Simulate 1 or 2 clusters assuming multivariate non-normal distributions (specifying correlations, skewness, kurtosis, and the number of indicators) and the degree of separation (effect size) in standard deviation units (standardized data). The function can works in two different ways.
When
udata
isNULL
: need to be specified or left to the default valueWhen
udata
is provided: parameters are taken fromudata
that is the result of calling the prep_user_data function.
Usage
sim_clust(
nclust = 1,
n = NULL,
dmin = 0,
dmax = NULL,
rmin = NULL,
rmax = NULL,
nind = NULL,
skewmin = 0,
skewmax = NULL,
kurtmin = 0,
kurtmax = NULL,
pn1 = 0.5,
debug = FALSE,
udata = NULL
)
Arguments
- nclust
The number of clusters. Can be 1 or 2, default to 1
- n
The total number of observations. If
nclust
is 1,n
is the number of observations, ifnclust
is 2,n * (1 - pn1)
is the number of observations for the cluster 2.- dmin
the lower bound for the range of effect sizes (in ~Cohen's d like scale).
- dmax
the lower bound for the range of effect sizes (in ~Cohen's d like scale). If not specified,
dmax
takes the value ofdmin
thus the effect size is the same for all indicators.- rmin
the lower bound for the range of correlations between indicators. TODO The correlation is assumed to be the same within each cluster.
- rmax
the upper bound for the range of correlations between indicators. If not specified,
rmax
takes the value ofrmin
thus using a single value.- nind
the number of indicators
- skewmin
the lower bound for the range of skewness.
- skewmax
the upper bound for the range of skewness. If not specified,
skewmax
takes the value ofskewmin
thus using a single value.- kurtmin
the lower bound for the range of kurtosi
- kurtmax
the upper bound for the range of kurtosi. If not specified,
kurtmax
takes the value ofkurtmin
thus using a single value.- pn1
the proportion of observations belonging to the 1 cluster. Default to
0.5
.- debug
logical indicating if returning the vectors of true values when sampling from a range.
- udata
list of summary statistics to use in the simulation. When specified, previous arguments are ignored.
Examples
# simulating with parameters
X <- sim_clust(nclust = 2, n = 100, dmin = 2, rmin = 0.5, nind = 5)
X
#> x1 x2 x3 x4 x5 group
#> 1 -1.98401049 -4.527229427 -2.63707458 -2.84033387 -1.738574224 1
#> 2 -2.72787907 -2.548290505 -2.47074550 -3.08151078 -3.781461092 1
#> 3 -2.34641061 -2.610768507 -1.46967636 -1.30770608 -3.008965336 1
#> 4 -0.65496744 -0.434667621 0.42467850 -0.33175420 -1.925022815 1
#> 5 -0.96467654 -1.350053151 -1.38822578 -2.06679334 -0.976647660 1
#> 6 -3.17648915 -3.964206046 -2.94910305 -3.38263724 -2.814942395 1
#> 7 -2.25613078 -2.696396578 -0.83205286 -1.93596130 -2.899296376 1
#> 8 -4.39539574 -2.502936068 -3.60835290 -2.75589339 -2.934781123 1
#> 9 -2.42184029 -2.511673079 -2.94727946 -1.27554629 -1.286244927 1
#> 10 -2.21180426 -0.331547438 -1.32062872 -0.36953761 -0.478215429 1
#> 11 -2.01163581 -1.990314196 -3.08021736 -2.00999292 -2.606292922 1
#> 12 -1.16133485 -1.671341771 -1.98717173 -0.34013351 -1.116116486 1
#> 13 -3.23455393 -3.571337474 -3.56244131 -2.15986052 -2.182705742 1
#> 14 -0.46221008 -1.222816816 -1.69894416 -2.10613706 -1.486207416 1
#> 15 -1.26623752 -0.786665588 -1.99827231 -2.30143136 -1.004882978 1
#> 16 0.68559875 -0.983113596 -0.40441256 -0.64518242 0.035862793 1
#> 17 -1.33808584 -1.576065721 -2.98399323 -2.31769683 -2.482365846 1
#> 18 -2.46331033 -1.779480439 -3.26449692 -3.05193459 -2.467539905 1
#> 19 -1.39930031 -0.977492935 -0.51711611 -2.35339030 -1.045359298 1
#> 20 -2.11795637 -2.101054575 -2.39447121 -1.13949644 -2.601039396 1
#> 21 -2.59431792 -1.042756031 -1.22810586 -1.73230738 -1.792351057 1
#> 22 -2.77479242 -1.369882085 -0.67393157 -0.52651796 -2.093193558 1
#> 23 -3.40386457 -3.079028557 -2.07027852 -2.80998078 -1.285858319 1
#> 24 -2.39067259 -1.676589872 -2.95469488 -2.56915909 -3.865073249 1
#> 25 -0.48542566 -2.730753345 -1.52493008 -1.57669108 -0.866898930 1
#> 26 -2.18636074 -3.639744636 -2.75429819 -2.99055387 -2.363002268 1
#> 27 -2.01228246 -0.920602942 -2.20069433 -1.46462287 -1.869670622 1
#> 28 -2.96211506 -4.268241161 -4.56223015 -3.08372852 -3.487435505 1
#> 29 -3.08666467 -3.225876129 -3.86381080 -4.09560109 -4.308957860 1
#> 30 -2.43070379 -0.754248638 -1.85662270 -1.10450992 -2.863527009 1
#> 31 -2.73207668 -1.936193060 -1.88098716 -2.61728848 -2.004225333 1
#> 32 -1.07361372 -2.194920435 -1.66316144 -1.81910932 -0.670543217 1
#> 33 -1.49033081 -0.783050033 -3.80214072 -0.60300822 -0.625636751 1
#> 34 -1.89193237 -2.138393869 -2.92948226 -1.63304851 -4.053714916 1
#> 35 -0.90638721 -1.155780406 -2.08801319 -1.73935933 -1.828208105 1
#> 36 -1.40491642 -1.871584447 -2.72228211 -1.92907034 -1.785183600 1
#> 37 -0.52306608 -1.947950773 -1.59043182 -0.69509906 -0.935645095 1
#> 38 -1.80539245 -2.253457236 -0.85682373 -1.61017458 -1.184977745 1
#> 39 -3.65993925 -2.522223795 -1.18820422 -2.71135152 -3.237213419 1
#> 40 -1.63272830 -3.458565147 -3.10561845 -1.46918230 -2.304841427 1
#> 41 -1.38037017 -2.764150054 -2.40142960 -2.54089832 -2.451128645 1
#> 42 -2.80390133 -1.345647375 -2.00955707 -2.97806394 -2.360734687 1
#> 43 -2.60015778 -2.759411121 -2.06980954 -2.10612760 -1.898025244 1
#> 44 -3.11607015 -2.372057432 -3.45504708 -2.57345021 -2.498586414 1
#> 45 -2.92521116 -4.265734359 -4.08862886 -3.41953635 -4.436347065 1
#> 46 -0.56707430 -2.879469673 -1.75150747 -1.47799623 0.214413297 1
#> 47 -3.38475365 -3.671726513 -3.10281484 -2.05448719 -2.726593126 1
#> 48 -0.23084556 -0.914203998 -1.14444604 -1.22869734 -0.908235105 1
#> 49 -2.61038155 -2.676119544 -1.07607948 -1.77839818 -2.006745376 1
#> 50 -1.98967343 -2.039634604 -1.28167132 -1.60328125 -1.135412668 1
#> 51 -2.56452142 -2.442070719 -1.95702454 -1.97222605 -2.603699785 2
#> 52 1.09861981 0.844090474 0.61028399 0.42149934 -0.005354655 2
#> 53 -2.11099175 -1.279929031 -1.34460018 -0.37437183 -1.954085930 2
#> 54 -0.68817604 -1.224910519 0.40067543 1.04865269 -0.349474794 2
#> 55 0.09715730 0.044005927 0.55752121 0.94986423 -0.389921148 2
#> 56 -1.29271773 -1.532307294 -0.50305818 -1.30998862 -1.624719817 2
#> 57 -2.06322037 -0.639133728 -0.78916698 -2.33377477 -1.844784676 2
#> 58 -1.44020364 -0.319014620 -0.82006004 0.25677953 -0.061847459 2
#> 59 1.54124872 1.829268114 2.25405929 2.61642504 1.712258404 2
#> 60 -0.37961093 0.414012613 0.94046097 -1.47103560 -0.067036022 2
#> 61 0.02144019 0.320994584 -0.09580214 -0.47671101 -0.654281345 2
#> 62 1.83320404 1.595355681 1.21401290 1.63638232 1.315434459 2
#> 63 1.15527929 0.626810696 1.11327612 -0.57700617 1.258151384 2
#> 64 1.51542064 0.866325326 0.55105334 1.61350762 0.532153243 2
#> 65 0.77395342 0.715442596 1.13805811 1.61961590 -0.088109791 2
#> 66 0.82616564 -0.207787039 1.14813274 1.09616576 0.583234184 2
#> 67 -0.09062488 0.127013084 -0.05070234 -0.23174065 -0.893779742 2
#> 68 -0.82058882 -0.900614518 -0.22177936 0.16415166 -0.757552163 2
#> 69 0.11660759 -0.245504173 -1.36537396 -1.24953546 -0.708789382 2
#> 70 0.48514954 0.152697067 0.91770860 0.31921079 0.104013513 2
#> 71 1.00681704 1.287832122 1.31865081 0.88405691 -0.180343930 2
#> 72 0.72037154 0.503000260 1.86892651 1.94704746 1.089736835 2
#> 73 -0.31990618 -0.024621277 -0.42419004 0.05841436 -0.657600664 2
#> 74 0.41388271 0.622580103 -0.49992256 0.25036277 -0.740156544 2
#> 75 -1.09690059 -0.694412921 0.38233938 -1.12912729 -0.760806737 2
#> 76 -0.70858012 -0.212652029 -0.22128056 0.45670740 0.329955649 2
#> 77 1.28744485 1.717289164 1.41148441 1.99592231 1.665735943 2
#> 78 0.25201231 1.919085090 1.13410498 0.52036075 0.297959339 2
#> 79 -1.88929077 1.476362269 -0.95579809 -1.03378462 -0.553372287 2
#> 80 2.02859424 1.335924164 1.15460321 1.28578532 0.048674999 2
#> 81 2.07872913 -0.630401734 -0.09644347 0.42399087 -1.056295720 2
#> 82 1.66745838 0.002585383 -0.88127474 0.75337354 1.186452184 2
#> 83 0.02033544 -0.805458612 1.16304143 0.53683250 -0.807700350 2
#> 84 0.62580106 0.672799069 0.11611506 0.08123568 0.555597069 2
#> 85 -0.18620956 -0.342089263 -0.94889551 -1.15991168 -1.214108167 2
#> 86 0.29041169 -0.942156928 0.45213803 1.21639623 -0.516029450 2
#> 87 0.45705344 0.777586805 0.10113160 -1.29287736 0.303146176 2
#> 88 1.85395866 0.282932886 2.02348129 1.13845513 0.854551715 2
#> 89 0.75449886 -0.466904446 -1.41840127 0.07009583 -0.533430375 2
#> 90 -0.83073003 -1.158256526 -0.49495581 -1.24208331 -2.365108644 2
#> 91 -0.81193974 -0.979326087 -1.30648205 -2.36302950 -1.011314381 2
#> 92 1.27128060 0.164552490 -1.77582863 -0.01216554 0.598762786 2
#> 93 0.86703493 1.097882038 1.20251960 1.71441447 1.201807758 2
#> 94 -0.92317071 0.516964442 -0.29119191 -2.30586101 -1.855177203 2
#> 95 -0.99130839 -0.483686308 -0.14047633 -0.04084626 0.352968480 2
#> 96 -0.41537993 0.978417196 0.06407567 -0.38945631 -0.137361596 2
#> 97 0.51241034 0.997156367 1.70514734 -0.14765827 0.155688100 2
#> 98 0.43519424 0.404155296 1.53402766 2.25042188 1.206219725 2
#> 99 0.38727387 -0.309931700 -1.17484387 -1.03085387 -1.146486811 2
#> 100 -0.95615025 -1.248384669 -1.39667448 -1.14022800 -0.548282270 2
# with external data
udata <- prep_user_data(X)
sim_clust(udata = udata)
#> x1 x2 x3 x4 x5 x6
#> 1 -1.11046053 -1.7045173125 -0.23298673 -0.560472970 0.035581235 1
#> 2 0.07787598 0.5528600921 -0.23476503 -0.270296051 0.348671089 1
#> 3 -0.05960887 0.0284960921 0.93128862 -0.619379330 -0.043296908 1
#> 4 1.27764288 0.6336756339 -0.13397348 -0.051261695 1.434925531 1
#> 5 1.36827020 1.3395996022 1.20956754 2.043442648 1.490220408 1
#> 6 0.32379480 -0.0166131268 -0.32173566 0.052908887 0.033568652 1
#> 7 -1.78519278 -1.9668540068 -1.72068244 -1.397537080 -2.444093379 1
#> 8 0.15523903 0.2097105178 -1.18700628 -0.419173484 0.533113309 1
#> 9 0.21000449 1.1013939366 0.52113735 -0.161236165 0.200127280 1
#> 10 0.08412244 -0.3362396835 0.37925864 0.003724700 -0.686510770 1
#> 11 1.10593665 1.2891923225 1.66401754 1.387311746 1.059053794 1
#> 12 -1.28317835 -2.2072511103 -1.41035800 -1.638849717 -1.493139848 1
#> 13 0.02659329 1.0140106042 0.63594650 0.261732891 0.284600137 1
#> 14 0.86465642 0.5675854492 1.04338777 1.094381715 0.041350184 1
#> 15 -0.80354004 -0.1036467428 0.26657960 -0.158887295 0.870660835 1
#> 16 0.50765342 0.0017913503 -0.61433587 -0.728250644 -0.268071006 1
#> 17 1.47252405 -0.2920142121 -0.15264008 0.525762877 0.697349376 1
#> 18 -0.15129841 -0.6307995221 -0.30751562 -0.753480912 -0.373801220 1
#> 19 1.69074294 1.5828922862 1.29159876 1.579471646 0.847941548 1
#> 20 1.06412994 1.7556917522 1.09715881 0.854643844 0.974097710 1
#> 21 -1.35682626 -1.5907766371 -0.61577003 -0.665061482 -1.098134844 1
#> 22 -1.31358793 -1.0864167041 -1.07013427 -0.641040428 -0.860370777 1
#> 23 2.01522809 1.9541279271 2.04750750 2.073757178 2.043872947 1
#> 24 -0.95066288 0.0383811063 0.28503424 -0.052901815 0.024155028 1
#> 25 0.60863948 0.6754888760 0.97918147 0.881070486 0.272750481 1
#> 26 -0.37268269 1.6530090064 0.99444428 1.191851192 0.928031038 1
#> 27 0.92815565 1.1534413550 0.55612110 0.685137147 0.866330492 1
#> 28 1.30644840 1.1503639701 0.71526582 1.151717283 1.191919029 1
#> 29 1.45475950 0.9174046735 0.84893596 -0.455686377 0.839255825 1
#> 30 -1.14895214 -1.3764331474 -0.67053730 -1.542221232 -0.756056608 1
#> 31 1.13461112 0.8481213412 0.62275576 0.493460971 0.812344745 1
#> 32 1.58154161 0.8851297525 0.77061697 1.669943396 1.375061847 1
#> 33 0.68189124 -0.1324547394 0.75752784 0.629312121 -0.742471409 1
#> 34 0.48570866 0.0743344018 0.97047311 0.907408811 0.405914648 1
#> 35 1.25698484 1.7214378223 1.55200919 1.899047876 1.731787286 1
#> 36 0.36904122 -0.3876554433 -0.17229325 -0.968923101 0.134958514 1
#> 37 1.30002870 1.2789821678 1.33830454 1.234074595 1.504841036 1
#> 38 -0.77579444 -0.3774239388 -0.52609531 0.010032889 -0.033405152 1
#> 39 -0.22592891 -0.4040572139 -0.42051062 -0.172522412 0.244426861 1
#> 40 -0.82705139 -1.7178794056 -1.61700848 -0.831787520 -0.845642736 1
#> 41 0.60184635 -0.0968280246 -0.10110556 -0.257564384 -1.281860480 1
#> 42 0.25501892 -0.7420591314 -1.10165700 -0.747774236 -0.197475014 1
#> 43 1.80849729 1.4196399170 0.68236525 0.827243534 0.343919781 1
#> 44 -0.46483953 -0.7345626937 -0.53372362 -0.528681950 -0.097410386 1
#> 45 0.86723810 0.9981224027 1.34507051 0.836917617 1.087448677 1
#> 46 -0.42241093 -0.9557473546 -0.15860504 0.102474420 0.809670286 1
#> 47 1.59848351 1.2313393985 1.44210397 1.374590601 1.434396865 1
#> 48 0.80036384 0.8090307445 0.79503460 0.602922745 0.754821936 1
#> 49 -1.78913184 -1.7135340650 -2.00152703 -1.540171442 -1.855374080 1
#> 50 -1.57775174 -1.7469082382 -1.49843758 -1.511148029 -1.857586645 1
#> 51 -1.52549448 0.6116754842 0.35078824 0.144219316 -0.729017109 1
#> 52 -0.63382018 0.1664441615 0.57034979 -0.637421632 -0.457585661 1
#> 53 -0.08024854 0.0857036720 -0.18711685 -0.144977195 -0.323538960 1
#> 54 -0.31863148 0.2491147538 0.35154494 0.477473389 0.383562120 1
#> 55 -1.06815848 0.0694373245 0.15717776 0.085693699 0.072077667 1
#> 56 1.07508606 1.1147718604 1.23521378 0.743907475 0.929173021 1
#> 57 1.19039628 0.9020042138 0.90683280 2.037859335 1.689566932 1
#> 58 0.95459244 0.3279031879 -0.06602360 0.439179457 0.513575312 1
#> 59 0.09683995 0.3516977952 0.39073988 -0.864385464 -0.291524841 1
#> 60 -0.17534970 -0.9311509789 -0.18371116 -0.508109170 -0.540862230 1
#> 61 1.31436077 0.5042416808 1.00807379 0.927949496 1.239230668 1
#> 62 1.50283181 0.5836268056 0.82313506 -0.113215823 1.086985532 1
#> 63 0.25680477 0.9491985282 0.85351231 -0.009582913 -0.304896542 1
#> 64 0.08979999 1.7264988794 1.55478038 1.657898748 1.088321568 1
#> 65 0.33125084 0.8415003622 0.85927049 0.005630863 0.554367098 1
#> 66 -1.33681967 -1.4683130281 -2.01054065 -1.619019940 -2.009855871 1
#> 67 -0.89877124 -0.2493236850 -1.23773407 -0.987113119 -1.516408783 1
#> 68 -0.36473892 -0.5993678339 -1.01046820 -0.224033740 0.051851787 1
#> 69 1.83350790 1.7213191116 2.08548523 1.107959806 1.008234618 1
#> 70 0.57466961 0.3051187875 -0.11066724 -0.518795447 0.838263539 1
#> 71 0.32354226 0.6796806918 0.85040848 -0.912186369 -0.095417465 1
#> 72 0.39600003 -0.2118721770 -0.29625628 0.864478587 0.236247659 1
#> 73 1.53736768 0.4247281504 0.70141358 1.339618935 0.485537652 1
#> 74 0.14173084 0.8621591961 0.80401005 -0.133577361 0.691399753 1
#> 75 -1.65707415 -1.3154148026 -1.47660140 -1.392865135 -1.880355561 1
#> 76 -0.23766318 -0.2589966791 -1.44750312 -1.278129081 -1.420282943 1
#> 77 -1.73611302 -1.1247445960 -1.44781265 -1.158551263 -1.811814147 1
#> 78 -0.22368847 -0.1210521100 -0.45793906 -0.494030512 -0.237993888 1
#> 79 1.82776981 0.7899951888 0.03818428 1.457331833 0.843821359 1
#> 80 1.25913814 1.2997011375 1.29089425 1.467942697 1.258294161 1
#> 81 0.34471561 -0.2770806583 -0.35178121 0.734881007 -0.054392731 1
#> 82 -0.57091595 0.2586926214 0.02869660 -0.250571109 -0.003202099 1
#> 83 0.84927013 1.0303817535 0.48231415 0.580845715 -0.151378086 1
#> 84 1.83506882 0.1141015316 0.58996522 0.313875337 0.969661718 1
#> 85 0.61056196 -0.1497741081 -0.57611410 0.092065602 -0.657942547 1
#> 86 -0.77224603 0.1588532274 -0.11076221 -1.274228632 -1.362792869 1
#> 87 0.67000619 0.3156587734 0.94686698 1.070415826 1.024019377 1
#> 88 1.15089447 0.3737667426 0.64789724 -0.181540998 0.846528964 1
#> 89 -0.11607350 -1.1461157861 -0.60972259 -0.799094624 -1.483466944 1
#> 90 0.73956951 1.3483824133 0.29704235 0.256381837 0.447767277 1
#> 91 -0.01319368 -0.1065240817 0.52176269 -0.346656771 0.136561984 1
#> 92 -0.82379689 0.0003148991 -0.68981166 0.102902427 -0.410754217 1
#> 93 1.88791883 1.5084337656 1.15667681 1.696768203 1.611677588 1
#> 94 -0.25486939 -0.4633021591 -1.01540758 -0.653891670 -1.232643715 1
#> 95 0.44238924 0.4614166752 0.62863318 0.621590717 0.894458105 1
#> 96 -0.90808444 -0.7832954905 -1.60284083 -1.411685630 -1.460771182 1
#> 97 -0.67100693 -0.3133826766 -0.77588509 -0.327709378 -0.394767825 1
#> 98 -0.06239489 0.1633738650 0.15565656 0.055773610 1.003535584 1
#> 99 -0.62636797 -0.4902043435 -0.84896099 -0.325323782 0.470247464 1
#> 100 -1.62190094 -2.1596624019 -1.82090063 -1.552605866 -1.654394232 1