コード例 #1
0
// NormPostSimNoPrior returns a simulated sample from the joint posterior distribution of the mean and variance for a normal
// sampling prior.
func NormPostSimNoPrior(data []float64, m int) (postMu, postS2 []float64) {
	// Arguments:
	// data - vector of observations
	// m - number of simulations desired
	// Returns:
	// mu - vector of simulated draws of normal mean
	// sigma2 - vector of simulated draws of normal variance

	xbar := mean(data)
	n := len(data)
	diff2 := make([]float64, n)

	for i, val := range data {
		diff2[i] = (val - xbar) * (val - xbar)
	}

	s := sum(diff2)
	postS2 = make([]float64, m)
	postMu = make([]float64, m)

	for i, _ := range postMu {
		postS2[i] = s / dst.ChiSquareNext(int64(n)-1)
		sd := sqrt(postS2[i]) / sqrt(float64(n))
		postMu[i] = dst.NormalNext(xbar, sd)
	}
	return
}
コード例 #2
0
// NormPostNoPriorNext returns a  sampled tuple from the joint posterior distribution of the mean and variance for a normal
// sampling prior.
func NormPostNoPriorNext(data []float64) (postMu, postS2 float64) {
	// Arguments:
	// data - vector of observations
	// Returns:
	// postMu -  simulated draw of normal mean
	// postS2 -  simulated draw of normal variance

	xbar := mean(data)
	n := len(data)
	diff2 := make([]float64, n)

	for i, val := range data {
		diff2[i] = (val - xbar) * (val - xbar)
	}

	s := sum(diff2)
	postS2 = s / dst.ChiSquareNext(int64(n)-1)
	sd := sqrt(postS2) / sqrt(float64(n))
	postMu = dst.NormalNext(xbar, sd)
	return
}