leeper / cregg

Simple Conjoint Analyses, Tidying, and Visualization
Other
50 stars 7 forks source link

Error in model.frame.default(weights, data = list(OUTCOME = c(1, 1, 1, : object is not a matrix #12

Closed b-w-a closed 5 years ago

b-w-a commented 5 years ago

Cannot get past this error code and not sure what the issue is. Tried lots of things to match some of the formatting of the 'immigration' data set, but cant get anything to work. I stacked 4 data.frames exported from read.qualtrics where I added a group variable based off race/ethnic group.

Happy to send the data directly, but don't to post here.

Put your code here:

## load package
library("cregg")

model <- selected ~ Convenience + Crime + Housing.Cost + Neighborhood.Composition +
  Neighborhood.Quality + School.Quality + Type.of.Place

out <- cj(df, model, id = ~ Response.ID, estimate = "mm", by ~ group)

## session info for your system
sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6
leeper commented 5 years ago

Is this the exact code? Are you just missing an = in by = ~ group?

b-w-a commented 5 years ago

Ok, well that solved that problem! I had that in earlier code and still could not get it to run. Now when I run the code I get Error in fix.by(by.y, y) : 'by' must specify a uniquely valid column

However, that is only when i read the data in from a .csv using read.csv. When I stack the object from read.qualtrics, I don't have the issue. Thanks for your help, I got it working.

GitHubKawata commented 5 years ago

I also have the same error - Has this question been answered elsewhere?

b-w-a commented 5 years ago

Yeah, I think it has to do with structure of the data.frame. I didn't 100% check this, but when the data.frame from cjoint::read.qualtrics was passed to cregg I had no issues. When saved as a .csv and read using readr::read_csv it gives issues since readr::read_csv reads the factors as characters by default. My guess is ensuring those values are factors you should be fine.

leeper commented 5 years ago

If anyone can provide a minimal reproducible example of the problem (even using just a toy dataset), I can investigate more and try to provide a more informative error message.

leeper commented 5 years ago

I think this is resolved by #25. If not, I will re-open.