Documentation ¶
Overview ¶
Package waldo performs basic two-sided statistical hypothesis testing for scalar parameter estimates using the Wald test.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StandardError ¶
StandardError computes an estimate for the standard error of a point estimator, as encoded in a Sample. The standard error is the standard deviation of the estimator's distribution. SInce the variance of this distribution is estimated, hence the overall calculation itself is an estimate.
Types ¶
type BernoulliSample ¶
BernoulliSample represents an IID sample drawn from a Bernoulli distribution with some unknown success probability p. Some examples include a series of weighted coin flips or clickthrough data for a campaign. An BernoulliSample instance can be created either from a slice of data or a count of successes together with the number of trials.
func (BernoulliSample) Estimator ¶
func (s BernoulliSample) Estimator() float64
MLE estimate for the underlying success probability. MLE computes the maximum likelihood estimator (MLE) estimate from the sample. If X := sum_{i=1}^n X_i, where X_i are iid from a Bernoulli distribution with unknown parameter p, then the MLE (as a function) is simply (1/m)X, where m is the size of the sample.
func (BernoulliSample) Variance ¶
func (s BernoulliSample) Variance() float64
type PairedComparison ¶
type PairedComparison struct {
Size float64
}
PairedComparisonTest is a Wald Hypothesis test of the specified size for paired sample data.
func (PairedComparison) Test ¶
func (t PairedComparison) Test(pairedSample Sample) Result
type PairedSample ¶
PairedSample represents data used to determine whether the parameter estimates for the random variables X and Y agree. A typical use-case is to determine whether two Bernoulli samples {X, Y} are drawn from the same distribution.
As a random variable, a paired sample represents Z := X - Y.
func (PairedSample) Estimator ¶
func (s PairedSample) Estimator() float64
Estimator for the comparison estimator hat(p) := X.Estimator - Y.Estimator
func (PairedSample) Variance ¶
func (s PairedSample) Variance() float64
Variance for a PairedSample is the sum of the individual variances. This follows from the fact that the variance operator is additive over independent variables, which X and Y are presumed to be, and scalars factor out as their squares. That is, if V is the variance operator, then V(X-Y) = V(X) + V(-Y) = V(X) + (-1)^{2}V(Y).
type Result ¶
type Result struct { // Confidence interval for the sample parameter estimate computed at // the same level as the size of the test. ConfidenceInterval []float64 // The confidence level is 1- the size of the Wald test that produced the result. ConfidenceLevel float64 Power float64 PValue float64 RejectNull bool Statistic float64 Size float64 NullValue float64 }
Results is a container for the result of performing a Wald test over some sample of data.
func PairedComparisonTest ¶
PairedComparisonTest performs a Wald comparison test of the specified size for the paired data (X, Y). It wraps PairedComparison.Test.
Example ¶
size := 0.05 X := BernoulliSample{103, 200} Y := BernoulliSample{110, 200} fmt.Printf("%#v", PairedComparisonTest(X, Y, size))
Output: waldo.Result{ConfidenceInterval:[]float64{-0.1327305906069241, 0.06273059060692406}, ConfidenceLevel:0.95, Power:0.10807314041617873, PValue:0.482731935542819, RejectNull:false, Statistic:-0.7019153324868983, Size:0.05, NullValue:0}
type Sample ¶
Sample represents data drawn from some distribution. To compute the Wald statistics we need to have a point estimator function (e.g., the maximum likelihood estimator (MLE)) as well as the sampling distribution's variance. Recall that the sampling distribution is defined as the distribution of the point estimator.
The estimator in question should be asymptotically normal, which is to say that the difference between the estimator (as a random variable of the data size) and the parameter being estimated over the standard error of the estimator converges in distribution to a standard normal distribution.
type Wald ¶
Wald is a simple two-sided statistical hypothesis test for a scalar parameter theta. It tests H_0: theta = null vs. H_1: theta != null, under the assumption that the estimator for theta is asymptotically normal. Asymptotic normality is met by Bernoulli trials with the maximum likelihood estimator, for instance. A Wald test with Size S has a confidence level of 1 - S.
func (Wald) ConfidenceInterval ¶
func (Wald) Power ¶
Power function estimate. The power is the probability of correctly rejecting the null hypothesis.
func (Wald) RejectNull ¶
func (Wald) Test ¶
Perform a Wald test on a sample of data.
Example (Bernoulli) ¶
data := BernoulliSample{Successes: 35, Trials: 40} wald := Wald{Size: 0.05, NullValue: 0.5} fmt.Printf("%#v", wald.Test(data))
Output: waldo.Result{ConfidenceInterval:[]float64{0.7725112383996421, 0.9774887616003579}, ConfidenceLevel:0.95, Power:0.999999906295462, PValue:7.425001949510999e-13, RejectNull:true, Statistic:7.171371656006362, Size:0.05, NullValue:0.5}