Skip to contents

Residuals from full conditionals of a Multivariate Linear Model (mlm) object. The full conditional for each response is a linear model with all other responses used as predictors in addition to the regressors specified in the formula of the mlm object. This is used to diagnose the multivariate normality assumption in plotenvelope.

Usage

cresiduals(object, standardize = TRUE, ...)

Arguments

object

a mlm object, typically the result of calling lm with a matrix response.

standardize

logical defaults to TRUE, to return studentized residuals using rstandard so they are comparable across responses.

...

further arguments passed to residuals.lm or rstandard.

Value

A matrix of residuals

Details

A residuals function for mlm objects, which returns residuals from a full conditional model, that is, a linear model of each response against all responses as well as predictors, which can be used to diagnose the multivariate normality assumption. These can be standardized (standardize=TRUE) to facilitate overlay plots of multiple responses, as in plotenvelope.

References

Warton DI (2022) Eco-Stats - Data Analysis in Ecology, from t-tests to multivariate abundances. Springer, ISBN 978-3-030-88442-0

Author

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

Examples

data(iris)
# fit a mlm:
iris.mlm=lm(cbind(Sepal.Length,Sepal.Width,Petal.Length,Petal.Width)~Species,data=iris)
# construct full conditional residuals:
cresiduals(iris.mlm)
#>     Sepal.Length  Sepal.Width Petal.Length  Petal.Width
#> 1     0.31367294  0.202516501 -0.301850145 -0.240802233
#> 2     0.47429637 -1.399025921 -0.182414309  0.383425946
#> 3    -0.24106926 -0.430574978  0.040805359  0.121609318
#> 4    -0.95656076 -0.526551269  0.977931661 -0.082401947
#> 5    -0.17937436  0.722221842  0.001542216 -0.444406291
#> 6     0.03684044  1.027064635 -0.035185225  0.113854365
#> 7    -1.06638351  0.302912457  0.568257718  0.231824439
#> 8    -0.12555699  0.038402502  0.247256532 -0.296982266
#> 9    -1.02163525 -1.073564006  0.928033767  0.249331951
#> 10   -0.06906266 -0.717018438  0.506389609 -0.521175728
#> 11    0.70432417  0.602598703 -0.481941948 -0.514492009
#> 12   -1.05806421  0.395862394  1.100021030 -0.558626361
#> 13    0.03856698 -1.022861007  0.285886695 -0.283412794
#> 14   -0.79359598 -0.523744394  0.301957654 -0.123918794
#> 15    2.39074532  0.983205596 -2.402668062 -0.297851087
#> 16    0.77993035  2.378404054 -1.194609506 -0.164180908
#> 17    1.14114905  0.751020347 -1.583614700  0.710204145
#> 18    0.41749985 -0.033719952 -0.533339756  0.365965061
#> 19    1.08891546  0.458914685 -0.578561536 -0.178876645
#> 20   -0.34719866  1.169090759  0.059832579 -0.222795197
#> 21    0.64680923 -0.391324618  0.081397497 -0.366435755
#> 22   -0.07882492  0.556805328 -0.242226956  0.532763437
#> 23   -0.40690250  1.013489593 -0.605385681 -0.082452599
#> 24    0.13350884 -1.053990605  0.018542848  1.434963264
#> 25   -1.88757612  0.616994229  2.254306053 -1.012183196
#> 26    0.25660863 -1.401820927  0.356892429  0.144769653
#> 27   -0.19154825 -0.363806017  0.169085164  0.769448604
#> 28    0.36994408  0.130742220 -0.151091206 -0.331372964
#> 29    0.80609842 -0.318020557 -0.605529117 -0.037514982
#> 30   -1.06283978 -0.219248419  1.196481823 -0.321242591
#> 31   -0.57013365 -0.740713087  0.894145300 -0.116686827
#> 32    1.40310765 -1.010001464 -1.156980074  1.147027061
#> 33   -0.73266508  2.638772263  0.510822238 -1.848088488
#> 34    0.50102878  2.294492202 -0.770695777 -1.068625741
#> 35    0.03518436 -0.951627009  0.273804363  0.087582529
#> 36    1.02240977 -0.931005292 -1.047316979  0.439576676
#> 37    1.90554110 -0.444227300 -1.628699251  0.133442915
#> 38   -0.61504939  1.102790030  0.469434698 -1.108612687
#> 39   -0.90738785 -0.762257934  0.607909875  0.248210421
#> 40    0.20378563 -0.104156763  0.013444430 -0.240679959
#> 41    0.36156611  0.038145328 -0.684167003  0.456755021
#> 42    0.71303380 -3.796152408 -0.368595372  2.022975618
#> 43   -1.23045090 -0.002554199  0.745811697 -0.047983180
#> 44   -0.14866091 -0.463378746 -0.227985891  1.836582177
#> 45   -1.34143584  1.223866798  1.373284194 -0.205195356
#> 46    0.24802768 -1.494071645 -0.180531025  0.936460217
#> 47   -0.72728884  1.476979480  0.680351481 -0.980021291
#> 48   -0.84426391 -0.217635235  0.660695161 -0.082138419
#> 49    0.37382592  0.744292344 -0.246893593 -0.570270905
#> 50    0.31091285 -0.409667887 -0.206831036 -0.003272779
#> 51    1.68957653  0.246746532 -0.679363521 -0.233450850
#> 52    0.35298194  0.723153609 -0.267979617  0.334498226
#> 53    1.07730540 -0.087859861  0.033747984  0.175871678
#> 54    0.01486333 -1.277495369 -0.248455591  0.673179257
#> 55    1.06426882 -0.865129455 -0.396144787  0.833865887
#> 56   -1.51087044  0.686187291  1.557510587 -0.692678269
#> 57   -0.58991947  1.153054518  0.580255443  0.446763578
#> 58   -0.53404722  0.174238166 -0.784937722 -0.618516844
#> 59    1.02240519 -0.155022005 -0.095240382 -0.476785166
#> 60   -1.25581297  0.359066972  0.117722184  0.671530577
#> 61   -0.08978165 -1.359776950 -0.524485451 -0.262794937
#> 62   -0.15036502  0.467563296 -0.391402858  0.786988763
#> 63    1.53325798 -1.675388916 -0.805518854 -0.736006984
#> 64   -0.79974572  0.395449033  1.228100512 -0.297626185
#> 65    0.46219241  0.570435769 -1.608443005  0.436784351
#> 66    1.67667024  0.081552694 -1.199771561  0.191440045
#> 67   -1.96206311  1.118912675  1.477945908  0.178343388
#> 68   -0.23741526  0.591640418  0.413217225 -1.716226501
#> 69    1.35685822 -2.774528746 -0.507540895  1.721910043
#> 70    0.08334738 -0.262174134 -0.264023989 -0.636622821
#> 71   -1.83786599  0.962988692  1.394709855  1.463152957
#> 72    1.17579011 -0.244657858 -1.302793177  0.274218337
#> 73    0.07372279 -1.508885653  1.033350712  0.727795819
#> 74   -0.84894626  0.493568978  1.625203955 -1.368949759
#> 75    1.18031586 -0.081628486 -0.783342172 -0.146666616
#> 76    1.50756664 -0.155687033 -1.031685527  0.282062506
#> 77    1.40673285 -0.919897002 -0.095304521  0.099748115
#> 78    0.51552919 -0.589188625  0.358554184  1.287247982
#> 79   -0.47746675  0.158818713  0.461729892  0.548965075
#> 80    1.25514315 -0.074702458 -1.749524151 -0.757249471
#> 81    0.19123586 -0.569569506 -0.485766942 -0.399506237
#> 82    0.36300710 -0.405304588 -0.641911527 -0.863638063
#> 83    0.52008783 -0.027666268 -0.824199807 -0.209868313
#> 84   -1.71772439 -0.419859412  2.419762790  0.583245153
#> 85   -2.62242806  1.419019355  1.959490218  0.064506930
#> 86   -1.20502772  1.820996766  0.586145012  0.427376857
#> 87    0.96078712  0.057195773 -0.270293271  0.357535896
#> 88    1.57201343 -2.136355333 -0.588794575  0.541445620
#> 89   -1.07556713  1.296600140  0.392852482 -0.452787864
#> 90   -0.31278905 -0.521110187 -0.108010667  0.376125701
#> 91   -1.67686811  0.381386630  1.736280416 -0.975366683
#> 92   -0.68898984  0.701729573  0.913641774 -0.297196839
#> 93    0.40963934 -0.334695490 -0.508764716 -0.209594801
#> 94   -0.03222012 -0.355535679 -1.090876188 -0.411674872
#> 95   -0.85522990  0.234250581  0.567293819 -0.156462455
#> 96   -1.12559242  1.462365503  0.778463848 -1.152599249
#> 97   -0.85328349  0.846491387  0.472767886 -0.394590880
#> 98    0.52123569  0.204192096 -0.313412470 -0.258944708
#> 99    0.92234629 -0.191661943 -2.581566313  0.419353141
#> 100  -0.41640415  0.397912240  0.017566294 -0.099833515
#> 101  -2.25424661  0.867643747  1.568447010  1.619394130
#> 102  -1.04844897  0.067494783  0.207494683 -0.143007886
#> 103   0.77182779 -0.561899643 -0.012243150  0.188772645
#> 104  -1.20044706  0.705365838  1.336541211 -1.499470094
#> 105  -0.83137069 -0.011808760  0.777142236  0.605625943
#> 106   0.51806305 -0.796316080  1.538184164 -0.572596556
#> 107  -2.30079610  0.668513530  0.340699854 -0.714347939
#> 108   0.19376148 -0.237768898  1.714678718 -1.987900618
#> 109   0.23466643 -1.251532201  0.897595397 -0.987400660
#> 110  -0.01166894  0.773131454  0.013575063  1.515082345
#> 111   0.55300317  0.725008281 -1.319645615  0.125839197
#> 112   0.38666929 -0.647668680 -0.428948302 -0.097758646
#> 113   0.87500786 -0.416677672 -0.849682791  0.607631007
#> 114  -0.67809909 -0.861638747 -0.319661454  0.858509859
#> 115  -0.71219374 -0.761445014 -0.912288390  2.766822883
#> 116  -0.01584990  0.299357829 -1.017180438  1.600947681
#> 117  -0.42736870  0.723753683  0.550341854 -1.381915644
#> 118  -0.66646844  1.984426717  2.036461904 -1.260233033
#> 119   0.93034168 -2.786261646  1.780196205  0.911085033
#> 120   0.29752378 -1.260306855 -0.069083416 -1.605397308
#> 121   0.54209724 -0.135129758 -0.641938840  1.290299193
#> 122  -1.22769475  0.356808241 -0.261640576  0.505755212
#> 123   0.81586426 -1.416302396  1.808551215 -0.999307925
#> 124   1.05382161 -0.557400516 -1.507438169 -0.174869139
#> 125  -0.49236091  1.000729889  0.363463489 -0.185009157
#> 126   0.19202082  0.845057354  0.987816473 -2.025383158
#> 127   0.83459110 -0.103490428 -1.589526739 -0.232166648
#> 128  -0.10475371  0.873372761 -0.832360831 -0.733036474
#> 129  -0.39013411 -0.530245163  0.332824272  0.528853749
#> 130   0.87923078  0.420105139  0.544183410 -2.659820843
#> 131   1.34934882 -1.146266442  0.387367204 -0.870902652
#> 132   0.65494937  1.962837666  0.860313912 -1.931850346
#> 133  -0.28719298 -0.768645052  0.101042833  1.136413042
#> 134   0.02476654  0.692207317  0.033388636 -2.443261221
#> 135  -1.86032534  0.841725217  2.602557556 -3.628615651
#> 136   2.43145936 -1.780791069 -1.138877601  1.479245005
#> 137  -1.40892868  1.189665443  0.294077000  1.431496706
#> 138  -0.92464944  1.246812696  0.857588193 -1.588341991
#> 139  -0.16206772  0.947945104 -0.986246691 -0.643708808
#> 140   1.31606460 -0.253524423 -1.399570167  0.667042119
#> 141   0.42640785 -0.540950046 -0.867059255  2.076104009
#> 142   2.38637729 -0.970693255 -3.034934886  2.362773567
#> 143  -1.04844897  0.067494783  0.207494683 -0.143007886
#> 144  -0.33893801  0.150908579  0.367158376  0.941244220
#> 145  -0.07740846  0.057299380 -0.575839356  2.249737400
#> 146   1.59784060 -0.978724620 -2.248738202  2.220908730
#> 147   1.21362577 -1.481214991 -1.496748247  0.588360951
#> 148   0.60367745  0.035946981 -1.069763113  0.272590818
#> 149  -1.29168602  1.423671672 -0.016470849  1.057043006
#> 150  -1.31819069  1.302294870  0.417277409 -1.142817297