Design Matrix with interactions
design_matrix.Rd
A design matrix with desired order of interactions.
Examples
set.seed(2021)
df <- data.frame(matrix(rnorm(40), ncol = 4))
design_matrix(df)
#> (Intercept) X1 X2 X3 X4 X1:X2
#> 1 1 -0.12245998 -1.0822049 -0.94244327 -1.96382511 0.13252679
#> 2 1 0.55245663 -0.2728252 -0.18568501 -1.44794439 -0.15072408
#> 3 1 0.34864950 0.1819954 -1.10112464 1.01944342 0.06345261
#> 4 1 0.35963224 1.5085418 1.20811525 -1.42141708 0.54252027
#> 5 1 0.89805369 1.6044701 -1.62493854 -0.60453212 1.44090030
#> 6 1 -1.92256952 -1.8414756 0.10537833 -1.58347390 3.54036489
#> 7 1 0.26174436 1.6233102 -1.45544335 -1.28593235 0.42489230
#> 8 1 0.91556637 0.1313890 -0.35401614 -1.45468488 0.12029537
#> 9 1 0.01377194 1.4811225 -0.09370004 -0.08707112 0.02039793
#> 10 1 1.72996316 1.5133183 1.10066863 0.50473644 2.61798489
#> X1:X3 X1:X4 X2:X3 X2:X4 X3:X4
#> 1 0.115411589 0.240489993 1.01991669 2.1252611 1.850793765
#> 2 -0.102582915 -0.799926473 0.05065955 0.3950357 0.268861568
#> 3 -0.383906557 0.355428441 -0.20039962 0.1855340 -1.122534268
#> 4 0.434477200 -0.511187414 1.82249234 -2.1442671 -1.717235654
#> 5 -1.459282053 -0.542902298 -2.60716532 -0.9699537 0.982327538
#> 6 -0.202597173 3.044338656 -0.19405163 2.9159286 -0.166863841
#> 7 -0.380954094 -0.336585545 -2.36263604 -2.0874671 1.871601683
#> 8 -0.324125269 -1.331860559 -0.04651383 -0.1911296 0.514981922
#> 9 -0.001290431 -0.001199138 -0.13878124 -0.1289630 0.008158567
#> 10 1.904116181 0.873175454 1.66566196 0.7638269 0.555547568
#> attr(,"assign")
#> [1] 0 1 2 3 4 5 6 7 8 9 10