For this to work g would have to be the index (what you're calling x1) and x1 should be a vector of parameters of length equal to the number of categories in this first factor. Same for the second factor.