Simple code for prediction using generated quantities

Hi
I am looking for a simple way to code in the generated quantities block for the probability of an outcome variable in a simple regression model being greater than a particular value of the outcome at a particular value of the predictor.
With this code, there are 2 separate datasets, with time_w and time_h being the predictors and logsf_w and logsf_h the outcomes.
So I want to know what is the (posterior predicted)probability of logsf_w being greater than say 5,when time_w is equal to say 0,or 10. And also the same for time_h and logsf_h.
The sigma values are given and fixed here.

model_string<-
"data {
int n1;
int n2;
vector[n1] time_h;
vector[n1] logsf_h;
real<lower=0> sigma_h;
vector[n2] time_w;
vector[n2] logsf_w;
real<lower=0> sigma_w;
}

parameters {
real beta0_h;
real beta1_h;
real beta0_w;
real beta1_w;
}

model {
vector[n1] mu_h;
vector[n2] mu_w;
beta0_h ~ normal(0,10);
beta1_h ~ normal(0,1);
beta0_w~ normal(0,10);
beta1_w~ normal(0,1);
mu_h = beta0_h+ beta1_h * time_h;
logsf_h ~ normal(mu_h, sigma_h);
mu_w = beta0_w+ beta1_w * time_w;
logsf_w ~ normal(mu_w, sigma_w);
}

generated quantities {
}
"
indent preformatted text by 4 spaces

Thanks for any help.

Chris

This makes perfect sense to do. Here’s some code:

generated quantities {
  int indicator;
  {
    real mu_w = beta0_w + beta1_w * 10; // or whatever you want it to be, you might want to make the '10' a data array so you can change it easily
    indicator = logsf_w > normal_rng(mu_w, sigma_w);
  }
}

And you can look at the posterior estimates of the mean of indicator or whatever.

Thanks for replying. Unfortunately I get this error code:
Version:1.0 StartHTML:0000000107 EndHTML:0000003495 StartFragment:0000000127 EndFragment:0000003477

SYNTAX ERROR, MESSAGE(S) FROM PARSER: binary infix operator >= with functional interpretation logical_gt requires arguments or primitive type (int or real), found left type=vector, right arg type=real; No matches for: logical_gt(vector, real) Available argument signatures for logical_gt: logical_gt(int, int) logical_gt(int, real) logical_gt(real, int) logical_gt(real, real) Base type mismatch in assignment; variable name = indicator, type = int; right-hand side type=ill formed error in ‘model1cdc745f2e2e_ae3835deadb50045c89945352c8ee8d0’ at line 36, column 12 ------------------------------------------------- 34: { 35: real mu_w = beta0_w + beta1_w * 10; // or whatever you want it to be, you might want to make the ‘10’ a data array so you can change it easily 36: indicator = logsf_w > normal_rng(mu_w, sigma_w); ^ 37: } ------------------------------------------------- PARSER EXPECTED: <expression assignable to left-hand side> Error in stanc(file = file, model_code = model_code, model_name = model_name, : failed to parse Stan model ‘ae3835deadb50045c89945352c8ee8d0’ due to the above error.

Regards

Chris

Oh wow, that’s cause what I typed is wrong lol. Try this:

generated quantities {
  int indicator;
  {
    real mu_w = beta0_w + beta1_w * 10; // or whatever you want it to be, you might want to make the '10' a data array so you can change it easily
    indicator = normal_rng(mu_w, sigma_w) > 5; // Generate new logsf_w values and see if they're greater than 5
  }
}

Thanks Ben-that works fine now.
Regards
Chris