From m@tt@n@b @end|ng |rom m@b@t@t@@|n|o  Tue Nov  7 01:21:04 2023
From: m@tt@n@b @end|ng |rom m@b@t@t@@|n|o (Mattan S. Ben-Shachar)
Date: Tue, 7 Nov 2023 02:21:04 +0200
Subject: [Rd] Inconsistency in paired t.test() interface?
Message-ID: <CAEVroTNaQ+nTcccJJSkc+5qfJx9sOFxtwP9vZ=kaQ53yjUXTQA@mail.gmail.com>

Hi all,

In the next release of R (4.4) the option to obtain a paired t.test with
the formula interface for "long" data has been removed:

t.test(x ~ group, paired = TRUE) # now results in an error.

Exploring how one might obtain a paired t.test, there seems to be some
inconsistency between the formula and default interfaces as well as within
the formula interface.

```
extra.1 <- c(0.7, -1.6, -0.2, -1.2, -0.1, 3.4, 3.7, 0.8, 0, 2)
extra.2 <- c(1.9, 0.8, 1.1, 0.1, -0.1, 4.4, 5.5, 1.6, 4.6, 3.4)
group <- rep(letters[1:2], each = 5)


t.test(Pair(extra.1, extra.2) ~ 1) # Paired t.test

t.test(Pair(extra.1, extra.2)) # NOT a paired t.test - this is actually a
one sample t-test

t.test(c(extra.1, extra.2))  # it is actually the same as combining the
vectors

# likewise, these two are the same:
t.test(Pair(extra.1, extra.2), Pair(extra.1, extra.2))
t.test(c(extra.1, extra.2), c(extra.1, extra.2))


t.test(Pair(extra.1, extra.2) ~ group) # This gives a two-sample test? (I
would expect it to fail)

t.test(c(extra.1, extra.2) ~ c(group, group))  # is once again the same as
combining the vectors:
```

The docs do say:
> If lhs is of class "Pair" and rhs is 1, a paired test is done.
But I would have expected a Pair object to behave similarly outside a
formula as well,
that is - I would have expected a `Pair` object to result in a paired
t-test (and not accept a `y` argument, or ignore it),
and for a formula `Pair(x, y) ~ group` to throw an error.

(This behavior is also found in wilcox.test())


My mental model expects the default and formula methods to be consitant, so
that these and only these would work:
- One sample:
  - `x` is a vector, `y` is `NULL`
  - `x ~ 1` formula
- Paired sample
  - `x,y` are numeric vectors + `paired = TRUE`
  - `x` is a `Pair` object (`y` is ignored)
  - `Pair(x,y) ~ 1` formula
- Two Samples
  - `x,y` are nueric vectors (`paired = FALSE`)
  - `x ~ group` formula

Any pointers on where my mental model is going wrong?



Thanks,
Mattan

	[[alternative HTML version deleted]]



[Rd] Inconsistency in paired t.test() interface?
Mattan S. Ben-Shachar