This is a simpler, but related issue to the one I posted on June 2.
Suppose we have 100 trials (N) and 40 (M) known successes, and we wish to estimate the binomial rate parameter for probability of success, theta. But suppose itself is uncertain (estimated) but we have information that the true value of N (NT) is less than and that the true proportion of individuals that are capable is a proportion of N, where the parameter governing the proportion is distributed as a Beta random variable. We wish to estimate theta accounting for the additional uncertainty due to uncertainty about N. I have easily programmed this in a fortran program using Metropolis-within-Gibbs. I am unable to do this in Stan/Rstan. The issue seems to be one of trying to sample a parameter declared a data or transformed data. Below are the .stan and .R files. any help will be much appreciated:
///Simple binomial inference of probability of success theta given known
//number of trials and successes.
// NG started June 7 2018
//This will not work.
int<lower=0> N; //number of trials
int<lower=0> M; //number of successes
real <lower=0, upper=1> theta; //probability of success
real<lower=0, upper=1> z;
theta ~ beta(B_Alpha,B_Beta);
z ~ beta(NT_Alpha, NT_Beta);
NT = floor(N*z);
#NG started June 7 2018
N <- 100; # number of trials
M <- 40; # number successes
B_Alpha<-50;# beta alpha (number prior successes) parameter for prior on success param theta
B_Beta<-50; # beta Beta (prior failures) param for prior on theta
NT_Alpha<-100; #beta alpha param for distribution of true number of trials,z: (NT = N*z)
NT_Beta<-50; #beta beta param for z
stanDat <- list(N,M, B_Alpha, B_Beta, NT_Alpha, NT_Beta)
Binomtst2fit <- stan(file=“Binomtst2.stan”, data = stanDat, pars = params, iter = 1000, chains = 4)