Bayesian inconsistency I have a small knowledge of Bayesian analysis which I want to apply to invert some instrumentation data which has a complex nonlinear response. However this simple example confused me so before I go any further I wanted to check it.
Lets assume I had n trials each with a 10% chance of success. I have 10 successes, and I want to find out how many trials there were. (This is equivalent to me saying I have an instrument with a 10% chance of detecting the things I want to measure. It detected 10 of them. I want to find how many things there really were - I know this is a trivial example, I just want to understand the method).
I can use a binomial distribution to generate my likelihood function - which is equal to my posterior as my prior is the same for all values. This gives a mode at 100 trials - as expected I guess. However the expectation is 109. Somehow I think something is wrong here. If I set up many experiments each with 100 trials and a 10 % success rate then on average I get an expectation of 109 trials (every experiment gives an expectation on n sucesses * 10 + 9) rather than 100. Surely the expectation should be unbiased? Am I doing something wrong or have I misunderstood?

Edit below to give more information after Greg Snow's response
My understanding is as follows, please correct me if I am wrong 
Taking Bayes theorem I have
P(Nt|Ns,I) = k x P(Ns|Nt,I) x P(Ns|I)
where Nt is the number of trials, Ns the number of successes, I is my conditioning information and k is a constant of proportionality. My conditioning information is simply that the trials are independent and each have a 10% chance of success. I have no prior information about Nt so my prior is just set to a constant - i.e P(Ns|I)=1. This gives
P(Nt|Ns,I) = k x P(Ns|Nt,I)
or if I sub in my numbers
P(Nt|Ns=10,I) = k x P(Ns=10|Nt,I).
I can represent P(10|Nt,I), by a binomial distribution
P(Nt|Ns=10,I) = k(0.1^10)((0.9)^(Nt-10))Nt!/(Ns!(Nt-Ns)!).
I then find the expectation which makes the k drop out and I get
E[Nt] = 109.
if I repeat with different values of Ns then I always get
E[Nt] = Ns/0.1 + 9.
 A: The likelihood function of your observation that $10$ trials out of an
unknown $n$ trials resulted in a success is
$$L(n; 10, 0.1) = \binom{n}{10}(0.1)^{10}(0.9)^{n-10}, ~ n = 10, 11, 12, \ldots $$
To find the value of $n$ for which this likelihood function has maximum
value, look at the ratio
$$\frac{L(n+1; 10, 0.1)}{L(n; 10, 0.1)}
= \frac{\binom{n+1}{10}(0.1)^{10}(0.9)^{n+1-10}}{\binom{n}{10}(0.1)^{10}(0.9)^{n-10}} = \frac{n+1}{n-9}0.9$$
which is 


*

*Larger than $1$ (meaning that 
$L(n+1; 10, 0.1)>L(n; 10, 0.1)$) for $n = 10, 11, \ldots$ as long
as $\displaystyle \frac{n+1}{n-9}0.9 > 1$, that is, 
$n < 99$.

*Equal to $1$ (meaning that $L(n+1; 10, 0.1)= L(n; 10, 0.1)$)
if $n = 99$.  
and


*

*Smaller than $1$ (meaning that 
$L(n+1; 10, 0.1)<L(n; 10, 0.1)$) for $n \geq 100$.


So, the likelihood function has two maxima
(twin peaks, in fact), at $99$ and $100$
and either could be taken as the maximum-likelihood estimate
of $n$.

There is nothing Bayesian about all of the above. Let us suppose
that the number of trials is $N$, 
an _ integer-valued random variable_ with probability mass
function (pmf) $p_N(n), n = 0, 1, \ldots$. We do not make any
assumptions about this (prior) pmf except to note that a discrete
random variable with countably infinite support cannot possibly
be uniformly distributed on the support. In this model, the
conditional pmf of the observation $X$ is binomial $(n,p)$: 
$$p_{X\mid N}(k \mid n) = P\{X = k \mid N = n\} 
= \binom{n}{k} p^k(1-p)^{n-k}, k = 0, 1, \ldots n, \tag{1}$$
and the joint distribution of $X$ and $N$ is
$$p_{X,N}(k,n) = p_{N}(n)\binom{n}{k} p^k(1-p)^{n-k}, k = 0, 1, \ldots n, n = k, k+1, \ldots \tag{2}$$
From this we can determine the marginal pmf $p_X(k)$ and get that
the posterior pmf of $N$ given that the event $\{X=k\}$ has occurred
is
$$p_{N\mid X}(n\mid k) = \frac{p_N(n)\binom{n}{k} p^k(1-p)^{n-k}}{p_X(k)} = \frac{p_N(n)}{p_X(k)} \binom{n}{k} p^k(1-p)^{n-k},
n = k, k+1, \ldots\tag{3}$$
Now, the nonBayesian part comes about with the insistence that
$p_{N\mid X}(n\mid k)$ must be of the form
$$p_{N\mid X}(n\mid k) = M\binom{n}{k} p^k(1-p)^{n-k},
n = k, k+1, \ldots\tag{4}$$
where $M$ is a constant instead of being a function of $n$
as in $(3)$. That is, we ignore any prior information about the
distribution of $N$ that we might have, or the model etc and
simply insist that $(4)$ holds.
So, what is the pmf in $(4)$?  Well, if $Y$ is a negative
binomial random variable with parameters $(k+1,p)$,
then its pmf is
$$p_Y(m) = \binom{m-1}{k}p^{k+1}(1-p)^{m-(k+1)}, ~ m = k+1, k+2, \ldots$$
and the pmf of $Y-1$, which takes on values $k, k+1, \ldots$ is
\begin{align}
p_{Y-1}(n) &= p_Y(n+1)\\
&= p\cdot \binom{n}{k}p^k(1-p)^{n-k}, ~ n = k, k+1, \ldots \tag{5}
\end{align}
that is, $M$ in $(4)$ has value $p$.
Consequently, the conditional mean of $N$ given that $X = k$
is
$$E[N\mid X = k] = E[Y-1] = \frac{k+1}{p}-1 = \frac kp + \frac{1-p}{p}.$$
When $p = 0.1$, we have that 
$$E[N\mid X = k] = \frac{k}{0.1} + \frac{0.9}{0.1}
= \frac{k}{0.1} + 9.$$
In the revised version of the problem, the OP confesses that he
has determined that
E[Nt] = Ns/0.1 + 9 which matches the above answer
perfectly.  But, there is no Bayesian inconsistency here. Eq. $(4)$
is not the posterior distribution of $N$ that any Bayesian would find,
and $\frac{k}{0.1} + 9$ is not the mean of the posterior distribution
of $N$: it is the mean of the distribution of $Y-1$ as given in $(5)$.
A: For the binomial distribution the $n$ is usually fixed, but in your example it is the variable of interest, so things need to be treated differently from common examples (things that can be dropped as constants in regular binomial cases cannot be dropped in your case).
The negative binomial distribution seems a little more appropriate her (though it may not be, since it is answering a little bit of a different question).
We really need to see how you coded your likelihood and what prior you used to be able to help more.
A: I think I now understand this. My distribution is skewed, so I knew my expectation would not be the same as my mode. The thing that confused me was that the implication was that if I had 1000 experiments that each measured 10 particles then on average there would have been 109 trials, and in total 109,000 trials. This was at odds with the situation where I had a single experiment which measured 10,000 successes which would indicate that there had been 10,009 trials.
The discrepancy occurs because the first case assumes 1000 independent experiments. If however I put the posterior function from the first trial in as the prior for the next trial, then put the posterior from this trial in again as the prior for the next, etc, then I get the result I expect for the 10,000 success trial. The issue here is that the first case assumes that for each trial we restart again with no knowledge, whereas the second case the knowledge increases with each success.
