The problem is when you set the year trend to be 1:n
, and also include dummy variable for each year, it happens to produce a non-full-column-rank covariates matrix:
Say if there are only 3 categories: r1, r2, r3, the model is y ~ trend + c2 + c3
and the covariates matrix you will have is :
> mat
int trend c2 c3
[1,] 1 1 0 0
[2,] 1 1 0 0
[3,] 1 2 1 0
[4,] 1 2 1 0
[5,] 1 3 0 1
[6,] 1 3 0 1
and you can find the column rank of covariates matrix mat
is only 3 instead of the number of coefficients you need to estimate (4), i.e. t(mat)%*%mat
is singular. That might cause the error.