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
When I have a matrix MMM with long column names and short row names, then I will normally display the transpose t(MMM). It will be much easier to read. I will also set the emacs window holding *R* to very wide (150 or so) and then I can see the whole width of the transposed matrix simultaneously. Rich On Thu, Apr 4, 2013 at 8:30 PM, Ross Boylan <ross@biostat.ucsf.edu> wrote:> 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<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 > > ______________________________**________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/** > posting-guide.html <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
The problem was that my formula had 2 "~" in it. It also had a lot of duplicate terms, but by themselves they don't cause trouble. Ross On 4/4/2013 5:30 PM, Ross Boylan wrote:> 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