I know that the support for linear models with multiple LHS is limited. But when it is possible to run a function on an "mlm" object, I would expect the results to be trusty. When using rstudent, strange results are produced. Is this a bug or is there some other explanation?
In the example below fittedA and fittedB are identical, but in the case of rstudent the 2nd column differs.
y <- matrix(rnorm(20), 10, 2)
x <- 1:10
fittedA <- fitted(lm(y ~ x))
fittedB <- cbind(fitted(lm(y[, 1] ~ x)), fitted(lm(y[, 2] ~ x)))
rstudentA <- rstudent(lm(y ~ x))
rstudentB <- cbind(rstudent(lm(y[, 1] ~ x)), rstudent(lm(y[, 2] ~ x)))
Setup
As you've observed, only the result for the first response is correctly returned by
rstandard(fit).Why
rstudentfails on "mlm"The thing is, there is no "mlm" method for
rstudent.When you call
rstudent(fit), the S3 method dispatching mechanism findsrstudent.lminstead, becauseinherits(fit, "lm")isTRUE. Unfortunately,stats:::rstudent.lmis not doing the correct computation for an "mlm" model.lm.influencedoes not give the correctsigmafor "mlm". The underlying C routineC_influenceonly computessigmafor an "lm". If you givelm.influencean "mlm", only the result for the first response variable is returned.Obviously for an "mlm" the
sigmashould be a matrix. Now given this incorrectsigma, "recycling rule" is applied behind the"/"in the following line ofstats:::rstudent.lm, because theres(residuals) on its left is a matrix but the stuff on its right is a vector.Effectively, computational result is only correct for the first response variable; all the rest of response variables would use the wrong
sigma.R core team needs to patch a number of diagnostic functions
Note that almost all functions listed in doc page
?influence.measuresare buggy for "mlm". They should have issued an warning saying that "mlm" methods are not implemented yet.lm.influnceneeds be patched at C-level. As soon as this is done,rstudent.lmwould work correctly on "mlm".Ohter functions can be easily patched at R-level, for example,
stats:::cooks.distance.lmandstats:::rstandard. At the moment (R 3.5.1) they are:and they can be patched (by using
outer) withA quick test: