Base type mismatch in assignment

I could use help with a coding error.

I have a 2x2 covariance matrix in which the sigmas on the diagonal are constrained to be identical. I have accomplished this previously by creating a temporary vector[2] in the transformed parameters in which the sigma gets assigned to both slots.

Although that has been successful in the past, now I’m getting an error about a base type mismatch. Code and error are both below:

transformed parameters{
	
 matrix [ Nx_kl_dyad_ID , 2 ] v_kl_dyad_ID;

	{
		vector[2] sigma_kl_temp;

	sigma_kl_temp[1] = sigma_kl_dyad_ID;
	sigma_kl_temp[2] = sigma_kl_dyad_ID;
	v_kl_dyad_ID = (diag_pre_multiply ( sigma_kl_temp, L_Rho_kl_dyad_ID) * z_kl_dyad_ID)';
	}
}

Base type mismatch in assignment; variable name = sigma_kl_temp, type = real; right-hand side type=vector
error in ‘model1495a5dd847_b77ca46156986d60d2c94302d3b1843a’ at line 64, column 22
62: v_c__d_ID = ( diag_pre_multiply ( sigma_c__d_ID , L_Rho_c__d_ID ) * z_c__d_ID )’;
63:
64: sigma_kl_temp[1] = sigma_kl_dyad_ID;
^
65: sigma_kl_temp[2] = sigma_kl_dyad_ID;

You can’t assign a vector (sigma_kl_dyad_ID) to a scalar (sigma_kl_temp[1]).

1 Like

Ah, I see what I did. This model has other covariance matrices and I assigned the sigmas as vectors in the parameters block.

But given that I want the same sigma on the diagonal, when I define sigma_kl_dyad_ID as:

real< lower = 0 > sigma_kl_dyad_ID;

then the parser no longer has a problem with the assignment in the transformed parameters.

Thanks, Ben.