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