unfold icon indicating copy to clipboard operation
unfold copied to clipboard

uf_designmat surpressing intercept still returns only n-1 predictors

Open behinger opened this issue 6 years ago • 1 comments

When running uf_designmat(...'formula','y~-1+cat(test)'), (with test having n levels the internal matlab function does not return n levels as I expected, but n-1 (identical to the '1+cat(test)' case.

Thanks to Pau Blanco from UPF for reporting this!

behinger avatar May 18 '19 17:05 behinger

Hey! thanks for the file. I replicated the problem but have to think on a general solution.

If you don't surpress the intercept, everything works as intended, as a n-level factor will be represented by n-1 predictors + the intercept. Which what you have.

There is indeed a bug when surpressing the intercept, then the matlab backend also returns n-1 predictors, which, frankly, doesn't make much sense to me :/ I have to read into it, I opened an issue on https://github.com/unfoldtoolbox/unfold/issues/69 and will fix it as soon as I have time.

For now you can "hack" it as follows:

change line 120 of uf_designmat from

'codingschema','string',{'effects','reference'},'reference';

to

'codingschema','string',{'effects','reference','full'},'reference';

and add to your uf_designmat(...,'codingschema','full')

This should prevent matlab from removing the event with -1 and you should get your expected result. But beware, if you run it with full and you include an intercept, your betas will be overcomplete and not unique (you will also see a warning)! You then cannot interpret the results, except by taking so called estimable functions (differences) - ok but that might be too much detail, just be careful ;)

Best, Bene

behinger avatar May 18 '19 18:05 behinger