Can I perform ANOVA test with time as the dependent variable (y) in R?

275 Views Asked by At

I want to test if the origin of a tadpole affects its metamorphosis date, meaning, if a tadpole's origin is from a pool in the north, would the metamorphosis be earlier than the metamorphosis of a tadpole originated from the south? to do that, I was hoping to use ANOVA test. my code looks like that:

DATE_OF_METAMORPHOSIS -> dmy_hms(DATE_OF_METAMORPHOSIS)

one.way <- aov(DATE_OF_METAMORPHOSIS ~ POPULATION, data = info_table)

it did compute something, but I'm not sure how R treated the dates in the DATE_OF_METAMORPHOSIS variable.. if anyone knows if my code did what I've described in words, or knows if R knows how to use dates as a continuance variable and how to do that, I would love the help! tnx!

example of my data:
info_table

ID | POPULATION | DATE_OF_METAMORPHOSIS|
---|------------|----------------------|
1 | 1 | 7/19/2021  12:01:00 AM|
2 | 2 | 7/29/2021  12:01:00 AM|
3 | 3 | 8/1/2021  12:01:00 AM|
4 | 1 | 8/4/2021  12:01:00 AM|
5 | 2 | 5/16/2021  12:01:00 AM|
6 | 3 | 5/14/2021  12:01:00 AM|
1

There are 1 best solutions below

2
Rui Barradas On

The two errors are:

  1. The datetime column is in the format mdy hms, not ymd hms;
  2. There is no column POPULATION, it's name is origin.

Correct both errors and it's a simple matter of running aov.

x <- '
ID | origin | DATE_OF_METAMORPHOSIS|
1 | 1 | 7/19/2021  12:01:00 AM|
2 | 2 | 7/29/2021  12:01:00 AM|
3 | 3 | 8/1/2021  12:01:00 AM|
4 | 1 | 8/4/2021  12:01:00 AM|
5 | 2 | 5/16/2021  12:01:00 AM|
6 | 3 | 5/14/2021  12:01:00 AM|'

info_table <- read.table(textConnection(x), header = TRUE, sep = "|")[-4]
info_table$DATE_OF_METAMORPHOSIS <- lubridate::mdy_hms(info_table$DATE_OF_METAMORPHOSIS)

one.way <- aov(DATE_OF_METAMORPHOSIS ~ origin, data = info_table)
summary(one.way)
#>             Df    Sum Sq   Mean Sq F value Pr(>F)
#> origin       1 8.885e+12 8.885e+12   0.743  0.437
#> Residuals    4 4.782e+13 1.196e+13

Created on 2022-05-24 by the reprex package (v2.0.1)