# How to input a matrix with half decided structure?

For example, I have a H matrix with 10 columns and I want to estimate the first 4 columns but I know the values of the last 6 columns already. The first 4 columns are like parameters but the last 6 columns are like data, how to achieve that in Stan?

Model `H = append_col(unknown_matrix, known_matrix)` somehow.

After having H<- append_col(H1, H2) (with H1 being the estimators and H2 being the data), which block of stan code should H be put into?

The model block; you need to come up with a likelihood for it.

When I put it in the model block it does not work (error message: attempt to assign variable in wrong block. left-hand-side variable origin=parameter

ERROR at line 69), why is that? I need to come up with a likelihood for what? H? H1? H2? What if I just have a prior for H1, no direct likelihood related with H.

You should not be declaring `H` in the parameters block, just `H1`. I can’t say how to model it but I presumed you had some joint distribution in mind for the whole matrix. If you just have a conditional distribution of `H2` given `H1`, then you don’t need to glue them together.

My situation is not like that. My H has some structure, for example, in the simulated data, the real H is:
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 1 0 0 1 1 1 0
[2,] 1 0 0 0 1 1 0
[3,] 1 1 0 0 1 1 0
[4,] 1 0 0 0 1 1 0
[5,] 1 0 0 1 1 1 0
[6,] 0 0 1 0 1 1 0
[7,] 1 0 0 0 1 1 0
[8,] 1 0 1 1 1 1 0
[9,] 0 0 1 0 1 1 0
[10,] 1 0 0 0 1 1 0
[11,] 1 0 0 0 0 0 1
[12,] 1 1 1 0 0 0 1
[13,] 0 0 0 0 0 0 1
[14,] 0 0 0 1 0 0 1
[15,] 0 0 0 0 0 0 1
[16,] 1 1 0 0 0 0 1
[17,] 1 1 0 0 0 0 1
[18,] 1 0 0 1 0 0 1
[19,] 1 0 0 0 0 0 1
While the first 4 columns have 1 and 0s randomly distributed, column 5,6 and 7 has some pattern in it. Then I have
Phii <- E .* H;
Theta <- Z*transpose(Phii); and then Theta is used as a parameter to generated data, so H_ij =1 means E_ij is used, H_ij=- means E_ij is not used. However, I figured out it is hard to model all three types in H, I will manually input column 5,6, and 7, and I am really interested in estimating in column 1 to 4. How can I tell stan that?

I have tried to put the H<- append_col(H1, H2) in the transformed parameter block, the code runs, but H1 have all identical columns, i.e., H1[,1]=H1[,2]=H1[,3]=H1[,4]. I don’t know why it happened and how to fix the code.

Well, if `H1` consists of unknown zeros and ones, then you cannot declare that in the parameters block anyway. You would have to figure out some way to integrate those out of the likelihood function.

I have used stan platform for quite sometime and have been posting questions. I know that in my model, the truth for H is 1 and 0, but I decide to start with a continuous prior that would generate 1 and 0 mainly, for example beta(0.001,0.001). I know this is imperfect, but just to start with as I am not really an expert in bayesian.

In general, it’s very hard for us to answer questions without a bit more background on what the model is. Here, you haven’t mentioned what the likelihood is, so it’s impossible for us to give you any concrete suggestions.

If there are binary unknowns, you need to marginalize them out. This might be intractable if they’re not conditionally independent, so this might not be a model Stan can fit.

Stan won’t be able to move between the modes at 0 and 1 in a `beta(epsilon, epsilon)` distirbution.