Tests for a difference in means from two normally distributed variates with possibly different variances.
bfTest(x, ...)# S3 method for default
bfTest(x, y,
alternative = c("two.sided", "less", "greater"),
mu = 0, conf.level = 0.95, control=bfControl(), ...)
# S3 method for formula
bfTest(formula, data, subset, na.action, ...)
A list with class "htest"
containing the following components:
the value of the t-statistic.
R = atan(SEMx/SEMy)
used in Behrens-Fisher distribution,
where SEMx=std error of the mean of x, see pbf
, but not used in calculation for this function
the p-value for the test.
a confidence interval for the difference in means (mean.x-mean.y) appropriate to the specified alternative hypothesis.
the estimated means
the specified hypothesized value of the mean difference
a character string describing the alternative hypothesis.
a character string describing the test.
a character string giving the name(s) of the data.
a (non-empty) numeric vector of data values.
an optional (non-empty) numeric vector of data values.
a character string specifying the alternative
hypothesis, must be one of "two.sided"
(default),
"greater"
or "less"
. You can specify just the initial
letter.
a number indicating the true value of the difference in means
confidence level of the interval.
a list of arguments used for determining the calculation algorithm, see bfControl
a formula of the form lhs ~ rhs
where lhs
is a numeric variable giving the data values and rhs
a factor
with two levels giving the corresponding groups.
an optional matrix or data frame (or similar: see
model.frame
) containing the variables in the
formula formula
. By default the variables are taken from
environment(formula)
.
an optional vector specifying a subset of observations to be used.
a function which indicates what should happen when
the data contain NA
s. Defaults to
getOption("na.action")
.
further arguments to be passed to or from methods.
Fisher (1935) developed a fiducial solution to the two-sample difference in means problem with normally distributed data with different variances. That has become known as the Behrens-Fisher solution. Robinson (1976) showed through extensive simulations, that the Behrens-Fisher solution is valid (i.e., the test gives type I error rate less than the significance level, and its confidence intervals on the difference in means have coverage at least as large as the nominal confidence level).
The following are the same as with the usual t-test in t.test
.
alternative = "greater"
is the alternative that x
has a
larger mean than y
. Missing values are silently removed. If the input data are effectively constant an error is generated.
Fisher, RA (1935). The fiducial argument in statistical inference. Annals of Eugenics. 6, 391-398.
Robinson, G (1976). Properties of Students t and of the Behrens-Fisher solution to the two means problem. The Annals of Statistics 4, 963-971 (Corr: 1982, p. 321).
The more common solution for this problem is Welch's t-test (the default in t.test
). Welch's t-test does not guarantee that the type I error rate is less than the significance level, but it appears to work well in most cases.
## Classical example: Student's sleep data
## Traditional interface
with(sleep, bfTest(extra[group == 1], extra[group == 2]))
## Formula interface
bfTest(extra ~ group, data = sleep)
## Results are simular to Welch's t-test,
## but a little more conservative
t.test(extra~group,data=sleep)
Run the code above in your browser using DataLab