I would start by doing a simulation to get a sample of $y$ values when $n=n_{new}$ from the training distribution. Then subtract of $y_{new}$ from the $y$ sample you got, and check if it's credibly non-zero. Here's some code to do that:
modelDescription = "
model {
for( i in 1 : ny ) {
y[i] ~ dbin(p[i],n[i])
p[i] ~ dbeta(alpha,beta)
}
alpha ~ dunif(0,1e3)
beta ~ dunif(0,1e3) #some priors...
}
"
sampleSize=500
y=rbinom(sampleSize,10,0.5)
n=round(y*10)-rbinom(sampleSize,2,0.5)+rbinom(sampleSize,2,0.5) #set p=1/10 with someRandomFluctuactions
n<-ifelse(n<1,1,n) #ensure all n>0
dataList = list(
ny = length(y) ,
y = y ,
n = n
)
parameters = c("alpha","beta")
#this is just a wrapper I have for rjags::coda.samples and dclone::codaSamples
test1 = bjmCreate("model1",parameters,modelDescription,dataList,60000)
require(coda)
test1p <- window(test1,start(test1)+1000) #Burn-in
chain<-as.matrix(test1p)
alpha<-chain[,1]
beta<-chain[,2]
chainSize<-nrow(chain) #note that nrow(chain)==length(alpha)==length(beta)
In the code above, we got an alpha and beta sample from MCMC, now we are going to generate a sample for $y$ when $n=50$
We model $y$ as $y \sim Binomial(n,p)$. So to generate sample for $y$, we need to do y<-rbinom(chainSize,newN,p).
We know the value of $n_{new}$, but we don't have $p$, but we can get a sample of it by remebering $p \sim Beta(\alpha,\beta)$, so we get a $p$ sample from p<-rbeta(chainSize,alpha,beta).
So, by pluging one thing into the other:
newN = 50 #setting here the value of N for which we'll predict y
p<-rbeta(chainSize,alpha,beta)
y<-rbinom(chainSize,newN,p)
Now we have a sample for $y$ when $n=50$, and our work would be done if we just wanted to predict it. But instead, you want to check if it an specific value of $y$ is from that distribution, so we do
newY = 5
yDiff <- y-newY
And check if the difference between both is credibly zero.
#Analisys of HPD
print(HPDinterval(mcmc(yDiff)))
densityplot(mcmc(yDiff))
I got the following result from densityplot(mcmc(yDiff)):
lower upper
var1 -4 4
attr(,"Probability")
[1] 0.95
That is, zero is within the 95% HDP, and thus, we can not reject the hypothesis that the proposed $(y_{new},n_{new})$ "comes from the same model as the training set".
This, in fact, makes sense since the our "true" value p=1/10 is exactly the values we used ($y_{new}=5$ and $n_{new}=50$).