Help! trying deprecated constructor; please alert package maintainer Error in new_CppObject_xp(fields$.module, fields$.pointer, ...)

Hi,

I have the following stan model and running code but got the error messages. Would anyone please take a look and give some advice? Thank you very much!

trying deprecated constructor; please alert package maintainer
Error in new_CppObject_xp(fields$.module, fields$.pointer, …) :
no valid constructor available for the argument list
In addition: Warning message:
In if (nchar(CXX) > 0) return(TRUE) :
the condition has length > 1 and only the first element will be used
failed to create the sampler; sampling not done

’Data and running code’

stan_data <- list(
C = 2,
N = c(7,3),
DLT = c(1,0),
Dose = c(800,200),
Dose0 = 400,
D = 5,
Dose_set = c(100,200,400,600,800),

X1 = c(0,1),
X2 = c(0,1),
Mn = c(-3.025, 0.023),
SD_loga = 1.810,
SD_logb = 1.023,
Rho = -0.450,
Gamma_mu1 = 0,
Gamma_mu2 = -1.374,
Gamma_SD1 = 0.255,
Gamma_SD2 = 0.837
)

stanmodel <- stan_model(file=‘BLRM-mono-covariate-cohort.stan’)
fit <- sampling(stanmodel, data=stan_data, iter=6000, warmup=1000, seed=1234)

’BLRM-mono-covariate-cohort.stan’

data {
int<lower=1> C; // number of cohorts
int<lower=1> N[C]; // number of Subjects by cohort
int<lower=0> DLT[C]; // number of DLTs by cohort
real<lower=0> Dose[C]; // dose amount by cohort
real<lower=0> Dose0; // standard dose
int<lower=1> D; // number of all doses
real<lower=0> Dose_set[D]; // dose amount of all doses

int X1[C] ; // number of all doses
int X2[C] ; // number of all doses

vector[2] Mn;
real<lower=0> SD_loga;
real<lower=0> SD_logb;
real<lower=-1, upper=1> Rho;
real Gamma_mu1;
real Gamma_mu2;
real<lower=0> Gamma_SD1;
real<lower=0> Gamma_SD2;
}

transformed data {
matrix[2, 2] Cov;
Cov[1, 1] = square(SD_loga);
Cov[1, 2] = SD_loga * SD_logb * Rho;
Cov[2, 1] = SD_loga * SD_logb * Rho;
Cov[2, 2] = square(SD_logb);
}

parameters {
vector[2] log_ab;
real log_gamma1;
real log_gamma2;
}

transformed parameters {
real log_a = log_ab[1];
real log_b = log_ab[2];
real b = exp(log_b);
real gamma1 = exp(log_gamma1);
real gamma2 = exp(log_gamma2);
real q[C];
for (c in 1:C)
q[c] = inv_logit(log_a + b*log(Dose[c]/Dose0) + gamma1*X1[c] + gamma2*X2[c]);
}

model {
for (c in 1:C) {
DLT[c] ~ binomial(N[c], q[c]);
}
log_ab ~ multi_normal(Mn, Cov);
log_gamma1 ~ normal(Gamma_mu1, Gamma_SD1);
log_gamma2 ~ normal(Gamma_mu2, Gamma_SD2);
}

generated quantities {
real p[D];
for (d in 1:D)
p[d] = inv_logit(log_a + b*log(Dose[d]/Dose0) + gamma1*X1[d] + gamma2*X2[d]);
}

You pass D as 5 but dose is of length 2, which means the last loop accesses the “third” element of dose and throws an error.

Thank you very much for your comments, Ben! D is for length(Dose_set), so it is 5. But you are right, I changed from Dose to Dose_set for the quantities such that D is used correctly. Please see the following changed code. But I still have errors. I am very sorry for so many questions and thank you so much for your patient help!

errors
[1] "Error in sampler$call_sampler(args_list[[i]]) : “
[2] " Exception: []: accessing element out of range. index 3 out of range; expecting index to be between 1 and 2; index position = 1X1 (in ‘model1fac78057c1e_BLRM_mono_covariate_cohort’ at line 62)”
[1] “error occurred during calling the sampler; sampling not done”

Data and running code’

stan_data <- list(
C = 2,
N = c(7,3),
DLT = c(1,0),
Dose = c(800,200),
Dose0 = 400,
D = 5,
Dose_set = c(100,200,400,600,800),

X1 = c(0,1),
X2 = c(0,1),
Mn = c(-3.025, 0.023),
SD_loga = 1.810,
SD_logb = 1.023,
Rho = -0.450,
Gamma_mu1 = 0,
Gamma_mu2 = -1.374,
Gamma_SD1 = 0.255,
Gamma_SD2 = 0.837
)

stanmodel <- stan_model(file=‘BLRM-mono-covariate-cohort.stan’)
fit <- sampling(stanmodel, data=stan_data, iter=6000, warmup=1000, seed=1234)

’BLRM-mono-covariate-cohort.stan’

data {
int<lower=1> C; // number of cohorts
int<lower=1> N[C]; // number of Subjects by cohort
int<lower=0> DLT[C]; // number of DLTs by cohort
real<lower=0> Dose[C]; // dose amount by cohort
real<lower=0> Dose0; // standard dose
int<lower=1> D; // number of all doses
real<lower=0> Dose_set[D]; // dose amount of all doses

int X1[C] ; // number of all doses
int X2[C] ; // number of all doses

vector[2] Mn;
real<lower=0> SD_loga;
real<lower=0> SD_logb;
real<lower=-1, upper=1> Rho;
real Gamma_mu1;
real Gamma_mu2;
real<lower=0> Gamma_SD1;
real<lower=0> Gamma_SD2;
}

transformed data {
matrix[2, 2] Cov;
Cov[1, 1] = square(SD_loga);
Cov[1, 2] = SD_loga * SD_logb * Rho;
Cov[2, 1] = SD_loga * SD_logb * Rho;
Cov[2, 2] = square(SD_logb);
}

parameters {
vector[2] log_ab;
real log_gamma1;
real log_gamma2;
}

transformed parameters {
real log_a = log_ab[1];
real log_b = log_ab[2];
real b = exp(log_b);
real gamma1 = exp(log_gamma1);
real gamma2 = exp(log_gamma2);
real q[C];
for (c in 1:C)
q[c] = inv_logit(log_a + blog(Dose[c]/Dose0) + gamma1X1[c] + gamma2*X2[c]);
}

model {
for (c in 1:C) {
DLT[c] ~ binomial(N[c], q[c]);
}
log_ab ~ multi_normal(Mn, Cov);
log_gamma1 ~ normal(Gamma_mu1, Gamma_SD1);
log_gamma2 ~ normal(Gamma_mu2, Gamma_SD2);
}

generated quantities {
real p0[D];
real p600[D];
real p800[D];
for (d in 1:D)
p0[d] = inv_logit(log_a + blog(Dose_set[d]/Dose0));
p600[d] = inv_logit(log_a + b
log(Dose_set[d]/Dose0) + gamma1);
p800[d] = inv_logit(log_a + b*log(Dose_set[d]/Dose0) + gamma1 + gamma2);
}

What you pasted does not parse and so I don’t see that error. You just have to go to line 62 and figure out why your indexing exceeds the size of the container. The following runs with the data you specified (not that it is much more readable if you put the code in a code block):

data {
  int<lower=1> C; // number of cohorts
  int<lower=1> N[C]; // number of Subjects by cohort
  int<lower=0> DLT[C]; // number of DLTs by cohort
  real<lower=0> Dose[C]; // dose amount by cohort
  real<lower=0> Dose0; // standard dose
  int<lower=1> D; // number of all doses
  real<lower=0> Dose_set[D]; // dose amount of all doses

  int X1[C] ; // number of all doses
  int X2[C] ; // number of all doses

  vector[2] Mn;
  real<lower=0> SD_loga;
  real<lower=0> SD_logb;
  real<lower=-1, upper=1> Rho;
  real Gamma_mu1;
  real Gamma_mu2;
  real<lower=0> Gamma_SD1;
  real<lower=0> Gamma_SD2;
}

transformed data {
  matrix[2, 2] Cov;
  Cov[1, 1] = square(SD_loga);
  Cov[1, 2] = SD_loga * SD_logb * Rho;
  Cov[2, 1] = SD_loga * SD_logb * Rho;
  Cov[2, 2] = square(SD_logb);
}

parameters {
  vector[2] log_ab;
  real log_gamma1;
  real log_gamma2;
}

transformed parameters {
  real log_a = log_ab[1];
  real log_b = log_ab[2];
  real b = exp(log_b);
  real gamma1 = exp(log_gamma1);
  real gamma2 = exp(log_gamma2);
  real q[C];
  for (c in 1:C)
    q[c] = inv_logit(log_a + b*log(Dose[c]/Dose0) + gamma1*X1[c] + gamma2*X2[c]);
}

model {
  for (c in 1:C) {
    DLT[c] ~ binomial(N[c], q[c]);
  }
  log_ab ~ multi_normal(Mn, Cov);
  log_gamma1 ~ normal(Gamma_mu1, Gamma_SD1);
  log_gamma2 ~ normal(Gamma_mu2, Gamma_SD2);
}

generated quantities {
  real p0[D];
  real p600[D];
  real p800[D];
  for (d in 1:D) {
    p0[d] = inv_logit(log_a + b*log(Dose_set[d]/Dose0));
    p600[d] = inv_logit(log_a + b*log(Dose_set[d]/Dose0) + gamma1);
    p800[d] = inv_logit(log_a + b*log(Dose_set[d]/Dose0) + gamma1 + gamma2);
  }
}
1 Like

Thank you so much, Ben!!! The code actually worked after I clear the workspace. And thank you for letting me know the code clock stuff. I will use that for future postings.