No, that would look at the mean of value - time. You need to convert to wide
format and use both of the resulting value columns (this _is_ wht the current
example does). Or do the splitting explicitly, as in
> data_long <- data.frame(
+ value = c(10, 12, 15, 8, 9, 11),
+ time = factor(rep(c("before", "after"), each = 3))
+ )
> groups <- with(data_long, split(value, time))
> t.test(groups$before, groups$after, paired=TRUE)
> On 4 Nov 2025, at 18.39, Petr Pikal <[email protected]> wrote:
>
> Hallo
>
> According to recent documentation this works for paired t.test.
> t.test(Pair(value,time)~1, data=data_long)
>
> It is the last example in help page.
>
> And your second question seems to be also different from what help page
> says:
>
> If paired is TRUE then both x and y must be specified and they must be the
> same length. Missing values are silently removed (in pairs if paired is TRUE
> ).
>
> Cheers.
> Petr
>
>
> Ășt 4. 11. 2025 v 18:23 odesĂlatel Robert Baer via R-help <
> [email protected]> napsal:
>
>> Hi all,
>>
>> Did the behavior of base t.test() subtly change with respect to the
>> paired argument?
>>
>> I think this code used to work with long form data, but now it seems not
>> to work:
>>
>> # Example long format data
>> data_long <- data.frame(
>> value = c(10, 12, 15, 8, 9, 11),
>> time = factor(rep(c("before", "after"), each = 3))
>> )
>>
>> t.test(value ~ time, data = data_long, paired = TRUE)
>>
>> # Errorin t.test.formula(value ~ time, data = data_long, paired = TRUE)
>> : # cannot use 'paired' in formula method
>>
>> A quick Google seems to suggest that the above code should still work.
>> What am I missing?
>>
>> -------------------------------
>>
>> Less sure about this one ...
>>
>> Also, I thought it had always been possible to use x = "difference
>> scores" in t.test(..., paired = TRUE) as long as y = NULL. My memory
>> about this is less secure than the behavior above.
>>
>> Control = c(10, 12, 15) Treat = c(8, 9, 11) data_wide <- data.frame(
>> Control, Treat, Diff = Treat - Control) t.test(data_wide$Diff, NULL,
>> "two.sided", 0, paired = FALSE) # works but y = NULL, mu = 0 mostly
>> implies difference scores
>>
>> t.test(data_wide$Diff, NULL, "two.sided", 0, paired = TRUE) # fails but
>> if y = NULL the value of paired should not matter should it?
>>
>> For y, help says "y an optional (non-empty) numeric vector of data
>> values". I take this to imply that x = compared to a population mean
>> hypothesis whenever y = NULL. Why should the value of paired influence
>> the outcome?
>>
>> Just bad memory on my part?
>>
>> R.version _ platform x86_64-w64-mingw32 arch x86_64 os mingw32 crt ucrt
>> system x86_64, mingw32 status major 4 minor 5.1 year 2025 month 06 day
>> 13 svn rev 88306 language R version.string R version 4.5.1 (2025-06-13
>> ucrt) nickname Great Square Root
>>
>>
>> --
>> ---
>> Robert W. Baer, Ph.D.
>> Professor of Physiology
>> Kirksville College of Osteopathic Medicine
>> A.T. Still Univerisity of Health Sciences
>> 800 W. Jefferson St.
>> Kirksville, MO 63501
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [email protected] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> https://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [email protected] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: [email protected] Priv: [email protected]
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.