Ejemplo n.º 1
0
/*
Credible interval for difference between binomial proportions, approximated by Normal distribution
Bolstad 2007 (2e): 248, eq. 13.13
post_diff_mu = binom_diff_prop_norm_approx_mu()
post_diff_sigma = sqrt(binom_diff_prop_norm_approx_var())
untested ...
*/
func BinomDiffPropCrI(post_diff_mu, post_diff_sigma, alpha float64) (float64, float64) {
	/*
		post_diff_mu		posterior mean for difference of normal means
		post_diff_sigma	posterior standard deviation for difference of normal means
		alpha			posterior probability that the true mean lies outside the credible interval
	*/

	var z float64

	z = s.ZInv_CDF_For(alpha / 2)

	low = post_diff_mu - z*post_diff_sigma
	high = post_diff_mu + z*post_diff_sigma
	return low, high
}
Ejemplo n.º 2
0
func BinomBetaPriCrIApprox(α, β, alpha float64, n, k int64) (float64, float64) {
	/*
		k			observed successes
		n			total number of observations
		a			beta prior a
		b			beta prior b
		alpha			posterior probability that the true proportion lies outside the credible interval
	*/

	var post_mean, post_var, post_α, post_β, z, low, upp float64

	post_α = α + float64(k)
	post_β = β + float64(n-k)

	post_mean = post_α / (post_α + post_β)
	post_var = (post_α * post_β) / ((post_α + post_β) * (post_α + post_β) * (post_α + post_β + 1.0))
	z = s.ZInv_CDF_For(alpha / 2)

	low = post_mean - z*math.Sqrt(post_var)
	upp = post_mean + z*math.Sqrt(post_var)
	return low, upp
}