How to make data types compatible

Hi all,

I have written the following model

data {
    int<lower=1> N;
    int<lower=2> n_fighters;
    int<lower=1, upper=n_fighters> red[N];                  # fighter_id
    int<lower=1, upper=n_fighters> blue[N];                 # opponent_id
    array[N, 2] int<lower=0> n_strikes_red;
    array[N, 2] int<lower=0> n_strikes_blue;
    int<lower=0> t_fight[N];
}

parameters {
    vector[n_fighters - 1] raw_lambda_str_att;
    vector[n_fighters - 1] raw_lambda_str_def;
    real gamma_str;
}

transformed parameters {
    vector[n_fighters] lambda_str_att = append_row(0, raw_lambda_str_att);
    vector[n_fighters] lambda_str_def = append_row(0, raw_lambda_str_def);
 }

model {
    # priors
    gamma_str ~ cauchy(0, 10);
    raw_lambda_str_att ~ normal(0, 2);
    raw_lambda_str_def ~ normal(0, 2);

    # work-rate model
    n_strikes_red[2] ~ poisson_log(gamma_str + lambda_str_att[red] + lambda_str_def[blue] + log(t_fight));
}

The array n_strikes_red consist of integers values that represent the number of strikes landed and the number of strikes attempted for N fights.

When I run this model I get the following error:

Instead supplied arguments of incompatible type: vector, array[ ] real.

How can I overcome this error?

Could you share the full error message with the line number? I suspect it is the poisson line, as you’re adding a vector to an array. If so, you could convert t_fight to a vector in the transformed data block.

I also noticed that you’re combining the old array syntax (the first line quoted below) with the new syntax (second line). To avoid issues in the future, I would rewrite using the new syntax only.

Yes, it happens indeed at that particular line.

As I am working with integers only I assumed this was the best way to define the “data”-block. Is it better to define the variables as vectors?
In the extended model I have additional data such as kicks, punches, elbows etc.

This is indeed the issue, as it returns a array of reals.

If the data is truly integers, you may want to keep the data block with an array of ints for clarity. But in transformed data, you can add

vector[N] log_t_fight = to_vector(log(t_fight));

and then use this in the model block – it will also avoid re-computing the same log every time if you do this

1 Like