Bugzilla – Bug 14992
row names of model.matrix
Last modified: 2012-07-21 06:41:48 UTC
Dear R core,
I just observed that model.matrix is inconsistent in returning row.names.
Here is an example (taken from the help page):
ff <- log(Volume) ~ log(Height) + log(Girth)
utils::str(m <- model.frame(ff, trees))
mat <- model.matrix(ff, m)
Here, the model.matrix derived the rownames from m. This is also true for, e.g.,
model.matrix(~ log(Height), m)
but rownames() are NULL in the cases
model.matrix(~ 1, m)
model.matrix(~ 0, m)
I think that currently it is not specified / documented, which row names the model.matrix should have. I would suggest to always derive the row names from the corresponding model.frame.
platform = x86_64-unknown-linux-gnu
arch = x86_64
os = linux-gnu
system = x86_64, linux-gnu
status = Under development (unstable)
major = 2
minor = 16.0
year = 2012
month = 07
day = 11
svn rev = 59772
language = R
version.string = R Under development (unstable) (2012-07-11 r59772)
nickname = Unsuffered Consequences
Thank you, for the clear report.
Though I don't see how the current behavior can become a problem,
I found it pretty easy to fix, and I do agree that consistency is desirable.
Actually, this change is a problem. It changes the output in several packages, including betareg and gstat.