Is there any way to work with mlm objects in mtable from the memisc package?
Without using multiple response matrix, what I want is something like:
library(car)
library(memisc)
lm1 = lm(Sepal.Length ~ Petal.Length + Petal.Width + Species, data=iris)
lm2 = lm(Sepal.Width ~ Petal.Length + Petal.Width + Species, data=iris)
mtable(lm1, lm2)
which produces
Calls:
lm1: lm(formula = Sepal.Length ~ Petal.Length + Petal.Width + Species,
data = iris)
lm2: lm(formula = Sepal.Width ~ Petal.Length + Petal.Width + Species,
data = iris)
===============================================
lm1 lm2
-----------------------------------------------
(Intercept) 3.683*** 3.048***
(0.107) (0.094)
Petal.Length 0.906*** 0.155*
(0.074) (0.065)
Petal.Width -0.006 0.623***
(0.156) (0.136)
Species: versicolor/setosa -1.598*** -1.764***
(0.206) (0.180)
Species: virginica/setosa -2.113*** -2.196***
(0.304) (0.265)
-----------------------------------------------
R-squared 0.837 0.551
adj. R-squared 0.832 0.539
sigma 0.339 0.296
F 185.769 44.496
p 0.000 0.000
Log-likelihood -48.116 -27.711
Deviance 16.681 12.708
AIC 108.231 67.423
BIC 126.295 85.486
N 150 150
===============================================
But:
mlmIris = lm(cbind(Sepal.Length, Sepal.Width) ~ Petal.Length + Petal.Width + Species, data=iris)
mtable(mlmIris)
produces
Error in qt(p = alpha/2, df = dendf) :
Non-numeric argument to mathematical function
I'm not going to reproduce the ways I've tried to extract an lm object that I can use in mtable. Suffice it to say, none of them worked.
As suggested in the comments you need to write a
getSummarymethod formlmobjects because there currently isn't any. Thelmmethod that you get by inheritance does not work.I have taken a quick stab at this and provide a
getSummary.mlmbelow along with a suitablesetSummaryTemplate. The coefficients and standard errors are now correctly extracted. What needs more work is the extraction of summary statistics (R-squared, residual sum of squares, F statistic, etc.) which I didn't work on. It should give you a good start though. If you improve the method further, please also consider providing it to Martin Elff (thememiscmaintainer) so that it is directly available inmemisc.After sourcing the functions provided below, this works:
The source code is: