Simulate Responses from a Multivariate Linear Model
simulate.mlm.Rd
Simulate one or more sets of responses from a Multivariate Linear Model (mlm
) object.
Usage
# S3 method for mlm
simulate(object, nsim = 1, seed = NULL, ...)
Arguments
- object
a
mlm
object, typically the result of callinglm
where the response is a matrix.- nsim
number of replicate datasets to simulate. If
nsim
is greater than 1, the output is arranged in a 3D array.- seed
an object specifying if and how the random number generator should be initialized (‘seeded’). Either NULL or an integer that will be used in a call to set.seed before simulating the response vectors. If set, the value is saved as the "seed" attribute of the returned value. The default, NULL will not change the random generator state, and return .Random.seed as the "seed" attribute, see ‘Value’
- ...
additional optional arguments.
Details
A simulate
function for mlm
objects, which simulates one or more
sets of responses from a Multivariate Linear Model (mlm
) object.
If multiple sets of responses are requested, they are returned in a 3D array,
with simulation number along the third dimension.
The weights argument is currently ignored -- a constant
variance-covariance matrix assumed for mlm
.
Examples
# fit a mlm to iris data:
data(iris)
iris.mlm=lm(cbind(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width)~Species,data=iris)
# simulate new responses:
simulate(iris.mlm)
#> Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1 4.336916 3.302294 1.0655465 0.357512453
#> 2 4.999450 3.623973 1.1991732 0.062077577
#> 3 5.604429 3.699635 2.1581253 0.409349178
#> 4 4.543292 3.397669 0.6013372 0.065673549
#> 5 5.463020 3.815866 1.6159568 0.183198168
#> 6 5.217808 3.666341 1.5032789 0.056364542
#> 7 4.966177 3.234439 1.0318091 -0.221995856
#> 8 3.862762 3.300720 0.7474789 0.086696593
#> 9 5.471152 3.395154 1.2779887 0.286216505
#> 10 4.736237 3.232121 1.4274905 0.407265541
#> 11 5.203111 3.869303 1.4391318 0.320885240
#> 12 5.415536 3.240258 0.8915217 0.085430145
#> 13 5.517800 3.595918 1.6016970 0.126725501
#> 14 4.496256 3.378000 0.8334214 -0.285838012
#> 15 5.030510 2.820626 1.4022410 0.255177202
#> 16 5.003608 3.446451 1.7972413 0.502606187
#> 17 4.784378 2.803243 1.3009279 -0.092865725
#> 18 4.794786 3.683944 0.9266450 0.101945997
#> 19 5.016119 3.434994 1.4481522 0.079528150
#> 20 5.444475 3.646019 1.2399507 0.219955272
#> 21 4.374579 2.883973 1.0271984 0.032643661
#> 22 3.799422 3.352048 0.8365086 0.582640304
#> 23 4.686848 2.991298 0.8003915 0.035434056
#> 24 3.817982 3.255606 0.8671657 0.135237079
#> 25 5.823067 3.640148 2.2587962 0.337002223
#> 26 4.848502 3.838008 0.9419936 0.209524050
#> 27 5.652409 3.682440 1.9598032 0.788254490
#> 28 5.383920 3.792091 2.0067923 0.468740388
#> 29 5.571278 3.456241 2.0941643 0.365261530
#> 30 4.665286 3.263158 1.3453722 0.107213410
#> 31 6.139628 3.988680 2.2131573 0.354141068
#> 32 4.954216 3.452872 1.5758860 0.588163683
#> 33 4.794934 3.400422 1.3702270 0.127437060
#> 34 5.201829 3.655136 1.9068196 0.202102360
#> 35 4.834993 2.966788 1.5790213 0.478792679
#> 36 4.539678 3.754557 1.2470970 0.277762580
#> 37 4.040424 3.367444 0.9236220 0.335531183
#> 38 4.562593 3.570047 1.6891141 0.568590265
#> 39 4.685535 3.975402 1.0991837 0.377835503
#> 40 5.073963 3.007109 1.9139823 0.463899355
#> 41 4.590336 2.887275 1.3799042 0.075737779
#> 42 4.770576 3.303121 1.0387929 -0.006220087
#> 43 4.795753 2.963475 1.4193418 0.390901942
#> 44 4.082679 2.794251 0.6958916 0.133757790
#> 45 5.709013 3.322081 1.8105228 0.259768021
#> 46 4.359398 2.952260 0.9079627 0.206974281
#> 47 4.783100 3.692719 1.1066191 0.107446535
#> 48 4.978297 3.280499 1.2552357 0.177927519
#> 49 4.908920 3.767906 1.5642517 0.505926388
#> 50 4.802023 3.454341 1.4567397 0.435014435
#> 51 5.222038 2.127190 4.3222224 1.416924654
#> 52 5.645913 2.716593 4.3486244 1.301081935
#> 53 5.797004 2.548227 3.5668266 0.974435812
#> 54 6.692272 3.554555 4.7945396 1.574447559
#> 55 6.139433 2.626301 4.4274981 1.645730987
#> 56 6.551989 2.604634 4.5860860 1.188845212
#> 57 6.142630 3.145209 4.5025629 1.624479974
#> 58 5.905346 2.924798 4.7017806 1.507749654
#> 59 5.314792 2.934509 3.5306289 0.948337652
#> 60 7.098745 2.942736 4.5637498 1.200442525
#> 61 5.748124 2.304335 4.6761477 1.045295005
#> 62 5.425747 2.797674 3.5993406 1.230948954
#> 63 5.682453 2.837386 4.0115068 1.133776234
#> 64 6.045053 3.118178 4.2818956 1.401275611
#> 65 6.131729 2.733139 3.9996780 1.169157551
#> 66 6.856804 2.969492 4.8355750 1.365334460
#> 67 6.711292 3.537815 4.9481638 1.433814269
#> 68 5.247052 3.154978 3.5354056 1.500380749
#> 69 5.205820 2.700971 3.9120518 1.422962585
#> 70 5.904450 2.798192 3.6462632 1.023506685
#> 71 6.166418 3.085760 4.3441872 1.344354074
#> 72 5.853480 2.913167 4.1372388 1.014912134
#> 73 5.805559 2.888758 3.9798132 1.327062631
#> 74 6.350974 3.146418 4.6627593 1.922905088
#> 75 6.112547 2.289783 4.1097220 1.315881890
#> 76 4.962438 2.844760 3.4114316 0.980966973
#> 77 6.716821 3.215090 5.0696865 1.583356280
#> 78 5.472202 2.741330 4.1295824 1.143897527
#> 79 6.215121 2.834899 4.5875745 1.537152814
#> 80 6.511913 2.803995 4.5482535 1.618641417
#> 81 5.709226 2.969794 4.2266390 1.465505916
#> 82 6.678718 3.044717 4.0672401 1.230321625
#> 83 6.028321 3.320140 4.3525800 1.180722483
#> 84 6.646716 2.746347 4.5721907 1.357142726
#> 85 6.367476 2.926351 4.6819694 1.127758978
#> 86 4.857565 2.461974 3.0783166 0.883127026
#> 87 5.299653 2.583602 3.8513474 1.415159954
#> 88 5.698976 2.675003 4.0702179 1.351758071
#> 89 5.512216 2.300797 3.7330678 1.128732489
#> 90 4.623883 2.370225 3.5775215 1.130302693
#> 91 6.240665 2.277810 4.1788140 1.232169011
#> 92 6.087451 2.584618 4.0498388 1.471463678
#> 93 5.478446 2.612714 4.0474417 1.477313720
#> 94 5.848614 3.095772 4.3998817 1.367682786
#> 95 7.086631 3.522268 5.2687164 1.331588993
#> 96 6.211838 3.076436 4.1055472 1.095908038
#> 97 6.002653 3.284956 4.1781268 1.109013178
#> 98 6.138321 3.032698 4.2206452 1.271257947
#> 99 5.612078 1.955602 3.8483107 0.950520530
#> 100 5.387791 2.585871 4.0534958 1.300226678
#> 101 6.109109 3.174173 5.2863727 2.123841828
#> 102 6.654060 2.807181 5.7429435 1.961218683
#> 103 6.578857 2.646414 5.5173787 1.729005453
#> 104 6.709594 3.244316 5.4958830 2.213021084
#> 105 6.130859 2.117414 5.6086684 1.965999140
#> 106 7.323109 3.386410 5.8440638 2.114664494
#> 107 6.348766 2.494370 5.6246031 1.905599714
#> 108 5.719429 2.627175 5.3870401 1.966145980
#> 109 6.680861 2.776263 5.6317561 2.205143068
#> 110 6.063729 2.603839 5.2503195 2.082270769
#> 111 5.993545 2.613627 5.1682384 1.950610322
#> 112 6.433180 2.713894 5.0168204 1.711174372
#> 113 6.445543 3.062025 5.1708961 1.786020764
#> 114 7.188935 3.145223 6.4646123 2.359654150
#> 115 5.879371 2.602529 4.7989566 1.757216904
#> 116 7.144083 2.691936 5.8826172 1.885874452
#> 117 6.975279 3.392152 5.5047350 2.024233024
#> 118 6.964330 3.492077 5.5293545 1.950612218
#> 119 6.813324 2.929891 5.7119235 2.009599664
#> 120 6.473374 3.003043 5.8324610 2.187706308
#> 121 6.901055 3.079829 6.0976525 1.976882883
#> 122 6.306943 3.173030 4.7839764 1.719381979
#> 123 6.939606 3.028750 5.7276999 1.861496032
#> 124 6.534613 2.923999 5.4384862 1.882897509
#> 125 7.397111 3.626258 6.4217910 2.423149829
#> 126 6.904817 2.878209 5.7891815 2.320763233
#> 127 6.716035 3.034870 5.8359434 2.150062119
#> 128 6.441794 2.765835 5.2087663 1.897058419
#> 129 6.622187 2.814523 5.7830912 2.045676439
#> 130 7.441916 3.490116 5.7139068 2.269232167
#> 131 6.119714 2.441379 5.3372853 1.858436715
#> 132 6.194215 2.989606 5.5399715 2.142893967
#> 133 6.751274 3.348805 5.7165231 2.152378567
#> 134 7.184168 2.844971 6.0477861 1.837648884
#> 135 6.556811 2.839886 5.4212140 1.859830795
#> 136 6.212986 3.309459 5.2718665 2.329933640
#> 137 6.315092 2.700631 5.7777152 2.048199860
#> 138 6.831832 2.426720 6.1024053 2.090017202
#> 139 6.973475 2.804196 6.3110226 1.928377777
#> 140 7.525311 3.570252 6.6292735 2.271349537
#> 141 7.097458 2.756129 5.6013577 1.981799272
#> 142 6.395872 2.748474 5.3337711 2.080530580
#> 143 7.092580 3.040316 6.1199487 2.610621120
#> 144 6.464641 2.764840 5.3276726 2.099441846
#> 145 5.476357 2.429601 4.8630119 1.732049451
#> 146 6.372983 2.915704 4.9520193 2.012545436
#> 147 6.500336 2.804972 5.7684896 1.920552636
#> 148 6.004531 2.549659 5.0480735 1.867625449
#> 149 5.713977 2.910763 4.7612137 1.662817867
#> 150 7.063747 3.615826 5.5870328 1.949627101
#> attr(,"seed")
#> [1] 10403 105 -802819175 1308174257 975111926 2083703866
#> [7] 277424902 1908132130 1112657491 -1273946601 -1473554414 198365903
#> [13] 49687224 -1223710413 -1466242984 1657177216 260534901 1113903553
#> [19] 1242484906 -2018521572 -1840861909 1715514726 -1777731694 1340185998
#> [25] -1873691368 640934949 1243787079 2016966480 1431390740 -209794888
#> [31] -1143723501 497399893 -1307650054 1091380869 -1126219183 -1156864859
#> [37] -1734243265 828615690 -730247123 -1000514871 -1144238009 1774513374
#> [43] -353885763 818292075 1431507032 -1601852000 -1851388927 -821053738
#> [49] -889574745 1150863517 175920583 -76782783 -464601878 -78262845
#> [55] 487613747 8279529 582857710 -1958584670 1051525873 -1612402708
#> [61] -825266061 699609543 -309571552 -1835348875 1574764555 446812929
#> [67] -900568935 806904028 1644300871 1291475728 -608117865 23078898
#> [73] 1773205822 -840045719 1383258365 1021899464 675767064 -600497314
#> [79] 1323492513 -2100156047 1416587295 -1989140590 1823735233 -457734509
#> [85] -1847862563 158437481 1759214325 -239439835 1977780848 117092891
#> [91] -412990103 254845429 -723155453 -14556557 -1502762790 -1591168503
#> [97] -747693470 553577372 1813950972 -528917268 -2043168062 977602597
#> [103] -2070373733 2130805618 798094629 -1964693093 677153723 200151114
#> [109] -477339916 -623765691 1670345296 882908914 812997798 -399290519
#> [115] -1787535695 -932320970 -1365549136 -98484008 448383417 1565806734
#> [121] 342802260 -1095041410 328540232 78509720 -1895789614 -1108154907
#> [127] -1246000716 -1092134526 -1382375536 129679939 -1468581607 328203642
#> [133] -1254496438 -1450175171 -218233143 375958169 1313615827 1210536204
#> [139] -189033409 313108663 -1405049430 -136859447 -931753968 -1838529681
#> [145] -63667802 -859949512 965152160 1009826687 -795388486 997312392
#> [151] 349403275 -1251615064 -1624615422 -1388577161 761710976 1149184787
#> [157] 1768191446 1411830207 -1102132894 1005991255 510880790 -1941925778
#> [163] 82316709 1906413004 1420316220 270228067 1204975701 -1110726042
#> [169] -856850199 -1033148300 -1253214449 420606275 -254202867 1335285668
#> [175] 651072240 1523051198 -589142145 520717577 -347922031 177851444
#> [181] -79971532 1576976682 1686095402 -1212168927 -55609113 1368153981
#> [187] -1201288502 -1664904676 935340035 -926070274 -1142390628 -1019333551
#> [193] -1358482835 -146982683 -1230415602 -780047610 -1889373773 1480563568
#> [199] -1285747718 -1370058354 1141011044 1971305863 1419915697 1625389837
#> [205] 1811458738 2078659550 -705736205 1921543798 1411524461 -1457560714
#> [211] 984816086 -1774504246 -1965240669 1930867581 1971172187 945883197
#> [217] 786382843 -1130301099 1090360984 -1714134338 -1554750759 1369942912
#> [223] -1410730490 -1983131011 -600228592 -741742715 -1179563991 782709636
#> [229] 1847047066 1908609595 808579721 -370385954 -593137763 34976160
#> [235] -1855543708 359715546 -1877437533 -400624916 -130132943 -804553700
#> [241] 214992716 -496787865 2076052529 1801590984 56616934 -198268753
#> [247] -1295823838 885426465 1431886747 1172275449 1179133080 -977061888
#> [253] -1375723534 703402572 657332309 1932835570 488176513 -2147417689
#> [259] -1846006037 -2145727122 202707210 1010344288 -1274256035 -1455479521
#> [265] 1517840316 724497611 548140896 1586966709 1389370807 1110764688
#> [271] 1825590361 -325521152 830854855 -247306719 447974159 1758181845
#> [277] 781862605 -463448736 -1856307235 150013840 -1641730815 -1219684530
#> [283] -45524658 1261165643 -2090632612 -113116308 -1166172067 -227424371
#> [289] -775884858 52034028 -335264968 1891170092 -1671773788 1005800525
#> [295] 2038152402 -49679491 -73909016 1659641694 -1039017489 -1324110373
#> [301] -1137405451 1208285491 -1987175210 1132214464 -1616056579 -1260167483
#> [307] 197890853 -379236255 2128932138 1943291790 -1012215385 956976438
#> [313] 423323459 1164828839 -1661329671 442167391 -924043647 -366989920
#> [319] -2087972283 -717684498 -1889887148 2132772444 1775488189 925166903
#> [325] 1515853528 1306111093 -1210066887 -1960919141 -2011726363 -678332169
#> [331] 822983282 1370519223 -449700154 -1244253837 -1465596967 930500539
#> [337] -538251357 -137290631 1748531381 -407234565 -1170331387 -468988247
#> [343] 1112535149 1156930584 1554833237 671345245 -671783941 782781453
#> [349] 1629999294 -192088874 -821295738 1306783183 731366023 37284692
#> [355] -917146737 1417465534 -457233396 -760516983 -833139961 -424409602
#> [361] -189599091 1782473958 -1094934343 -645457673 1658680757 782417785
#> [367] -843859167 1871674492 787030932 588118030 1847058258 976617422
#> [373] 1055729964 -2121284760 525119088 -123392013 1574394891 1465718521
#> [379] 708034196 888043027 -1004369722 -1995620620 -382986248 -1866590647
#> [385] 489777912 -179194855 111180588 853024812 -949411377 1712292435
#> [391] -1164299401 1934981370 -587120964 -101269099 -1558711649 1272102544
#> [397] 1373085629 -1491340748 -1058286714 1004965011 1803699703 -120109907
#> [403] 1700501754 997087614 373118519 944260293 435885709 1869454979
#> [409] 1474228880 -675967066 -222490009 1586966951 -1373456689 -1202994539
#> [415] 102281282 -1298200548 -639644730 382698455 -1519155846 53066814
#> [421] 799748216 545678021 -1577398572 -22812404 1948236300 1233473991
#> [427] -1609465502 1545042871 -1315440489 -1274688831 -1019429996 1948992190
#> [433] -525055343 -1631700982 1392235949 1807374445 -1472351230 149413867
#> [439] 714284644 472616161 -38740404 230731154 -1382583771 -763411897
#> [445] 2119313727 -1288952609 1973679678 -1438857006 2090877841 -1183779200
#> [451] -2144450684 455899464 -591960454 2014957850 -410311745 1900646793
#> [457] -62160535 -1237807710 -1238886087 -459218485 -1067067939 -958854018
#> [463] 1575225480 -340222927 849651756 -457733206 1351403138 1050378917
#> [469] 653872778 -1879056168 1206692640 -1276359531 -1085848700 331377371
#> [475] -1107949307 -179785566 -2001746945 980601415 1067044604 1138852705
#> [481] -1362794043 437088302 133361965 809727532 -795254204 1351382358
#> [487] -921414341 1801219331 447524099 -656509192 -587288460 -1088332395
#> [493] -240232610 -462110887 -1293565675 -199992123 -1236558335 -1486399165
#> [499] -919001464 -723284201 2044943029 -317842167 263411648 1899028349
#> [505] -496531686 -1747754370 2079203359 -505621845 -932811310 551048977
#> [511] 2009790346 -806045618 -2060345548 1497968742 -148926247 1876446239
#> [517] 601472918 -617160542 -1359929395 975628857 -1934138594 464683073
#> [523] -1773639378 -883665188 1607497320 1763719061 725722867 -460100024
#> [529] 747484102 1950354420 -1480595184 -1982165643 1958487686 -142224659
#> [535] 232066090 1769462072 1668143309 -1212445038 -807941881 1565221713
#> [541] 1161246251 -1953940992 -1222377135 -1734955657 -96207541 2073365097
#> [547] -635364405 2019966373 1687421265 -308586587 -1201272080 1874941203
#> [553] 1811504242 -1440348337 17432341 1345303503 1916285885 -957965006
#> [559] 1899162655 5862499 1748958802 643768920 1108617932 1474255177
#> [565] 1463450272 -914041373 -744472243 1329698627 -1440082429 -1376215762
#> [571] -198328963 -110376314 1606137079 1466467373 473935416 2055443993
#> [577] -576290315 -2100201472 389318557 1308482249 1405621179 -2123464341
#> [583] -117638453 -1782445239 -2005167471 -2088214647 -75134765 922993703
#> [589] 1300850766 -982880376 -1220799905 -1543928658 239485458 -176806351
#> [595] -1641247758 383917456 -136882348 -872621276 1920958623 1172923851
#> [601] -742855378 -1002970476 -975366350 395782522 -1553905963 -1493659956
#> [607] 216616978 -1435959669 -324712409 194142151 886084881 866391507
#> [613] -1076469782 -1024825757 834987996 -1901850218 25907938 -1146876260
#> [619] -1794425807 -1954896476 1391700570 -752475172 -2095217809 763556277
#> [625] 1399687635 837917333