Likelihood of latent variables in hierarchical model for model comparison

Thanks for getting back to me on this!

I want the log-likelihood of each x_s to be calculated as \textrm{logp}(x_s | \mu_0)+\sum{\textrm{logp}(x_i|x_s)} where the sum is taken over the data points belonging to group s.

You can see me trying to calculate the likelihood of x_s given mu_0 in the line:
ll_xs = stats.norm(mu0, xs_sigma).logpdf(xs)

and the likelihood of the sum in the line:
ll_x[c,d,s] = stats.norm(xs[c, d, s], x_sigma[c, d, s]).logpdf(x_subj[s]).sum()

I then add them together using:
ll = ll_xs + ll_x

Is that clearer?