[R] Error in summary.mlm: formula not subsettable

Helios de Rosario helios.derosario at ibv.upv.es
Wed Oct 26 15:48:57 CEST 2011


When I fit a multivariate linear model, and the formula is defined
outside the call to lm(), the method summary.mlm() fails.

This works well:
> y <- matrix(rnorm(20),nrow=10)
> x <- matrix(rnorm(10))
> mod1 <- lm(y~x)
> summary(mod1)
...

But this does not:
> f <- y~x
> mod2 <- lm(f)
> summary(mod2)
Error en object$call$formula[[2L]] <- object$terms[[2L]] <-
as.name(ynames[i]) :
  objeto de tipo 'symbol' no es subconjunto

I would say that the problem is in the following difference:
> class(mod1$call$formula)
[1] "call"
> class(mod2$call$formula)
[1] "name"

As far as I understand, summary.mlm() creates a list of .lm objects
from the individual columns of the matrices in the .mlm object, and then
it tries to change the second element of object$call$formula, to present
the name of the corresponding column as the response variable. But if
the formula has been defined outside the call to lm(), that element
cannot be modifed that way.

A bug, perhaps?

> sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Spanish_Spain.1252  LC_CTYPE=Spanish_Spain.1252
[3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base




-- 
Helios de Rosario Martínez
  Researcher



More information about the R-help mailing list