# [Re-Post] Rejecting Initial Value (Student_t distribution)

I accidentally withdrew from the previous post.
Here’s the link to the original post: Rejecting Initial Value (Student_t distribution)

I’ve edited the model section of the Stan code like this:

``````model {
// Specify the model for the standardized data
for(i in 1:(N-1)) {
//    for(j in 1:(T-1)) {
//      z_y[i,j] ~ student_t(nu, z_beta_0[i] + z_c[i,j] * z_beta_1[i] + z_a[i,j] * z_beta_2[i] + z_b[i,j] * z_beta_3[i], z_sigma);
z_y[i,] ~ student_t(nu, z_beta_0[i] + z_c[i,] * z_beta_1[i] + z_a[i,] * z_beta_2[i] + z_b[i,] * z_beta_3[i], z_sigma);
//    }
if(i == 1) {
print(z_beta_0);
print(z_beta_1);
print(z_beta_2);
print(z_beta_3);
}
}

// Priors vague on standardized scale:
z_beta_0 ~ normal(0, 4);
z_beta_1 ~ student_t(1, 0, sigma_beta);
z_beta_2 ~ student_t(1, 0, sigma_beta);
z_beta_3 ~ student_t(1, 0, sigma_beta);
z_sigma ~ uniform(1.0E-5, 1.0E+1);
nu ~ exponential(1/30.0);
sigma_beta ~ gamma(2.618,1.618); // mode 1.0, sd 1.0
}
``````

No value is printing and I’m getting the same error as before :/

You are printing after the error occurs. Move the print statements up to the `transformed data` block.

1 Like

oh the transformed a,b,c matrices are nan…

``````    if(i == 1) {
print(z_y[i,]);
print(z_a[i,]);
print(z_b[i,]);
print(z_c[i,]);
}
``````
``````[-4.31084,-2.52493,-2.02949,-1.82791,-1.67506,-1.53718,-1.42394,-1.29744,-1.18898,-1.10052,-0.96623,-0.842091,-0.769982,-0.720461,-0.663362,-0.600796,-0.535553,-0.438247,-0.375654,-0.331008,-0.294284,-0.264194,-0.234704,-0.204969,-0.17398,-0.138487,-0.10644,-0.0774543,-0.0454332,-0.01363,0.0100981,0.0428227,0.0736126,0.102284,0.143898,0.190082,0.238933,0.299481,0.358189,0.394845,0.423727,0.46188,0.503777,0.548978,0.581706,0.593995,0.610401,0.629602,0.643542,0.655682,0.672034,0.698187,0.77121,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016,0.948016]
[nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan]
[nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan]
[nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan,nan]
``````

I hate it when that happens

I’m new to Stan and modeling so I still don’t think I understand the issue correctly.
I’ve written the same codes for y,a,b and c - why is it that only y values are working properly?

This doesn’t have much to do with Stan modeling. It is just data processing. I suspect something is wrong with the data you are giving it. But another thing you can and should do is to create functions to do anything non-trivial. That way you can export them to R and verify that they are working correctly. So, something like

``````functions {
row_vector standardize(row_vector x) {
real xbar = mean(x);
real s = sd(x);
return (x - xbar) / s;
}
}
``````

Then, in R do

``````library(rstan)
expose_stan_functions("filename.stan")
standardize(y[1,])
``````

Things like this will help you narrow down where the problem is.

1 Like

ohhhhh I see. That helped a lot thanks.
So now the transformed data block seems to be alright, but still the same errors…

``````SAMPLING FOR MODEL 'model2_2' NOW (CHAIN 1).
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: student_t_lpdf: Location parameter[1] is nan, but must be finite!  (in 'model99924c0e669e_model2_2' at line 67)
``````

That means it is not alright yet.

Thanks so much for your help and patience :)