
Simulate from Parameterized MVN Mixture Models
sim.RdSimulate data from parameterized MVN mixture models.
Arguments
- modelName
A character string indicating the model. The help file for
mclustModelNamesdescribes the available models.- parameters
A list with the following components:
proA vector whose kth component is the mixing proportion for the kth component of the mixture model. If missing, equal proportions are assumed.
meanThe mean for each component. If there is more than one component, this is a matrix whose kth column is the mean of the kth component of the mixture model.
varianceA list of variance parameters for the model. The components of this list depend on the model specification. See the help file for
mclustVariancefor details.
- n
An integer specifying the number of data points to be simulated.
- seed
An optional integer argument to
set.seedfor reproducible random class assignment. By default the current seed will be used. Reproducibility can also be achieved by callingset.seedbefore callingsim.- ...
Catches unused arguments in indirect or list calls via
do.call.
Value
A matrix in which first column is the classification and the remaining
columns are the n observations simulated from the specified MVN
mixture model.
- Attributes:
"modelName"A character string indicating the variance model used for the simulation.
Details
This function can be used with an indirect or list call using
do.call, allowing the output of e.g. mstep, em,
me, Mclust to be passed directly without the need to
specify individual parameters as arguments.
Examples
irisBIC <- mclustBIC(iris[,-5])
irisModel <- mclustModel(iris[,-5], irisBIC)
names(irisModel)
#> [1] "modelName" "n" "d" "G" "bic"
#> [6] "loglik" "parameters" "z"
irisSim <- sim(modelName = irisModel$modelName,
parameters = irisModel$parameters,
n = nrow(iris))
# \donttest{
do.call("sim", irisModel) # alternative call
#> group x1 x2 x3 x4
#> [1,] 2 5.892364 3.112100 4.884095 2.16021048
#> [2,] 2 6.991952 2.878990 5.806907 1.66075063
#> [3,] 2 6.777374 2.962417 6.046605 2.28083930
#> [4,] 1 5.096752 3.333028 1.688420 0.42348554
#> [5,] 2 6.320879 3.068921 4.766376 1.51954776
#> [6,] 2 6.654859 3.367376 5.578925 2.08671560
#> [7,] 2 6.086514 3.447387 4.545482 1.70261637
#> [8,] 2 6.584607 2.569003 5.282048 1.54499898
#> [9,] 2 5.820641 2.834722 3.567591 1.27709905
#> [10,] 2 6.936317 2.803664 5.033749 1.61229071
#> [11,] 2 6.187352 2.779145 4.002027 1.34937277
#> [12,] 2 6.391023 3.439651 5.506473 1.94829994
#> [13,] 2 5.821579 3.221585 5.698060 2.65577631
#> [14,] 2 6.623737 2.837080 5.062102 1.59777090
#> [15,] 1 4.225739 2.531858 1.374776 0.37311121
#> [16,] 2 6.145366 2.830184 3.674388 0.91072912
#> [17,] 2 6.908078 3.267487 5.170275 1.76870483
#> [18,] 2 5.327669 2.719041 4.657410 2.02213468
#> [19,] 1 5.092422 3.161678 1.523155 0.15852334
#> [20,] 2 5.609469 2.666261 3.780324 1.13129306
#> [21,] 2 6.070299 2.984665 3.993217 1.09715366
#> [22,] 2 6.097073 2.870138 5.599883 2.16885432
#> [23,] 2 7.241020 3.524912 7.174456 2.64273988
#> [24,] 2 5.708818 2.845093 4.991389 1.68593333
#> [25,] 1 5.534734 3.471212 1.670063 0.37811446
#> [26,] 2 6.177913 3.526097 5.449136 2.38037633
#> [27,] 1 4.566981 2.336040 1.324451 0.24936909
#> [28,] 2 6.440908 3.183295 4.502688 1.63328051
#> [29,] 1 5.327048 3.673121 1.652838 0.27522061
#> [30,] 2 6.198401 2.699261 5.225309 1.87436974
#> [31,] 2 5.915050 2.534643 4.370192 1.57655844
#> [32,] 1 4.661995 3.339097 1.475636 0.22379017
#> [33,] 1 5.702651 4.456313 1.539543 0.39955120
#> [34,] 2 5.890212 3.093981 5.099939 1.84081081
#> [35,] 2 6.608085 2.690905 4.889035 1.31232768
#> [36,] 2 5.855174 2.817782 4.650903 1.83459692
#> [37,] 1 5.462238 4.060700 1.253321 0.20323684
#> [38,] 2 4.975905 2.330940 3.311954 0.85387066
#> [39,] 2 6.731570 2.862077 5.010237 1.57612661
#> [40,] 2 7.535891 3.307274 6.516173 2.29362621
#> [41,] 2 7.653077 3.358806 5.503142 1.83430775
#> [42,] 2 6.078472 2.873623 4.903889 1.62690765
#> [43,] 2 5.279167 2.688735 3.899428 1.11836487
#> [44,] 2 5.960505 2.582242 4.747200 1.52267717
#> [45,] 2 5.515146 2.746771 3.585407 1.41787397
#> [46,] 1 4.764209 2.850615 1.663109 0.16409540
#> [47,] 1 4.928552 3.233658 1.485280 0.30098015
#> [48,] 2 6.781388 2.821283 5.728834 2.33538747
#> [49,] 2 6.161331 2.900146 3.717914 0.66744573
#> [50,] 2 4.585639 2.326796 2.523156 0.64747671
#> [51,] 1 4.759353 2.775279 1.566944 0.16900946
#> [52,] 2 7.133925 2.755869 6.097984 2.10875830
#> [53,] 2 6.598691 3.038344 5.577386 1.73653810
#> [54,] 1 4.437030 2.735303 1.541621 0.16808344
#> [55,] 1 4.979573 3.665843 1.374528 0.29896361
#> [56,] 1 5.275630 4.066582 1.273517 0.31353243
#> [57,] 1 4.566873 3.192958 1.291056 0.32149320
#> [58,] 2 6.021106 2.910992 5.454228 2.21283834
#> [59,] 2 5.713160 2.549318 4.069155 1.11177491
#> [60,] 1 4.926855 3.331165 1.338714 0.28616757
#> [61,] 1 5.031385 3.366812 1.779487 0.42224383
#> [62,] 2 5.754929 2.467422 4.279438 1.13216629
#> [63,] 2 4.794021 2.335134 3.392785 0.96291498
#> [64,] 2 6.507700 3.004900 5.383629 1.96301480
#> [65,] 1 4.962530 3.535605 1.464945 0.11857950
#> [66,] 1 5.802195 4.178015 1.826556 0.27199244
#> [67,] 2 5.780362 2.651567 4.416441 1.56364259
#> [68,] 2 5.898920 2.852802 3.705525 1.53756132
#> [69,] 2 6.818703 2.840126 6.090726 2.27437619
#> [70,] 1 4.858731 3.488462 1.624489 0.32400074
#> [71,] 2 5.288548 2.529982 4.112109 1.31804098
#> [72,] 2 5.921354 2.493543 4.130016 1.34785726
#> [73,] 2 6.420947 2.898328 5.797910 1.86496979
#> [74,] 1 5.093037 3.702605 1.521971 0.32133603
#> [75,] 2 6.458952 3.314090 5.255110 1.97437202
#> [76,] 1 4.620324 3.476975 1.106740 0.16079011
#> [77,] 2 6.963479 3.244091 5.863006 1.95583643
#> [78,] 2 5.951215 2.427276 4.297973 1.30215617
#> [79,] 2 6.829583 3.106950 5.975773 2.40391213
#> [80,] 2 5.641438 2.526931 3.356128 0.90077805
#> [81,] 2 6.288024 2.963692 4.877360 1.62792240
#> [82,] 2 6.201170 2.804769 5.361528 2.13030549
#> [83,] 2 6.271158 2.373553 5.136524 2.08767838
#> [84,] 2 5.241830 2.769173 3.607277 1.18569794
#> [85,] 1 4.890853 2.954173 1.641073 0.20111130
#> [86,] 2 6.985735 3.038542 5.751161 2.15434634
#> [87,] 2 6.767167 3.090215 5.694763 2.02499198
#> [88,] 1 4.879902 3.429815 1.312773 0.29583751
#> [89,] 2 6.263140 3.054319 5.828169 2.39407921
#> [90,] 2 6.116635 3.095454 4.694514 1.44228215
#> [91,] 2 5.891050 3.162495 4.781989 1.70128330
#> [92,] 1 4.968601 3.450250 1.774141 0.43160919
#> [93,] 1 5.010378 2.956539 1.438296 0.20700475
#> [94,] 1 5.623476 3.934419 1.589082 0.28616437
#> [95,] 2 6.058281 3.198752 4.449359 1.28475161
#> [96,] 2 5.316258 2.582679 3.265963 0.91796180
#> [97,] 2 6.916629 3.070882 5.403126 1.65306395
#> [98,] 2 5.561780 2.232689 4.765539 1.80613892
#> [99,] 2 5.766475 2.613175 4.709038 1.60941695
#> [100,] 1 5.355299 3.716190 1.544857 0.41200711
#> [101,] 2 7.528979 3.404533 6.354226 2.40734633
#> [102,] 2 6.477506 3.429970 4.976219 2.02222390
#> [103,] 2 5.721206 2.648260 4.456036 1.31094270
#> [104,] 1 4.750801 3.274771 1.460229 0.33085668
#> [105,] 2 6.772555 3.152354 5.942773 2.65485911
#> [106,] 2 6.198401 2.838707 4.551736 1.40373577
#> [107,] 2 6.881108 3.021152 5.933739 1.64769360
#> [108,] 2 6.498932 2.740648 5.769536 1.96223447
#> [109,] 1 4.745082 3.215049 1.222188 0.38081135
#> [110,] 2 6.368108 3.002078 5.348831 2.04957091
#> [111,] 2 5.311770 2.693833 3.863553 1.63854074
#> [112,] 2 6.506416 2.630877 5.094374 1.77762605
#> [113,] 1 4.644811 2.899309 1.488444 0.09113547
#> [114,] 1 4.779915 3.363293 1.392099 0.12270314
#> [115,] 2 6.159973 2.868307 5.283567 2.09428781
#> [116,] 2 5.981099 3.218350 5.119496 1.97433292
#> [117,] 2 6.143804 2.813042 4.884435 1.37483985
#> [118,] 2 7.450295 2.708364 6.585552 2.05633281
#> [119,] 2 7.056963 3.257373 6.378677 2.19836001
#> [120,] 2 5.697049 3.117381 5.143878 1.93892702
#> [121,] 2 6.361328 3.286884 5.308211 1.94621680
#> [122,] 2 6.725567 2.963505 6.243579 2.12027309
#> [123,] 1 5.166262 3.373826 1.515930 0.27959597
#> [124,] 1 5.619808 3.694652 1.432318 0.15071819
#> [125,] 2 7.305078 3.398196 6.720373 2.28609688
#> [126,] 1 5.543748 4.179103 1.444573 0.28769431
#> [127,] 2 6.596623 2.856318 4.842815 1.90432612
#> [128,] 2 6.048109 3.037725 4.540285 1.61891887
#> [129,] 1 4.711185 2.832472 1.555133 0.35788407
#> [130,] 2 7.459785 3.150028 5.966869 2.46113041
#> [131,] 2 6.578133 3.042483 5.620291 2.03261254
#> [132,] 2 5.807547 2.619390 3.857629 1.21301914
#> [133,] 2 6.234816 2.807685 4.719480 1.55065418
#> [134,] 2 7.513683 3.324514 5.588693 2.02573735
#> [135,] 2 6.357053 2.729336 4.845442 1.64427754
#> [136,] 2 5.144614 2.800920 3.519301 1.23948930
#> [137,] 2 5.960814 2.848935 4.504897 1.22033432
#> [138,] 2 6.607641 3.404001 5.262087 1.92780166
#> [139,] 2 5.204303 2.971066 3.638198 1.89481477
#> [140,] 1 4.832567 3.179596 1.391590 0.15193644
#> [141,] 1 5.197880 3.757896 1.200477 0.22251791
#> [142,] 1 5.415354 3.732182 1.462058 0.30820470
#> [143,] 2 5.549845 2.714582 3.192257 0.88433228
#> [144,] 2 5.835497 2.857555 4.447573 1.91537977
#> [145,] 2 5.900522 3.359951 4.403118 1.47297650
#> [146,] 2 6.427063 3.455046 4.351002 1.20418047
#> [147,] 1 4.688527 2.970280 1.481206 0.28833087
#> [148,] 2 5.019983 2.200212 3.867862 0.86502737
#> [149,] 2 6.416934 2.696552 4.749124 1.41959763
#> [150,] 1 5.267045 3.895190 1.229889 0.09935122
#> attr(,"modelName")
#> [1] "VEV"
# }
par(pty = "s", mfrow = c(1,2))
dimnames(irisSim) <- list(NULL, c("dummy", (dimnames(iris)[[2]])[-5]))
dimens <- c(1,2)
lim1 <- apply(iris[,dimens],2,range)
lim2 <- apply(irisSim[,dimens+1],2,range)
lims <- apply(rbind(lim1,lim2),2,range)
xlim <- lims[,1]
ylim <- lims[,2]
coordProj(iris[,-5], parameters=irisModel$parameters,
classification=map(irisModel$z),
dimens=dimens, xlim=xlim, ylim=ylim)
coordProj(iris[,-5], parameters=irisModel$parameters,
classification=map(irisModel$z), truth = irisSim[,-1],
dimens=dimens, xlim=xlim, ylim=ylim)
irisModel3 <- mclustModel(iris[,-5], irisBIC, G=3)
irisSim3 <- sim(modelName = irisModel3$modelName,
parameters = irisModel3$parameters, n = 500, seed = 1)
# \donttest{
irisModel3$n <- NULL
irisSim3 <- do.call("sim",c(list(n=500,seed=1),irisModel3)) # alternative call
# }
clPairs(irisSim3[,-1], cl = irisSim3[,1])