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

Duncan Murdoch murdoch.duncan at gmail.com
Wed Oct 26 16:03:05 CEST 2011


On 26/10/2011 9:48 AM, Helios de Rosario wrote:
> 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?

Yes, I'd say it's a bug.  summary.lm handles this situation fine, but 
summary.mlm does not.

I'll take a look...

Duncan Murdoch



More information about the R-help mailing list