Create a design matrix containing a linear trend, a treatment effect, and a trend-by-treatment interaction for a single-case design with m cases and n measurement occasions.

design_matrix(m, n, treat_times = n/2 + 1, center = 0)

Arguments

m

number of cases

n

number of time points

treat_times

(Optional) vector of length m listing treatment introduction times for each case.

center

centering point for time trend.

Value

A design matrix

Examples

design_matrix(3, 16, c(5,9,13))
#>    id constant treatment trend interaction
#> 1   1        1         0     1           0
#> 2   1        1         0     2           0
#> 3   1        1         0     3           0
#> 4   1        1         0     4           0
#> 5   1        1         1     5           1
#> 6   1        1         1     6           2
#> 7   1        1         1     7           3
#> 8   1        1         1     8           4
#> 9   1        1         1     9           5
#> 10  1        1         1    10           6
#> 11  1        1         1    11           7
#> 12  1        1         1    12           8
#> 13  1        1         1    13           9
#> 14  1        1         1    14          10
#> 15  1        1         1    15          11
#> 16  1        1         1    16          12
#> 17  2        1         0     1           0
#> 18  2        1         0     2           0
#> 19  2        1         0     3           0
#> 20  2        1         0     4           0
#> 21  2        1         0     5           0
#> 22  2        1         0     6           0
#> 23  2        1         0     7           0
#> 24  2        1         0     8           0
#> 25  2        1         1     9           1
#> 26  2        1         1    10           2
#> 27  2        1         1    11           3
#> 28  2        1         1    12           4
#> 29  2        1         1    13           5
#> 30  2        1         1    14           6
#> 31  2        1         1    15           7
#> 32  2        1         1    16           8
#> 33  3        1         0     1           0
#> 34  3        1         0     2           0
#> 35  3        1         0     3           0
#> 36  3        1         0     4           0
#> 37  3        1         0     5           0
#> 38  3        1         0     6           0
#> 39  3        1         0     7           0
#> 40  3        1         0     8           0
#> 41  3        1         0     9           0
#> 42  3        1         0    10           0
#> 43  3        1         0    11           0
#> 44  3        1         0    12           0
#> 45  3        1         1    13           1
#> 46  3        1         1    14           2
#> 47  3        1         1    15           3
#> 48  3        1         1    16           4