Constructing the matrices to estimate the S weights becomes problematic when the user uses factor(d) instead of d when declaring IV-like specifications.
The issue arises when fixing d to either 0 or 1:
A contrasts error will arise, since factor(d) does not make sense when d is a constant.'
You already had code that takes the formula, and converts all factor(d) expressions into booleans.
However, you did not have code to account for the fact that some columns generated prior to fixing d (e.g. factor(d)1:x)) will not be generated once fixing d (e.g. if d is fixed at 0, then factor(d)1:x will not be generated).
Constructing the matrices to estimate the S weights becomes problematic when the user uses
factor(d)
instead ofd
when declaring IV-like specifications.The issue arises when fixing
d
to either0
or1
: Acontrasts
error will arise, sincefactor(d)
does not make sense whend
is a constant.'You already had code that takes the formula, and converts all
factor(d)
expressions into booleans. However, you did not have code to account for the fact that some columns generated prior to fixingd
(e.g.factor(d)1:x)
) will not be generated once fixingd
(e.g. ifd
is fixed at0
, thenfactor(d)1:x
will not be generated).But you know beforehand which columns should exist after fixing
d
. So the solution is simply to generate any missing columns (with values 0) once you fixd
. Here is the code: https://github.com/jkcshea/ivmte/blob/5fab27f8f6ca35d983d66726c66f99ad9d17ef12/R/design.R#L86-L92