# Rejecting Initial Value (Student_t distribution)

Hi,
my rStan code is as follows:

``````data {
int<lower=1> N;
int<lower=1> T;
matrix[N,T] y;
matrix[N,T] a;
matrix[N,T] b;
matrix[N,T] c;
}
transformed data {
// Standardize the data:
matrix[N, T] z_y;

matrix[N, T] z_a;
matrix[N, T] z_b;
matrix[N, T] z_c;

real a_m[N];
real a_sd[N];
real b_m[N];
real b_sd[N];
real c_m[N];
real c_sd[N];

real y_m[N];
real y_sd[N];

for(i in 1:N) {
y_m[i] = mean(y[i,]);
y_sd[i] = sd(y[i,]);
z_y[i,] = (y[i,] - y_m[i]) / y_sd[i];

a_m[i] = mean(a[i,]);
a_sd[i] = sd(a[i,]);
z_a[i,] = (a[i,] - a_m[i]) / a_sd[i];
c_m[i] = mean(c[i,]);
c_sd[i] = sd(c[i,]);
z_c[i,] = (c[i,] - c_m[i]) / c_sd[i];
b_m[i] = mean(b[i,]);
b_sd[i] = sd(b[i,]);
z_b[i,] = (b[i,] - b_m[i]) / b_sd[i];
}
}
parameters {
real z_beta_0[N];

real z_beta_1[N];
real z_beta_2[N];
real z_beta_3[N];

real<lower=0> z_sigma;
real<lower=0> sigma_beta;
real<lower=0> nu;
}

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);
//    }
}

// 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
}
generated quantities {
real beta_0[N];
real beta_1[N];
real beta_2[N];
real beta_3[N];
real sigma[N];

// Transform to original scale:
for(i in 1:N) {
beta_1[i] = (z_beta_1[i] / c_sd[i]) * y_sd[i];
beta_2[i] = (z_beta_2[i] / a_sd[i]) * y_sd[i];
beta_3[i] = (z_beta_3[i] / b_sd[i]) * y_sd[i];
beta_0[i] = z_beta_0[i] * y_sd[i] + y_m[i] - ((z_beta_1[i] * c_m[i] / c_sd[i]) + (z_beta_2[i] * a_m[i] / a_sd[i]) + (z_beta_3[i] * b_m[i] / b_sd[i])) * y_sd[i];
sigma[i] = z_sigma * y_sd[i];
}
}
``````

When I run this code, I get this error:

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 ‘model105c715d6449f_model2_2’ at line 60)

Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] “Error in sampler\$call_sampler(args_list[[i]]) : Initialization failed.”

My R Session Info is as follows:

``````> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.5

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] coda_0.19-1        rstan_2.17.3       StanHeaders_2.17.2 ggplot2_2.2.1

loaded via a namespace (and not attached):
[1] Rcpp_0.12.16     codetools_0.2-15 lattice_0.20-35  grid_3.5.0       plyr_1.8.4       gtable_0.2.0     stats4_3.5.0     scales_0.5.0
[9] pillar_1.2.2     rlang_0.2.0      lazyeval_0.2.1   tools_3.5.0      munsell_0.4.3    compiler_3.5.0   inline_0.3.14    colorspace_1.3-2
[17] gridExtra_2.3    tibble_1.4.2
``````

Your help would be much appreciated.

I would guess that the standardization of the data resulted in a NaN somewhere. You can and should check by defining everything in transformed data to have a lower bound of `negative_infinity()`, which will be violated if anything is NaN.

Thanks for your reply.

I’ve changed the stan code

``````parameters {
real<lower=negative_infinity()> z_beta_0[N];

real<lower=negative_infinity()> z_beta_1[N];
real<lower=negative_infinity()> z_beta_2[N];
real<lower=negative_infinity()> z_beta_3[N];

real<lower=0> z_sigma;
real<lower=0> sigma_beta;
real<lower=0> nu;
}
``````

and I got the same kind of error.

``````#a hundred of these
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 'model9992232f24ac_model2_2' at line 60)

Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] "Error in sampler\$call_sampler(args_list[[i]]) : Initialization failed."
error occurred during calling the sampler; sampling not done
``````

Try printing out all the transformed data values for the first observation.