[R] model.frame: object is not a matrix
Ross Boylan
ross at biostat.ucsf.edu
Fri Apr 5 02:30:44 CEST 2013
Over a decade ago there was a problem with model.frame when the variable
names were long:
https://stat.ethz.ch/pipermail/r-help/2002-August/024492.html
I have similar symptoms with R 2.15.3 on Windows 7:
Browse[2]> x <- model.matrix(formula(myform), p$data)
Error in model.frame.default(object, data, xlev = xlev) (from mice.R#601) :
object is not a matrix
My attempt at a work-around did not help:
Browse[2]> x <- model.matrix(formula(myform), as.matrix(p$data))
Error in model.frame.default(object, data, xlev = xlev) (from mice.R#601) :
'data' must be a data.frame, not a matrix or an array
Browse[2]> formula(myform)
~educ_sg + ethnic_sg + hiv + J10 + A5 + mar_stat + orientation +
Born_US ~ educ_sg + ethnic_sg + hiv + J10 + A5 + mar_stat +
orientation + Born_US + (DWPAD_ActAvoid + DWPAD_EducConf +
DWPAD_PasAvoid + DWPAD_Support) * ethnic_sg * racGayDiscStress +
0
Notice there are many three-way interactions, which certainly will
produce long column names.
There was a suggestion in the old thread to set width= in aov, for use
by deparse, but I'm not using aov and there are no obvious hooks to
deparse. The level names are also long and include spaces, inequality
signs, and periods (also "-" if it uses raw numeric values); perhaps
that is the culprit.
Any suggestions for how to diagnose or fix? This is all happening
inside a package that is for general use, and so require recoding of
variable and level names to something brief is not very attractive.
However, changing these within the program might be workable.
Ross Boylan
More information about the R-help
mailing list