Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Function for Anova_test can't find column OR giving me error

I am trying to run an ANOVA test on my data using this dataframe

df = structure(list(Total_Devices = c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), Tracking_Group = c(Stationary_Acoustic = "Acoustic", 
Stationary_Acoustic = "Acoustic", Stationary_Acoustic = "Acoustic", 
Stationary_Acoustic = "Acoustic", Stationary_Archival = "Archival", 
Stationary_Acoustic = "Acoustic", Stationary_Acoustic = "Acoustic", 
Stationary_Acoustic = "Acoustic", Stationary_Acoustic = "Acoustic", 
Stationary_Radio = "Radio", Stationary_Acoustic = "Acoustic", 
Stationary_Acoustic = "Acoustic", Stationary_Acoustic = "Acoustic", 
Controlled_Acoustic = "Acoustic", Stationary_Archival = "Archival", 
Controlled_Acoustic = "Acoustic", BRUV_Acoustic = "Acoustic", 
Stationary_Acoustic = "Acoustic", Stationary_Acoustic = "Acoustic", 
Animalborne_Acoustic = "Acoustic", Controlled_Acoustic = "Acoustic", 
Animalborne_Archival = "Archival", Stationary_Acoustic = "Acoustic", 
Stationary_Acoustic = "Acoustic", Animalborne_Archival = "Archival", 
BRUV_Acoustic = "Acoustic", Animalborne_Archival = "Archival", 
Animalborne_Archival = "Archival", Animalborne_Archival = "Archival", 
BRUV_Acoustic = "Acoustic", Controlled_Acoustic = "Acoustic", 
Stationary_Satellite = "Satellite", Animalborne_Archival = "Archival", 
Stationary_Acoustic = "Acoustic", Controlled_Acoustic = "Acoustic", 
Animalborne_Archival = "Archival", BRUV_Acoustic = "Acoustic", 
Controlled_Acoustic = "Acoustic", Animalborne_Archival = "Archival", 
Animalborne_Satellite = "Satellite", Animalborne_Archival = "Archival", 
Animalborne_Archival = "Archival", Animalborne_Archival = "Archival", 
Animalborne_Archival = "Archival", Animalborne_Archival = "Archival", 
Controlled_Archival = "Archival", Animalborne_Archival = "Archival", 
Controlled_Acoustic = "Acoustic", Controlled_Satellite = "Satellite", 
Stationary_Acoustic = "Acoustic", Stationary_Archival = "Archival", 
Stationary_PIT = "PIT", Stationary_Radio = "Radio", Stationary_Satellite = "Satellite", 
Stationary_Acoustic_Archival = "Acoustic", Stationary_Acoustic_Archival = "Acoustic", 
Stationary_Acoustic_PIT = "Acoustic", Stationary_Acoustic_Archival = "Acoustic", 
Stationary_Acousitc_PIT = "PIT", BRUV_Acoustic_Satellite = "Acoustic", 
Stationary_Acoustic_Radio = "Acoustic", BRUV_Acoustic_Satellite = "Acoustic", 
Stationary_Radio_PIT = "PIT", Stationary_Acoustic_Archival = "Acoustic", 
Animalborne_Satellite_Archival = "Archival", Animalborne_Acoustic_Archival = "Acoustic", 
Animalborne_Satellite_Archival = "Archival", Animalborne_Satellite_Archival = "Archival", 
Animalborne_Archival_PIT = "PIT"), size_range = c(0.954242509439325, 
1.88874096068289, 1.66745295288995, 0.544068044350276, 0.556302500767287, 
0.845098040014257, 1.56229286445647, 1, 1.3541084391474, 1.83884909073726, 
0.778151250383644, 1.07918124604762, 1.02118929906994, 0.903089986991944, 
0.954242509439325, 0.845098040014257, 1.47712125471966, 1.87794695162919, 
0.301029995663981, 1.7419390777292, 0.690196080028514, 1.75815462196739, 
1.19865708695442, 1.36172783601759, 1.36735592102602, 1.41497334797082, 
1.41830129131975, NA, 1.53147891704226, 1.95424250943932, 1.43933269383026, 
1.7160033436348, 1.97772360528885, NA, 2.21218760440396, 1.99563519459755, 
2.3747483460101, 2.08278537031645, NA, 2.77815125038364, 2.03342375548695, 
1.95424250943932, 1.95424250943932, NA, NA, 4.56110138364906, 
NA, NA, NA, NA, NA, NA, NA, NA, 0.361727836017593, 1.26717172840301, 
0.944482672150168, 1.32221929473392, 1.57749179983723, 2.00860017176192, 
1.00432137378264, 2.52633927738984, 1.38021124171161, 1.34242268082221, 
NA, 2.31175386105575, 2.30102999566398, NA, NA)), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -69L), groups = structure(list(
    Total_Devices = 2:3, .rows = structure(list(1:54, 55:69), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -2L), .drop = TRUE))

I have tried using this code

res <- rstatix::anova_test(data = df,
                 dv = size_range,
                 within = Total_Devices)

but I get this error message

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Error in `mutate()`:
! Problem while computing `data = map(.data$data, .f, ...)`.
Caused by error in `map()`:
ℹ In index: 1.
Caused by error in `.args$data[, model.variables]`:
! Can't subset columns that don't exist.
✖ Column `Total_Devices` doesn't exist.
Run `rlang::last_error()` to see where the error occurred.

I have also tried using this code

res <- rstatix::anova_test(data = df,
                 dv = df$size_range,
                 within = df$Total_Devices)

but I get this error message

Error in `map()`:
ℹ In index: 1.
ℹ With name: dv.
Caused by error:
! Can't subset columns with `df$size_range`.
✖ Can't convert from `df$size_range` <double> to <integer> due to loss of precision.
Run `rlang::last_error()` to see where the error occurred

I have also tried changing the columns to numeric and factors but still I am getting the same error message.

Is it because this should be run through a t-test instead?

>Solution :

Your current df is recognized as list type by anova_test() which is not accepted format (data frame) for the function. Also, looking at the ?anova_test, the formula must be of type aov() function with tilde (~) separating factor from dependent variable as follows:

library(rstatix)

df<-as.data.frame(df)
df$Total_Devices<-factor(df$Total_Devices)

res<-anova_test(size_range ~ Total_Devices, data=df)

res

ANOVA Table (type II tests)

         Effect DFn DFd        F     p p<.05      ges
1 Total_Devices   1  51 0.000823 0.977       1.61e-05
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading