Error in summary.mlm: formula not subsettable

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Error in summary.mlm: formula not subsettable

Helios de Rosario
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Error in summary.mlm: formula not subsettable

Duncan Murdoch-2
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Error in summary.mlm: formula not subsettable

Duncan Murdoch-2
In reply to this post by Helios de Rosario
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, it was a bug.  A simple workaround is the following:

mod2$call$formula <- formula(mod2)

I'll add that to summary.mlm, but in the meantime, you can just do it
yourself.

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.