Construct Design Matrix for Beta Updates in ALS
cpp_construct_Walpha_design.RdBuilds the design matrix for updating receiver effects (beta parameters) in the Alternating Least Squares algorithm, holding sender effects (alpha) fixed.
Details
In the ALS algorithm, when updating beta with alpha fixed, the model becomes linear in beta. This function constructs the required design matrix efficiently.
For covariate k and observation (i,j,t), the design matrix element is: [A * X[,,t] * W[,,k]'][i,j]
Where A = sum_l alpha[l] * W[,,l] is the current sender effects matrix (with alpha[1] = 1 fixed for identifiability).
The algorithm mirrors the alpha update but with roles reversed: 1. Compute A from current alpha and W 2. For each covariate k: - Calculate A * X * W[,,k]' for all time points - Flatten to match the vectorized Y 3. Combine into design matrix