Paired Sample T test: keeps complaining outcome (int) variable is not numeric

Hello! Tried running pairedsampleTtest() with a df of 4 columns (ID, scoreT1, scoreT2, Group); scoreT1 & scoreT2 are outcome variables and are confirmed as numeric. Yet, the test result showed error message of 'scoreT2' is not numeric'. What did i do wrong? Thanks!!

amytest

A tibble: 10 x 4

ID scoreT1 scoreT2 Group

1 ID_001 3 5 1
2 ID_002 2 6 1
3 ID_003 4 8 1
4 ID_004 3 6 1
5 ID_005 2 6 1
6 ID_006 2 3 2
7 ID_007 3 3 2
8 ID_008 2 2 2
9 ID_009 4 3 2
10 ID_010 3 3 2

is.numeric(amytest$scoreT1)
[1] TRUE
is.numeric(amytest$scoreT2)
[1] TRUE
pairedSamplesTTest(formula = ~scoreT2 + scoreT1, data = amytest)
Error in pairedSamplesTTest(formula = ~scoreT2 + scoreT1, data = amytest) :
'scoreT2' is not numeric

Hello @tyamychan ,

I have a lot of packages installed, but I could not find the function pairedSamplesTTest .
So it would help if you indicate to which package this function belongs.
You also can check yourself if you use the proper syntax for this function by typing

?pairedSamplesTTest

in the R console.

As a last remark: always try to make it as easy as possible for forum members to recreate your issue.
You can do this by specifying the code that is necessary to create the input data(sets). In your case:

library(tibble)

amytest <- tribble(
~ID, ~scoreT1, ~scoreT2, ~Group,

"ID_001",  3,  5,  1, 
"ID_002",  2,  6,  1, 
"ID_003",  4,  8,  1, 
"ID_004",  3,  6,  1, 
"ID_005",  2,  6,  1, 
"ID_006",  2,  3,  2, 
"ID_007",  3,  3,  2, 
"ID_008",  2,  2,  2, 
"ID_009",  4,  3,  2, 
"ID_010",  3,  3,  2, 
)

Thank you HanOostdijk! Thanks for the suggestion, sorry that it's my first time using the forum,
The package is called 'lsr'

I checked the documentation, I should have gotten the arguments right (I even went ahead and provided those 'optional' arguments). But still complains about my scoreT2 is not numeric, but isNumeric() returns TRUE.

Thanks again!

Oh, I just figured out the problem! As I imported the data from Excel, and it's in 'tibble' format by default. I had to convert it to dataFrame using as.data.frame() , then ran the PairedSampleTTest() again. It's working now ^^

Good catch!
Please indicate that you have solved the problem by flagging your last remark as the solution.
This prevents other forum members looking at it, only to notice later that it is already solved.

You could also indicate your problem to the maintainer of the lsr package in
https://github.com/svannoy/lsr-package/issues .
I think it is very easy for him/her to avoid this kind of problems.
Just open a new issue and copy the code below:
(alternatively I could do this, but as you found problem and solution ....
Just let me know.)

library(tibble)
#> Warning: package 'tibble' was built under R version 4.1.2
library(lsr)
#> Warning: package 'lsr' was built under R version 4.1.2

amytest <- tribble(
~ID, ~scoreT1, ~scoreT2, ~Group,

"ID_001",  3,  5,  1, 
"ID_002",  2,  6,  1, 
"ID_003",  4,  8,  1, 
"ID_004",  3,  6,  1, 
"ID_005",  2,  6,  1, 
"ID_006",  2,  3,  2, 
"ID_007",  3,  3,  2, 
"ID_008",  2,  2,  2, 
"ID_009",  4,  3,  2, 
"ID_010",  3,  3,  2, 
)


pairedSamplesTTest( formula = ~scoreT1 + scoreT2,data=amytest)
#> Error in pairedSamplesTTest(formula = ~scoreT1 + scoreT2, data = amytest): 'scoreT1' is not numeric

amytest2 <- as.data.frame(amytest)
pairedSamplesTTest( formula = ~scoreT1 + scoreT2,data=amytest2)
#> 
#>    Paired samples t-test 
#> 
#> Variables:  scoreT1 , scoreT2 
#> 
#> Descriptive statistics: 
#>             scoreT1 scoreT2 difference
#>    mean       2.800   4.500     -1.700
#>    std dev.   0.789   1.958      1.947
#> 
#> Hypotheses: 
#>    null:        population means equal for both measurements
#>    alternative: different population means for each measurement
#> 
#> Test results: 
#>    t-statistic:  -2.762 
#>    degrees of freedom:  9 
#>    p-value:  0.022 
#> 
#> Other information: 
#>    two-sided 95% confidence interval:  [-3.092, -0.308] 
#>    estimated effect size (Cohen's d):  0.873
Created on 2022-02-23 by the reprex package (v2.0.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.