bf_ttest: Bayes Factor for _t_-test and one-way ANOVA

Description Usage Arguments Details See Also Examples

View source: R/bf_ttest.R

Description

Bayes Factor for t-test and one-way ANOVA

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
bf_ttest(
  data,
  x,
  y = NULL,
  subject.id = NULL,
  paired = FALSE,
  test.value = 0,
  bf.prior = 0.707,
  ...
)

bf_oneway_anova(
  data,
  x,
  y = NULL,
  subject.id = NULL,
  paired = FALSE,
  test.value = 0,
  bf.prior = 0.707,
  ...
)

Arguments

data

A dataframe (or a tibble) from which variables specified are to be taken. A matrix or a table will not be accepted.

x

Either the grouping variable from the dataframe data if it's a two-sample t-test or a numeric variable if it's a one-sample t-test.

y

The column in data containing the response (outcome) variable to be plotted on the y-axis. Can be entered either as a character string (e.g., "y") or as a bare expression (e.g, y).

subject.id

Relevant in case of repeated measures design (paired = TRUE, i.e.), it specifies the subject or repeated measures identifier. Important: Note that if this argument is NULL (which is the default), the function assumes that the data has already been sorted by such an id by the user and creates an internal identifier. So if your data is not sorted and you leave this argument unspecified, the results can be inaccurate.

paired

Logical that decides whether the experimental design is repeated measures/within-subjects or between-subjects. The default is FALSE.

test.value

A number specifying the value of the null hypothesis (Default: 0).

bf.prior

A number between 0.5 and 2 (default 0.707), the prior width to use in calculating Bayes factors.

...

Arguments passed on to bf_extractor

conf.level

Confidence/Credible Interval (CI) level. Default to 0.95 (95%).

centrality

The point-estimates (centrality indices) to compute. Character (vector) or list with one or more of these options: "median", "mean", "MAP" or "all".

conf.method

The type of index used for Credible Interval. Can be "hdi" (default), "eti", or "si" (see si(), hdi(), eti() functions from bayestestR package).

k

Number of digits after decimal point (should be an integer) (Default: k = 2L).

top.text

Text to display on top of the Bayes Factor message. This is mostly relevant in the context of ggstatsplot functions.

output

If "expression", will return expression with statistical details, while "dataframe" will return a dataframe containing the results.

Details

If y is NULL, a one-sample t-test will be carried out, otherwise a two-sample t-test will be carried out.

See Also

bf_contingency_tab, bf_corr_test, bf_oneway_anova

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# for reproducibility
set.seed(123)
library(tidyBF)

# ----------------------- one-way ANOVA -----------------------------------

# to get dataframe (between-subjects)
bf_oneway_anova(
  data = iris,
  x = Species,
  y = Sepal.Length,
  bf.prior = 0.8,
  output = "dataframe"
)

# to get expression (within-subjects) (needs `BayesFactor 0.9.12-4.3` or above)
if (utils::packageVersion("BayesFactor") >= package_version("0.9.12-4.3")) {
  bf_oneway_anova(
    data = bugs_long,
    x = condition,
    y = desire,
    subject.id = subject,
    paired = TRUE,
    output = "expression"
  )
}

# ------------------- two-samples tests -----------------------------------

# to get dataframe (between-subjects)
bf_ttest(
  data = mtcars,
  x = am,
  y = wt,
  paired = FALSE,
  bf.prior = 0.880,
  output = "dataframe"
)

# to get expression (within-subjects)
bf_ttest(
  data = dplyr::filter(bugs_long, condition %in% c("LDLF", "LDHF")),
  x = condition,
  y = desire,
  subject.id = subject,
  paired = TRUE,
  bf.prior = 0.880,
  output = "dataframe"
)

# ------------------- one-samples test -----------------------------------

# to get expression
bf_ttest(
  data = iris,
  x = Sepal.Length,
  test.value = 5.85,
  output = "expression"
)

tidyBF documentation built on June 12, 2021, 9:06 a.m.