Skip to contents

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 calling lm 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.

Value

A matrix of simulated values for the response (or an array, for nsim greater than 1)

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.

See also

Author

David Warton <david.warton@unsw.edu.au>

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.200978    2.825801   1.39654723  0.24972630
#> 2       4.318562    3.329894   0.55164717 -0.21515575
#> 3       5.254231    3.342421   1.92664855  0.13956214
#> 4       5.151684    3.796836   1.93569845  0.27291349
#> 5       5.684409    3.652141   1.65650601 -0.01001265
#> 6       4.395321    3.733580   1.12744259  0.47708597
#> 7       5.292739    3.799997   1.60536750  0.20466059
#> 8       4.871967    2.899367   1.38114076  0.13185737
#> 9       4.069070    3.312135   0.64972774  0.28445416
#> 10      5.120769    3.265031   2.12782054  0.40315003
#> 11      5.330841    3.580128   1.49985877  0.12988763
#> 12      5.177083    3.348545   1.45113047  0.06459168
#> 13      4.534609    3.092727   1.11303165  0.18218810
#> 14      5.102923    2.959697   1.02322860  0.02505378
#> 15      4.718782    2.919131   1.39063341  0.27385550
#> 16      5.381146    3.450103   1.39278148  0.32428560
#> 17      5.479397    3.750609   1.46704446  0.09967066
#> 18      5.372375    3.370330   1.42191789  0.12612435
#> 19      5.511614    3.438025   1.61361386  0.32239343
#> 20      4.116455    3.506816   1.35512711  0.21195580
#> 21      5.481359    3.149424   1.63130883  0.15972582
#> 22      5.189062    3.634384   1.16130518  0.28275605
#> 23      5.337538    3.156004   1.32658709  0.26517995
#> 24      5.187569    3.908086   1.65475241  0.38743281
#> 25      5.468330    3.580206   1.51620296  0.08262696
#> 26      5.657252    3.832517   2.14679065  0.28630975
#> 27      5.454075    3.607925   1.53473719  0.15563142
#> 28      4.691469    3.187503   1.29080489  0.08845448
#> 29      5.757686    3.481600   2.15656965  0.45261661
#> 30      3.748291    2.732238   0.03106476 -0.00192140
#> 31      4.524957    2.947170   1.72126368  0.11654952
#> 32      4.993370    3.446627   1.60979786  0.49172608
#> 33      5.589128    4.374694   1.92220404  0.52627870
#> 34      4.805306    3.141613   1.37619382  0.19821375
#> 35      4.369410    3.059210   0.78113190 -0.11233389
#> 36      5.420600    3.840031   1.49620323  0.27249807
#> 37      5.057003    3.399689   1.94689036  0.32590815
#> 38      6.070911    3.560182   2.49515102  0.35188214
#> 39      4.099611    2.903688   0.92726848 -0.02125550
#> 40      4.155101    2.916433   0.92337749  0.21030629
#> 41      4.776597    3.610434   1.33003909  0.52290947
#> 42      6.269068    3.657671   1.70859781  0.18616687
#> 43      5.075855    3.603221   1.00825932  0.16871696
#> 44      4.175744    3.087367   1.05323519  0.00448581
#> 45      5.331882    3.698521   1.93788203  0.54763104
#> 46      5.234957    3.551521   1.89731820  0.24308328
#> 47      4.784011    3.497571   1.09922231  0.41383138
#> 48      4.644260    3.131348   1.11997240  0.10067307
#> 49      5.208339    3.776496   1.51508267  0.19229795
#> 50      5.058882    3.895116   1.23385397  0.17812715
#> 51      5.888575    2.741548   4.51030271  1.46710507
#> 52      5.157908    2.915565   3.62074831  1.32600173
#> 53      5.510412    2.832324   3.89756530  1.28695552
#> 54      6.889023    3.244702   4.48671180  1.29458596
#> 55      6.223730    3.216808   4.09585254  1.32071499
#> 56      4.945582    2.648886   4.35506344  1.38315941
#> 57      5.862038    2.825527   4.25906634  1.40888464
#> 58      5.836171    2.616747   4.48362509  1.00668985
#> 59      6.005799    2.862617   4.12858800  1.19343146
#> 60      6.008198    2.625672   4.41345098  1.49755684
#> 61      6.397126    2.913171   3.97496167  1.19158122
#> 62      6.458854    3.330773   4.45104757  1.40526369
#> 63      5.638839    2.377427   4.68614951  1.29898775
#> 64      6.461039    2.836803   4.31707407  1.37683395
#> 65      5.570467    2.661451   3.71641382  1.20921125
#> 66      5.903847    2.458873   4.17330718  1.10593412
#> 67      6.133798    3.223465   4.30762761  1.50840333
#> 68      6.693772    2.775698   5.19786378  1.56301913
#> 69      5.678777    2.290029   3.84846467  0.94094348
#> 70      5.981038    3.350287   3.76508183  1.35099290
#> 71      5.127382    2.579653   4.06910868  1.38872350
#> 72      5.829341    2.900984   4.41336330  1.60208906
#> 73      6.550752    3.308670   4.88071681  1.40360426
#> 74      6.306020    2.937496   4.63926974  1.42896111
#> 75      5.428768    2.960488   4.19512013  1.42947991
#> 76      5.583977    2.308025   3.63783498  1.29339551
#> 77      5.769178    2.542574   4.15342206  1.29378662
#> 78      5.436676    2.879526   3.93128351  1.10809954
#> 79      5.517751    2.002300   3.67113774  0.99858724
#> 80      5.846115    1.870301   4.50527638  1.15240025
#> 81      6.160182    3.062861   4.59945323  1.45666668
#> 82      6.188599    2.816063   4.32571447  1.01942451
#> 83      6.927651    2.751601   4.83776050  1.26474315
#> 84      6.578900    3.356976   4.48122020  1.45530214
#> 85      5.901538    2.664915   3.85721813  1.12767880
#> 86      6.343354    3.486992   4.13931872  1.22566719
#> 87      5.158934    2.304629   4.06493495  1.48948267
#> 88      6.155114    2.947692   4.60166119  1.37079810
#> 89      5.877358    2.549802   4.12612682  1.30902947
#> 90      6.208156    2.914024   4.46405046  1.61043407
#> 91      5.731889    3.089871   4.05771509  1.41757849
#> 92      5.785944    2.470860   4.10826241  1.34356767
#> 93      6.277305    2.239251   4.48031399  0.97822668
#> 94      5.329332    2.695397   4.21400072  1.45954137
#> 95      5.490871    2.408655   4.08282241  1.16138024
#> 96      6.130336    3.186481   4.20612236  1.47632227
#> 97      6.570670    2.581203   4.33043202  1.23917103
#> 98      6.493433    2.853993   4.90840254  1.35498107
#> 99      5.499063    2.432872   4.08103066  1.45904832
#> 100     5.737791    2.523484   4.43517421  1.05846908
#> 101     6.170510    2.438281   5.72318985  1.96181642
#> 102     7.559341    3.261659   6.25307976  2.22593852
#> 103     5.602563    2.519204   4.79105087  1.99283041
#> 104     6.793641    2.868664   5.71492483  1.94889950
#> 105     6.817845    3.167786   5.80026353  2.01929626
#> 106     6.148711    3.111413   5.36894328  2.25657762
#> 107     7.000574    2.831003   6.28392291  2.09265570
#> 108     5.737640    2.927709   5.29954310  2.16004725
#> 109     5.905507    2.642863   4.76948601  1.65699227
#> 110     6.719933    3.325212   5.67722284  2.04188529
#> 111     6.381337    2.943559   6.31726367  2.00935825
#> 112     6.670436    3.311127   5.56800204  2.14794538
#> 113     6.393279    2.722976   5.80626699  1.93592546
#> 114     7.224158    2.909177   5.51818041  1.84001682
#> 115     7.006358    3.380429   5.40786608  1.67411915
#> 116     5.724481    3.063453   5.35179271  2.05456893
#> 117     6.464930    2.543877   5.28019591  1.66596215
#> 118     6.585043    3.053046   5.36951422  1.67827731
#> 119     6.617169    2.696539   5.46787534  2.17210765
#> 120     7.577495    3.452656   6.22914597  2.33136393
#> 121     5.736586    2.535274   5.61763134  2.12691785
#> 122     6.842067    3.286865   5.81180600  2.08340625
#> 123     6.624108    3.246115   5.22852724  1.77047034
#> 124     5.251712    2.542523   4.55011959  1.67185744
#> 125     6.045971    2.821633   5.38661058  2.05200170
#> 126     6.760700    2.564690   5.72696913  1.93560420
#> 127     6.774125    3.007770   5.64261835  2.03382768
#> 128     6.947480    3.456937   5.40871058  1.88968597
#> 129     6.086330    2.632093   4.87746580  1.58873888
#> 130     6.122349    2.785627   5.13676877  1.81664256
#> 131     6.309947    2.673486   5.45723879  1.83560642
#> 132     6.762739    2.770839   5.58241429  1.74705510
#> 133     6.652610    2.647762   6.11001382  2.13361299
#> 134     5.948742    2.516633   5.33277058  2.16418115
#> 135     6.233129    2.686854   5.71388528  2.25352258
#> 136     6.774710    3.413097   5.77703327  2.24487898
#> 137     7.689391    3.395205   6.39795822  2.50450067
#> 138     6.629541    2.990771   5.48793394  2.07009894
#> 139     6.580580    2.670852   5.86346312  2.07942445
#> 140     6.281282    2.415028   5.23390393  1.76034377
#> 141     6.906161    2.966723   6.28265271  2.26270725
#> 142     6.575812    2.748573   5.58388747  2.11177876
#> 143     6.164891    2.854123   5.28275524  1.98669015
#> 144     7.814234    3.757725   5.89751371  2.18528802
#> 145     6.770769    2.967283   5.65783213  2.21855981
#> 146     6.826235    2.783189   5.72632797  1.81549031
#> 147     6.054140    2.563505   5.48236955  2.07980576
#> 148     6.407925    2.848938   5.28950155  1.91076111
#> 149     6.077798    2.436157   5.28193894  2.12977076
#> 150     7.126842    2.669864   6.14942295  1.86534143
#> attr(,"seed")
#>   [1]       10403          30 -1468252688  1857059959 -1958502717 -1241505050
#>   [7] -1748131059  1298074777  -522308475 -1128108087  1670336994  -398414487
#>  [13]   944470253  2039619258   893154523  -245923846  -653589308 -1284500889
#>  [19] -1554204129  1540985095   322801081 -2057992450  -754108434  -695468052
#>  [25]    34315742   -89962947 -1344233196   135222390   583505768   499964670
#>  [31]  1304086270  -150129211  1107333043 -1686926405  -419149541   426711857
#>  [37] -1023055620  -349850212 -2127089142  2041885984 -1115571200  -909717822
#>  [43]   869673997   969619254 -1809339400   669915365  1504627545  1002577835
#>  [49] -1733870903   547219677 -1219200944 -1683528752   634133668 -1666269438
#>  [55] -2070172959  -434315218  -447416448 -1929319557   773614468  1155891062
#>  [61]   476991732 -1871181774 -1505412191 -1400669513  1762478946  -977750151
#>  [67] -2065522220 -1201125852 -1464432409   654512469   863597464  1512905636
#>  [73]  1135580520  -128129795  1056068711 -1631531899 -1255009338   647685601
#>  [79]    46763593  -591257232    -5217954  -779159538   313910819 -1075551494
#>  [85]  -449884798  -309951676  -760672105  1528941304   265135426  1732998611
#>  [91]  -409465844 -1855056783  1785930446  2138218078   217142379 -1288241167
#>  [97] -1801726798  -390722272   724264071  -654578753 -2126228877   775198367
#> [103]  1025451618 -1679103725   482548295   476442969  -682884406  -894007572
#> [109]  2090659354  2134232689  -399271830  -910721800   169514656  1577073725
#> [115]  -588690595 -1560241421   489030233  1446902965  2043857341  1606701229
#> [121]  -226326892  2092456103  -202343160   333802569  -806902847    18977304
#> [127]  1534124209  1525478765   215315583 -1905028537   298408997   965627869
#> [133]  1183370752 -1656853887  1062437432  1301521616  1373664256   173393582
#> [139]  1894560111  1110920976 -1372403286  -144068993 -1888025008  1821999710
#> [145] -1337082094   162021649 -1213028596 -1414717415  -825266544  1156129295
#> [151]  1689599401   459384318   802620753  -225350419   572325267   312003573
#> [157]  -433781420  -448344015 -1443996650   450223902  2140766335  1126158026
#> [163]  1663441128 -2061072907 -1971793845 -1622670158   249017058    12685665
#> [169]   250378141  1234659719 -1215944518   180382662   168158964    53467640
#> [175]   176420157   459000044 -1382253533   848047273  1448651746   811016567
#> [181]    21214108  -799605568   461184215  1021280383   951803259 -1960286733
#> [187]  1350792426   439801758 -1235984320   554426045   277386530 -1670552933
#> [193]   854965626   137721739  -678531143  1496351243  -503823232  -966869089
#> [199]  1643724826   352630622 -1632950609   -88000184   154354495  1188172599
#> [205]   732960122 -1814007950  -275117108 -1326591946   546674086  1725969605
#> [211]  1266347109  -510020000 -1620994198  -768582738   -86407759 -1752107607
#> [217]   324901629 -2045959323  1761686028 -1654123180  1512090156  -310610381
#> [223]  -715562866 -1188496765  -150236858   177154943  1403815865 -1327000545
#> [229]  2024217491   635588853 -1033918029  2068705410  -533019402 -2145543279
#> [235] -1874811030 -1604760764   381242244   666094464  1966339432  -907039334
#> [241] -1549026974      -57048   705570169  1670133020 -1944563867 -1192620921
#> [247]  1174097474  -252700033  -734157346 -1823059394 -1589586568  -333412077
#> [253] -1794214168  1172319011  -172325135   206768049   189914062   550960722
#> [259] -1741239737  1781184838  1903433368 -1673420322 -2000879536  -713062451
#> [265]  2054398692  -569480048  -212285237   676876797  2071526397   -51598963
#> [271]   895409137   317840701  -113006094 -1393388563  1980236091  -326104809
#> [277]  1140069307 -1929642044 -2137681475   225888433  -659787528 -1189335260
#> [283]  -478511751  2064156481 -1101162599 -2114406862 -1736728851 -1101734365
#> [289]  -667427864   952140852  1486651119 -1415930367  -140675447  1333179448
#> [295] -1226641607  1819353301  1975378996  -965921382 -1241134129   -43283729
#> [301]  -392027820   624978752 -2066435379  -859609154  -866336642   382239781
#> [307]   677365699 -2038408346  1418079110 -1318257394   551951458 -1989985512
#> [313]  1491866775  1395781575  -319956264  1834625187   348796238  -871557990
#> [319]   655194596  -693103950 -1986789639  1843262890 -1797162627   345186838
#> [325] -1996651483  -586971209  -368721027 -1433759398  1136154534  1390839228
#> [331]   394339830   651596370  1311146953  1776491658   954315023  -749845938
#> [337]  -931485652   558289287  1188565774   837545477 -1988787000  -751723977
#> [343]   673522616  1938881874  -480183930  1468488952    79202616   481038015
#> [349]  -595169325  -293001965  1194349556 -1421667856   313704099   315342300
#> [355]  -827110496 -1626162362  1333561189 -1415970660   877215498  1408412431
#> [361]  1092899791  -262843277  -357803824 -2113573336 -1776958402  -678868439
#> [367]    17544013 -1414947037 -1124245538 -1053937393   886419697 -1385486802
#> [373]   472897801 -1297037737  1998977212 -1876805825   -37784667 -1023744346
#> [379]  1904944874  1571585845 -1168601362   599833402  2038868951   372999419
#> [385]  -172945948   395995041 -1254519736  1399596844   174648881 -1433696948
#> [391]  1944069311 -1522314512 -1065919756   899005832   260023115  -546652385
#> [397]  1550892266   647946156   147556696  1237044241 -1301550477   654009853
#> [403] -1748902826  -850363058  -193394884 -1004677390  1001914355  1765916711
#> [409] -1036837385 -2090027385  1560950754  1580086644 -1216728711   373508474
#> [415]  1798316602  2054819250 -1049763554  -456586389 -1772613483  1259377175
#> [421] -1139925545   559675645   630283524 -2085603755  1678720300 -1165794384
#> [427] -1311534297  2026290614 -1351498634 -1814040972 -1805289120 -1923180184
#> [433]   187084078 -1150111522 -1699163710   867332072    13086645  1363385666
#> [439]   415772348  1221983085  -149280741 -1797045976   -83616369   169324616
#> [445] -1031032488   918814459   625524287  -693550959  -779947230  -460292246
#> [451]  -104538789 -1770031701  1762818166 -1344570345  1585708005 -2070001950
#> [457]  1602474991  1191516870  1325325724  1886693149  1270752358  2041361644
#> [463]  -561487394   166281667  1330357896  1919459548  1995289182  1891806110
#> [469] -1961941306  -574706773 -1424490846  -883213102  1649981723   913252804
#> [475]   332271450   631530059  1642201445   552464073     3487912  1931590989
#> [481]   821355293   992022568   120650764  1939018662 -1388120216  -779212692
#> [487]   904851286  -631361828 -1350494972   -62282283  1049579713   215308288
#> [493]  2040995736 -1394496792  1927716242 -1613077540  1776793899 -1565489921
#> [499]  1314523911 -1568620229  -691961623  1107767402 -1015765595  -372076736
#> [505]  1000947905   265733373  1380121045  -738596860 -1950742036   816987224
#> [511]   716498000   699295552 -2030668781   921633643 -1581955396  -974757188
#> [517] -1282929069  1936875566 -1612370921  2138496160   883896403 -1851193139
#> [523]   -27409771  1895585703  1006992140  -326154186   515966776  2133369170
#> [529] -1488935758 -2040630930   692086962  -776300506  -610529059 -1081350387
#> [535]  2142032816  1327289627  1199752580  1226428466  1517100486  1547364926
#> [541]  2071867131  -376454572  -348617133  -211357651  1424404545   788101647
#> [547]   212419341   324351010 -1173746076 -2033538116  -120968066  1341175245
#> [553]  -516698549 -1438312160  -718511204  -620049088  -386137216  1827909352
#> [559]  -318671427   346438949  -357591836  1892281209    72841714    50765530
#> [565] -1425294091   677563172  1914280582  1451399635  -450496539 -1124162123
#> [571]  2098734964  -735098453   715305932   517306416   -96342192   311769076
#> [577]   584015109   614623819   513670558 -2127736893  2118330253  2130451102
#> [583]  -998801589 -1535998872   146825565 -1601165398  1290979351 -1981195231
#> [589]  -993563899   717784789 -1575862468  1856866498  1825385021  -110349599
#> [595]  1595467916 -2125558290    22707222 -1005242373   290470055  -893524482
#> [601]  -803125308 -1255965703  -197109890 -1095764475   621343362  1298850276
#> [607]   -17062252   756947593  -711119586    14486898  1428866940 -1804327601
#> [613]  -513989650  -232105102  2092280956 -1443112203 -1649618438  -321473689
#> [619]  -761343003  1872349909  1973733616 -1458548324  1443569093  1511953803
#> [625]  1431375706  1559599008