2
$\begingroup$

I have data from 16 automated sensors that measure a parameter across 4 experimental treatments with 4 replicated experimental units each:

time series

How would I go about to robustly test for significant differences between my treatments within this 24h period using a GAM, while accounting for autocorrelation of the individual time series?

My main uncertainty lies in where I should introduce the experimental units into the model. If I just a point measurement I would not specify Unit, as it is where the Treatment is replicated. But in a time series, I have repeated measurements from the same units, so how do I say that my time series are grouped by unit that is not a Treatment?

My attempt:

mod<-gamm(value ~ Treatment +
       s(Hour, by=Treatment, k=6) + 
       s(Unit, bs="re"),
      correlation = corARMA(form = ~ Hour|Unit, p = 1),
     data=mod_data)

Another problem I have is persistent autocorrelation: checking the model with acf(resid(mod$gam)) still shows high autocorrelation in the residuals, so something else is wrong here I think.

enter image description here

This is the data:

mod_data = structure(list(Unit = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                  1L, 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, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
                                  3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
                                  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
                                  5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
                                  5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
                                  6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
                                  7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
                                  7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 
                                  8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
                                  9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 
                                  9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
                                  10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 
                                  11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 
                                  11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 
                                  12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
                                  12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 
                                  13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
                                  13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
                                  14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
                                  14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
                                  15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
                                  15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 
                                  16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L
), .Label = c("1A", "1B", "1C", "2A", "2B", "2C", "2D", "3A", 
              "3D", "4A", "4B", "4C", "4D", "5A", "5B", "5C"), class = "factor"), 
Hour = c(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
         12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 
         0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 
         14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 
         2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
         15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 
         3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 
         16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 
         5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 
         18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 
         7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 
         19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
         8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
         20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
         10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 
         22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
         12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 
         0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 
         14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 
         2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
         15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 
         3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 
         16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 
         5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 
         18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 
         7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 
         19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
         8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
         20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
         10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 
         22L, 23L), Treatment = structure(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, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                            1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                            1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                            1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
                                            4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
                                            1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                            1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 
                                            4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
                                            4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
                                            3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 
                                            1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                            1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
                                            3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
                                            2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
                                            2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 
                                            4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
                                            4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
                                            2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 
                                            4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
                                            4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
                                            3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
                                            3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
                                            3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 
                                            2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
                                            2L, 2L, 2L), .Label = c("A", "B", "C", "D"), class = "factor"), 
value = c(11.12, 11.03, 11.59, 11.6, 11.5, 11.23, 11.54, 
          11.96, 12.07, 12.03, 11.34, 9.85, 8.36, 8.11, 8.11, 9.2, 
          11.93, 9.5, 9.8, 10.22, 10.04, 10.66, 10.49, 11, 2.1, 2.14, 
          2.19, 1.91, 2.08, 1.99, 2.09, 2.23, 2.01, 1.9, 1.84, 1.66, 
          1.53, 1.62, 1.4, 1.53, 1.66, 1.65, 1.9, 1.77, 1.92, 1.88, 
          1.88, 2, 10.53, 11.42, 10.23, 11.13, 11.3, 12.08, 11.28, 
          10.49, 11.34, 11.14, 9.02, 8.22, 8.13, 8.11, 6.36, 7.27, 
          9.56, 8.92, 9.22, 10.08, 10.13, 10.05, 9.83, 9.98, 24.68, 
          25.32, 25.2, 25.83, 24.92, 26.33, 24.93, 25.83, 26.64, 30.43, 
          27.05, 25.56, 23.18, 21.34, 20.2, 20.06, 20.87, 19.55, 18.09, 
          18.96, 20.39, 20.8, 22.37, 23.13, 5.7, 5.77, 5.56, 5.88, 
          5.68, 6.07, 5.51, 5.89, 5.98, 5.81, 5.03, 4.06, 3.73, 3.43, 
          3.45, 3.19, 4.03, 4.46, 4.5, 4.37, 4.83, 4.66, 4.83, 4.41, 
          23.54, 25.52, 25.75, 25.71, 29.73, 26.97, 25.36, 28.1, 28.6, 
          30.28, 28.52, 24.87, 23.23, 21.24, 20.41, 21.45, 23.56, 21.92, 
          19.98, 20.7, 21.5, 22.14, 23.03, 23.58, 11.38, 12.02, 12.65, 
          12.27, 11.78, 12.3, 13.04, 12.52, 12.5, 13.54, 12.67, 9.99, 
          10.14, 8.63, 7.87, 7.03, 8.41, 8.76, 9.19, 9.73, 9.95, 10.13, 
          10.58, 11.02, 1.04, 1.05, 1.09, 1.13, 1.06, 1.07, 1.11, 1.05, 
          1.07, 1.04, 1.04, 1.02, 1, 0.99, 0.99, 1, 1.02, 1.04, 1.06, 
          1.03, 1.03, 1.07, 1.03, 1.05, 1, 0.98, 0.96, 0.98, 0.96, 
          0.98, 0.97, 0.96, 0.96, 0.92, 0.91, 0.91, 0.94, 0.91, 0.91, 
          0.94, 0.9, 0.9, 0.94, 0.94, 0.96, 0.97, 1.02, 0.93, 1.06, 
          1.11, 1.09, 1.05, 1.1, 1.17, 1.09, 1.11, 1.09, 1.03, 0.99, 
          1.02, 1.03, 0.97, 0.99, 1, 0.91, 0.95, 0.99, 1.05, 1.06, 
          1.06, 1.07, 1.11, 4.57, 4.7, 5.07, 4.82, 4.82, 4.82, 4.78, 
          4.73, 5.01, 5.17, 4.97, 4.69, 4.91, 4.17, 3.96, 4.1, 4.23, 
          4.23, 3.96, 4.09, 4.33, 4.5, 4.53, 4.59, 2.74, 2.85, 2.54, 
          2.74, 2.91, 3.02, 2.76, 2.63, 2.61, 2.37, 2.12, 2.05, 1.92, 
          1.81, 1.97, 2.07, 2.39, 2.4, 2.29, 2.65, 2.38, 2.35, 2.41, 
          2.62, 22.94, 23.29, 24.76, 25.32, 26.36, 26.59, 29.37, 25.26, 
          31.5, 34.11, 34.09, 29.9, 28.43, 26.45, 26.68, 27.74, 27.33, 
          20.27, 17.57, 18.73, 19.53, 19.92, 21.53, 21.86, 5.29, 6.04, 
          4.81, 5.27, 5.12, 5.46, 5.21, 5.57, 6.11, 4.85, 3.77, 3.96, 
          4.8, 4.66, 4.1, 4.26, 4.13, 3.77, 3.88, 4.22, 3.94, 3.79, 
          4.02, 4.37, 3.38, 3.66, 3.4, 3.69, 3.6, 3.71, 3.85, 3.7, 
          3.99, 3.81, 2.88, 2.47, 2.19, 2.04, 2.09, 2.33, 2.89, 2.86, 
          2.79, 2.76, 2.74, 2.63, 2.85, 2.82, 4.18, 4.1, 4.12, 4.2, 
          4.08, 4.2, 4.22, 4.22, 4.58, 4.65, 3.43, 2.53, 2.13, 1.89, 
          1.75, 2.06, 3.41, 4.09, 4.26, 4.14, 4.22, 4.13, 4.16, 4.15
)), row.names = c(NA, -384L), class = c("data.table", "data.frame"
))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.