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

Hi, I am trying to run the following stan model with the given data. But it gave me the following error.

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

Anyone can help? Thank you very much!

stan.m="
data {
int<lower=0> N[1];
vector<lower=0>[N[1]] dose;
real<lower=0> dr;
int DLT[N[1]];
int total[N[1]];

vector[2] mu;
cov_matrix[2] Sigma;
}
parameters {
vector[2] log_ab;
}

transformed parameters {
real log_a = log_ab[1];
real log_b = log_ab[2];
real<lower=0> b = exp(log_b);
}

model {
vector[N[1]] prob;
// Prior
log_ab~multi_normal(mu, Sigma);
//likelihood

for(i in 1:N[1]){
prob[i]=exp(log_a + blog(dose[i]/dr))/(1+exp(log_a + blog(dose[i]/dr)));
DLT[i] ~ binomial(total[i],prob[i]);
}
}
"

stan_data <- list(
dose = c(800),
total = c(7),
DLT = c(1),
N = 1,
dr = dr,

mu = mu,
Sigma = Sigma,
Rho      = rho

)

fit = stan(model_code=stan.m, data=stan_data, iter=1000, chains=4,thin=2)

The messages get swallowed but there are several things wrong here.

First, the model doesn’t parse. You need to do b * log(...) rather than b log(...); i.e. the Stan language does not support implicit multiplication.

Second, the model doesn’t initialize.

Exception: mismatch in number dimensions declared and found in context; processing stage=data initialization; variable name=N; dims declared=(1); dims found=() 

This is because you declared int<lower=0> N[1]; but passed a scalar integer. You should just do

int<lower=0> N;

and then replace all the N[1] with N.

The same thing with dose, total, etc. If you really want it to be a vector of length 1, you can pass it as as.array(dose) but you probably just want to declare it as a scalar.

Although it doesn’t throw an error, you should just write your likelihood as

DLT ~ binomial_logit(total, log_a + b * log(dose / dr) / 
                     exp(log1p_exp(log_a + b * log(dose / dr));

and even then you could avoid the recalculation of b * log(dose / dr) by saving it to a temporary vector. Also, only specify thin > 1 if you run out of RAM, which is unlikely for a model like this.

stan.m="
data {
int<lower=0> N[1];
vector<lower=0>[N[1]] dose;
real<lower=0> dr;
int DLT[N[1]];
int total[N[1]];

vector[2] mu;
cov_matrix[2] Sigma;
}
parameters {
vector[2] log_ab;
}

transformed parameters {
real log_a = log_ab[1];
real log_b = log_ab[2];
real<lower=0> b = exp(log_b);
}

model {
vector[N[1]] prob;
// Prior
log_ab~multi_normal(mu, Sigma);
//likelihood

for(i in 1:N[1]){
prob[i]=exp(log_a + blog(dose[i]/dr))/(1+exp(log_a + blog(dose[i]/dr)));
DLT[i] ~ binomial(total[i],prob[i]);
}
}
"
mu.loga=-3.025
mu.logb=0.023

sig.loga=1.810
sig.logb=1.023

rho=-0.450

cov.ab=rhosig.logasig.logb

mu=c(mu.loga,mu.logb)
Sigma=rbind(c(sig.loga^2,cov.ab),c(cov.ab,sig.logb^2))

stan_data <- list(
dose = as.array(c(800)),
total = as.array(c(7)),
DLT = as.array(c(1)),
N = 1,
dr = 400,

mu = mu,
Sigma = Sigma,
Rho = rho
)

fit = stan(model_code=stan.m, data=stan_data, iter=1000, chains=4,thin=2)

Thank you so much for your reply! Please see the above code. I tried to add as.array() and add the multiplier, but it did not work out. Any other suggestions? Thank you!

Yes

It worked, thank you very much!

I posted another question with link

I appreciate if you can advice as well!

Thank you!

Hello, would you please help me with my other question? I am very new to stan and still learning the language. When the code could not go through, it is really frustrated. I appreciate that you helped me with my first question and the code went through successfully. I really appreciate your time taking a look of my other similar question. Thank you very much!!!

It worked, thank you very much!