Home > front end >  how to fix the problem with strange error codes from t test
how to fix the problem with strange error codes from t test

Time:01-27

I have a df and I would like to run a ttest on it, however I keep getting error codes which I don't think make senesce. Could anyone take a look and see what might be the problem?

df<-structure(list(Order1 = c(0, 6, 6, 0, 6, 0, 0, 6, 6, 0, 6, 0), 
    AVAL = c(133, 116, 123, 137, 266, 244, 483, 443, 219, 265, 
    202, 197), ID = c("109", "109", "110", "110", "111", "111", 
    "113", "113", "114", "114", "115", "115")), row.names = c(NA, 
-12L), class = c("tbl_df", "tbl", "data.frame"))

library(lsr)

pairedSamplesTTest( formula= AVAL ~ Order1   (ID), data=df )

The error code that I got is: enter image description here

CodePudding user response:

We may need to convert the tibble to data.frame. According to the documentation

data - Optional data frame containing the variables.

pairedSamplesTTest( formula= AVAL ~ Order1   (ID), data=as.data.frame(df) )
  Paired samples t-test 

Outcome variable:   AVAL 
Grouping variable:  Order1 
ID variable:        ID 

Descriptive statistics: 
                  0       6 difference
   mean     243.167 228.167     15.000
   std dev. 129.257 119.996     25.923

Hypotheses: 
   null:        population means equal for both measurements
   alternative: different population means for each measurement

Test results: 
   t-statistic:  1.417 
   degrees of freedom:  5 
   p-value:  0.216 

Other information: 
   two-sided 95% confidence interval:  [-12.204, 42.204] 
   estimated effect size (Cohen's d):  0.579 

Warning messages:
1: In pairedSamplesTTest(formula = AVAL ~ Order1   (ID), data = as.data.frame(df)) :
  group variable is not a factor
2: In pairedSamplesTTest(formula = AVAL ~ Order1   (ID), data = as.data.frame(df)) :
  id variable is not a factor

NOTE: Also, make sure to convert the group variable and id to factor to remove the warnings


was able to reproduce the same error in the OP's post when used lsr version 0.5.2

> pairedSamplesTTest( formula= AVAL ~ Order1   (ID), data=df )
Error in pairedSamplesTTest(formula = AVAL ~ Order1   (ID), data = df) : 
  outcome variable must be numeric
  •  Tags:  
  • Related