I'd coded the levels of categorical variables wrong.
They were numbered 1,...,n rather than 0,...,n as the documentation specifies.