0

For example, right now, I have to key in the t.test one at a time for each independent variables.

t.test(Age~composite_renal_march2020,data = DN_DKK3,var.equal=TRUE)

t.test(HbA1c~composite_renal_march2020,data = DN_DKK3,var.equal=TRUE)

I tried to pipe the following code to try to run t.test for the 2 variables simultaneously:

DN_DKK3 %>% 
  select(-SampleID) %>% 
  group_by(Age, HbA1c) %>% 
  t.test(~composite_renal_march2020, var.equal = TRUE)

However, the pipe code kept giving me this error message:

Error in vec_c(): ! Can't combine composite_renal_march2020 and RetinopathyGrade13 . Run rlang::last_trace() to see where the error occurred.


Backtrace: ▆

  1. ├─... %>% t.test(~composite_renal_march2020, var.equal = TRUE)
  2. ├─stats::t.test(., ~composite_renal_march2020, var.equal = TRUE)
  3. └─stats:::t.test.default(., ~composite_renal_march2020, var.equal = TRUE)
  4. ├─x[xok]
  5. ├─dplyr:::[.grouped_df(x, xok)
  6. ├─base::NextMethod()
  7. └─tibble:::[.tbl_df(x, xok)
  8. └─tibble:::tbl_subset_matrix(x, j, j_arg)
    
  9.   ├─base::unname(vec_c(!!!values, .name_spec = ~.x))
    
  10.   └─vctrs::vec_c(!!!values, .name_spec = ~.x)
    

Warning message: In is.na(y) : is.na() applied to non-(list or vector) of type 'language'

I am stuck on how to solve this error message... hope to get some advice here. Thank you all so much!

UseR10085
  • 7,120
  • 3
  • 24
  • 54
Janus Lee
  • 1
  • 1
  • Please provide some data to make the code reproducible. Please visit [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – UseR10085 Jul 28 '23 at 03:53
  • 2
    Surely this has been asked and answered multiple times. You are expected to do a good faith search, show what you found, tried and say why it was unsuccessful. – IRTFM Jul 28 '23 at 04:00
  • if you have R version 4.3 and above, you could use `SLR::multiple_tests` function. You could install the package from github ie `devtools::install_github('oonyambu/SLR')` I am not sure. You could google – Onyambu Jul 28 '23 at 05:07
  • `SLR::multiple_tests(.~composite_renal_march2020|Age + HbA1c, subset(data, , -SampleID)` with the default being `t.test` – Onyambu Jul 28 '23 at 05:10

1 Answers1

0

I'm not sure if I fully understand your question. But maybe you could do something like this:

data(mtcars)
# for selecting variables for testing
vars <- colnames(mtcars)[1:ncol(mtcars) - 1]

cl <- parallel::makeCluster(2)
# Test everything against 'am '
res <- pbapply::pblapply(vars, function(x) t.test(mtcars[x], mtcars$am), cl = cl)

I am assuming that you want to test a number of variables against the same variable. This allows you to do just that and even in parallel depending on the number of corse you have you can change 2 in whatever works for you.

res will be a list where each entry is the output of a single t.test()

I hope this helps, if not please let me know and I'll try to help.

Joan
  • 30
  • 4