PSA: Sufficient-Stats for Gaussian Likelihoods should speed up most Hierarchical models with IID observation subgroups

Minor update: I worked out the appropriate jacobian correction necessary to use the chi-square rather than gamma distribution for the variance, which achieves a further 1.2x-1.3x speedup:

And here’s the code for the chi-square likelihood:

	target += (
		normal_lupdf(
			obs_mean
			| pop_mean[one_thru_k]
			, pop_sd[one_thru_k]./sqrt_n
		)
		+ (
			(
				chi_square_lupdf(
					obs_var ./ pow(pop_sd[one_thru_k],2)
					| 1
				)
				- 2*sum(log(pop_sd[one_thru_k]))
			)
			* k_minus_one
		)
	)  ;