function Trans_Mat = T_mat_Genner(N)
%function Matter = T_mat_Genner(N, sig_red);
%Inputs: dimension of the factor (number of levels)
%
%output: the transform matrix Q_M from the notes


%to get the factors in the full space, with the sum-to-zero constraint, we
%first need the matrix of Helmert Contrasts:
Helmert_Mat=[rot90(tril(ones(N-1,N-1),-1) + diag(-[1:1:N-1])); ones(1, N-1)];
%we can then calculate the transformation matrix using the equation from
%the notes:
Trans_Mat=Helmert_Mat*(Helmert_Mat'*Helmert_Mat)^(-1/2);

%generating a MVN random vector in the reduced space, using the std of the factor in
%the reduced space, and hitting it with Trans_Mat, will give factor levels
%in the full space with the sum-to-zero constraint. 