5.1 Factor covariates

If your covariates are factors, like site number or month, and you are estimating a \(a\) value, i.e. level or intercept, for each then you will use a matrix with 0s and 1s. This is identical to how say lm() would translate your model with factors.

Say your covariate is quarters and you have 3 years of data:

covariate <- rep(paste0("q",1:4), 3)

You translate this to a matrix with four rows and 10 columns. Each row is for a different quarter.

vals <- unique(covariate)
TT <- length(covariate)
p <- length(vals)
c <- matrix(0, p, TT)
for(i in 1:p) c[i,] <- covariate == vals[i]
rownames(c) <- vals
c
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
q1    1    0    0    0    1    0    0    0    1     0     0     0
q2    0    1    0    0    0    1    0    0    0     1     0     0
q3    0    0    1    0    0    0    1    0    0     0     1     0
q4    0    0    0    1    0    0    0    1    0     0     0     1