Expected value of random sum of random variables In example 3.2.2 of the book "An Introduction to Stochastic Processes" by Kao, the following statement is presented. Why are $X_i$ and $N(t)$ dependent? I would be thankful if you can clarify the procedure to determine $E[S_N]$.
If $\{X_i\}$ are identically distributed random variables with a common mean $\mu$, and $N$ is independent of $\{X_i\}$, then we know that $E[S_N]=E[X]E[N]$, where $S_N=X_1+X_2+⋯+X_N$. In a renewal process, we see that $S_N(t)=X_1+⋯+X_N(t)$ denotes the time of the last renewal before t. Unfortunately, it is not true that $E[S_N(t)]=E[X]E[N(t)]$ because $N(t)$ depends on $\{X_i\}$ (I cannot understand the difference with the former case). However, the following related result holds:
$$E[S_{N(t)+1}]=E[X](M(t)+1).$$
I cannot understand the difference between two cases and how to determine which formula is appropriate to use.
 A: Let $X_i \sim \mathsf{Norm}(\mu=50, \sigma=10),$ and independently
let $N \sim \mathsf{Pois}(\lambda=10).$ Then $S_N = \sum_{i=1}^N X_i.$
set.seed(1114)
s.n = replicate(10^6,  sum(rnorm(rpois(1,10), 50, 10)))
summary(s.n);  var(s.n)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    0.0   386.1   490.9   500.0   604.1  1575.3 
[1] 26049.51

An exact value of $E(S_N) = E(X_i)E(N) = 50(10) = 500,$ simulated above as $500.0.$
The value of $Var(S_N)$ has squared units and so is not quite so precisely
estimated in the simulation.
$Var(S_N) = E(N)Var(X_i)+[E(X_i)]^2Var(N) = 26000.$
See these notes for a proof.
A: In the first model, $N$ is a nonnegative integer-valued random variable that is independent of the identically distributed random variables $X_1, X_2, \ldots$ with common mean $E[X]$. $S_N$ is defined as $\sum_{i=1}^N X_i$ (note that $S_N=0$ when $N=0$) and  we wish to find $E[S_N]$. Note that
$$E\left[S_N\,\big\vert\, N=n\right]= E\left[\sum_{i=1}^N X_i \,\bigg\vert\, N=n\right] = E\left[ \sum_{i=1}^n X_i\right]
= nE[X].\tag{1}$$ Hence,
\begin{align}
E[S_N]  &= \sum_{n=0}^\infty P(N=n)\cdot E\left[S_N\,\big\vert\, N=n\right]\\
&= \sum_{n=0}^\infty P(N=n) \cdot nE[X]\\
&= E[X]\sum_{n=0}^\infty P(N=n) \cdot n\\
&=E[X]\cdot E[N]
\end{align}
exactly as the OP claimed.
In the second model, the $X_i$ are i.i.d. strictly positive continuous random variables representing inter-arrival times. That is, the first arrival after $t=0$ is at time $X_1$, the second arrival is at time $X_1+X_2$, the third arrival is at time $X_1+X_2+X_3$, and so on.  Now, for any fixed time $t$, $N(t)$ is defined as the number of arrivals in the time interval $(0,t]$. Thus, $N(t)$ is a nonnegative integer-valued random variable just as $N$ was in the previous model, but $N(t)$ and the $X_i$ are no longer independent random variables. Note, for example, that conditioned on $N(t) = n$, we immediately have that the conditional density of $X_1, X_2, \cdots, X_n$ is nonzero only in the region bounded by the hyperplane $X_1+X_2+\cdots+X_n \leq t$. A little thought reveals that we must also insist on $X_{n+1} > t-(X_1+X_2+\cdots+X_n)$ to ensure that there are exactly $n$ arrivals in $(0,t]$. Thus, computation of $E\left[S_{N(t)}\,\big\vert\, N(t)=n\right]$ is not as easy as the computation of  $E\left[S_N\,\big\vert\, N=n\right]$ in $(1)$ where the independence of the $X_i$ and $N$ made life a lot easier: here, the $X_i$ are definitely not independent of the value of $N(t)$.
