1
$\begingroup$

I am trying to run a Friedman Test on some data in R. I would like to measure a 3-way interaction with a repeated measure. However, I keep getting a persistent error message when I run the code and cannot figure out what the issue is.

Below is a description of my data with a dput for reproducibility:

  • cl_conc (response variable)
  • soil_type (explanatory variable 1; 4 levels)
  • treatment (explanatory variable 2; 4 levels)
  • days (repeated measure; 3 levels) -core_id (subject variable; 48 levels)
    leach.fried <- friedman.test(cl_conc ~ soil_type*treatment*days | core_id, data = leach2)

When I run the code I get this error but am unsure what exactly it means after researching it

Error in friedman.test.formula(cl_conc ~ soil_type * treatment * days | :
incorrect specification for 'formula'

Here is my data:

leach2 <-
  structure(
    list(
      core = c(
        "MS",
        "MS",
        "MS",
        "ML",
        "ML",
        "ML",
        "MK",
        "MK",
        "MK",
        "MC",
        "MC",
        "MC",
        "FS",
        "FS",
        "FS",
        "FL",
        "FL",
        "FL",
        "FK",
        "FK",
        "FK",
        "FC",
        "FC",
        "FC",
        "MS",
        "MS",
        "MS",
        "ML",
        "ML",
        "ML",
        "MK",
        "MK",
        "MK",
        "MC",
        "MC",
        "MC",
        "FS",
        "FS",
        "FS",
        "FL",
        "FL",
        "FL",
        "FK",
        "FK",
        "FK",
        "FC",
        "FC",
        "FC",
        "MS",
        "MS",
        "MS",
        "ML",
        "ML",
        "ML",
        "MK",
        "MK",
        "MK",
        "MC",
        "MC",
        "MC",
        "FS",
        "FS",
        "FS",
        "FL",
        "FL",
        "FL",
        "FK",
        "FK",
        "FK",
        "FC",
        "FC",
        "FC",
        "CS",
        "CL",
        "CK",
        "CC",
        "PS",
        "PL",
        "PK",
        "PC",
        "CS",
        "CL",
        "CK",
        "CC",
        "PS",
        "PL",
        "PK",
        "PC",
        "CS",
        "CL",
        "CK",
        "CC",
        "PS",
        "PL",
        "PK",
        "PC",
        "CS",
        "CL",
        "CK",
        "CC",
        "PS",
        "PL",
        "PK",
        "PC",
        "CS",
        "CL",
        "CK",
        "CC",
        "PS",
        "PL",
        "PK",
        "PC",
        "CS",
        "CL",
        "CK",
        "CC",
        "PS",
        "PL",
        "PK",
        "PC",
        "CS",
        "CK",
        "CL",
        "CC",
        "PS",
        "PL",
        "PK",
        "PC",
        "CS",
        "CL",
        "CK",
        "CC",
        "PS",
        "PL",
        "PK",
        "PC",
        "CS",
        "CL",
        "CK",
        "CC",
        "PS",
        "PL",
        "PK",
        "PC"
      ),
      core_id = c(
        "MS1",
        "MS1",
        "MS1",
        "ML1",
        "ML1",
        "ML1",
        "MK1",
        "MK1",
        "MK1",
        "MC1",
        "MC1",
        "MC1",
        "FS1",
        "FS1",
        "FS1",
        "FL1",
        "FL1",
        "FL1",
        "FK1",
        "FK1",
        "FK1",
        "FC1",
        "FC1",
        "FC1",
        "MS2",
        "MS2",
        "MS2",
        "ML2",
        "ML2",
        "ML2",
        "MK2",
        "MK2",
        "MK2",
        "MC2",
        "MC2",
        "MC2",
        "FS2",
        "FS2",
        "FS2",
        "FL2",
        "FL2",
        "FL2",
        "FK2",
        "FK2",
        "FK2",
        "FC2",
        "FC2",
        "FC2",
        "MS3",
        "MS3",
        "MS3",
        "ML3",
        "ML3",
        "ML3",
        "MK3",
        "MK3",
        "MK3",
        "MC3",
        "MC3",
        "MC3",
        "FS3",
        "FS3",
        "FS3",
        "FL3",
        "FL3",
        "FL3",
        "FK3",
        "FK3",
        "FK3",
        "FC3",
        "FC3",
        "FC3",
        "CS1",
        "CL1",
        "CK1",
        "CC1",
        "PS1",
        "PL1",
        "PK1",
        "PC1",
        "CS2",
        "CL2",
        "CK2",
        "CC2",
        "PS2",
        "PL2",
        "PK2",
        "PC2",
        "CS3",
        "CL3",
        "CK3",
        "CC3",
        "PS3",
        "PL3",
        "PK3",
        "PC3",
        "CS1",
        "CL1",
        "CK1",
        "CC1",
        "PS1",
        "PL1",
        "PK1",
        "PC1",
        "CS2",
        "CL2",
        "CK2",
        "CC2",
        "PS2",
        "PL2",
        "PK2",
        "PC2",
        "CS3",
        "CL3",
        "CK3",
        "CC3",
        "PS3",
        "PL3",
        "PK3",
        "PC3",
        "CS1",
        "CK1",
        "CL1",
        "CC1",
        "PS1",
        "PL1",
        "PK1",
        "PC1",
        "CS2",
        "CL2",
        "CK2",
        "CC2",
        "PS2",
        "PL2",
        "PK2",
        "PC2",
        "CS3",
        "CL3",
        "CK3",
        "CC3",
        "PS3",
        "PL3",
        "PK3",
        "PC3"
      ),
      soil_type = c(
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "WSL",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "NCL ",
        "ESL",
        "ESL",
        "ESL",
        "ESL",
        "FAH",
        "FAH",
        "FAH",
        "FAH",
        "ESL",
        "ESL",
        "ESL",
        "ESL",
        "FAH",
        "FAH",
        "FAH",
        "FAH",
        "ESL",
        "ESL",
        "ESL",
        "ESL",
        "FAH",
        "FAH",
        "FAH",
        "FAH",
        "ESL",
        "ESL",
        "ESL",
        "ESL",
        "FAH",
        "FAH",
        "FAH",
        "FAH",
        "ESL",
        "ESL",
        "ESL",
        "ESL",
        "FAH",
        "FAH",
        "FAH",
        "FAH",
        "ESL",
        "ESL",
        "ESL",
        "ESL",
        "FAH",
        "FAH",
        "FAH",
        "FAH",
        "ESL",
        "ESL",
        "ESL",
        "ESL",
        "FAH",
        "FAH",
        "FAH",
        "FAH",
        "ESL",
        "ESL",
        "ESL",
        "ESL",
        "FAH",
        "FAH",
        "FAH",
        "FAH",
        "ESL",
        "ESL",
        "ESL",
        "ESL",
        "FAH",
        "FAH",
        "FAH",
        "FAH"
      ),
      treatment = c(
        "Tl",
        "Tl",
        "Tl",
        "SM",
        "SM",
        "SM",
        "KCl",
        "KCl",
        "KCl",
        "Control",
        "Control",
        "Control",
        "Tl",
        "Tl",
        "Tl",
        "SM",
        "SM",
        "SM",
        "KCl",
        "KCl",
        "KCl",
        "Control",
        "Control",
        "Control",
        "Tl",
        "Tl",
        "Tl",
        "SM",
        "SM",
        "SM",
        "KCl",
        "KCl",
        "KCl",
        "Control",
        "Control",
        "Control",
        "Tl",
        "Tl",
        "Tl",
        "SM",
        "SM",
        "SM",
        "KCl",
        "KCl",
        "KCl",
        "Control",
        "Control",
        "Control",
        "Tl",
        "Tl",
        "Tl",
        "SM",
        "SM",
        "SM",
        "KCl",
        "KCl",
        "KCl",
        "Control",
        "Control",
        "Control",
        "Tl",
        "Tl",
        "Tl",
        "SM",
        "SM",
        "SM",
        "KCl",
        "KCl",
        "KCl",
        "Control",
        "Control",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "KCl",
        "SM",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control",
        "Tl",
        "SM",
        "KCl",
        "Control"
      ),
      days = c(
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        11L,
        18L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        4L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        11L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L,
        18L
      ),
      cl_conc = c(
        18.1,
        18.1,
        17.4,
        77.1,
        81.4,
        66.8,
        19.4,
        22.3,
        36.9,
        1.9,
        1.2,
        0.6,
        27.8,
        28.3,
        28.3,
        107.8,
        150.3,
        94.6,
        84.8,
        53.4,
        51.9,
        9.1,
        4.25,
        1.9,
        19.8,
        20.7,
        20.5,
        102,
        56.7,
        47.4,
        33.4,
        15.3,
        19.9,
        2,
        1.2,
        0.8,
        37.1,
        39.8,
        34.8,
        81.9,
        67.5,
        56,
        41.1,
        38.3,
        30.9,
        12.4,
        6,
        3.1,
        27.8,
        27.8,
        24.9,
        79.7,
        65.5,
        55.2,
        13.5,
        20.4,
        24.7,
        1.6,
        1.2,
        0.7,
        42.7,
        40.5,
        30.1,
        121.2,
        73.6,
        38,
        53,
        38.5,
        22.3,
        4.7,
        1.9,
        0.85,
        46.5,
        52.6,
        32.9,
        2.8,
        45.1,
        1.3,
        51.2,
        2.6,
        47.59251129,
        68.3,
        38.8,
        5.4,
        34.1,
        66.7,
        23.51266468,
        0.6,
        34.2,
        55.7,
        23.8,
        5,
        42.1,
        47.9,
        44.3,
        0.8,
        56.23151874,
        81.2,
        36.1,
        1.6,
        36.3,
        48.2,
        35.6,
        1.5,
        44.8,
        80.9,
        34.66600908,
        3.1,
        33.3,
        81.5,
        20.2,
        0.4,
        40.1,
        66.8,
        24.5,
        3.6,
        39,
        68.2,
        36,
        0.303367677,
        31.1,
        23.2,
        75.7,
        0.6,
        26.2,
        45.3,
        21.3,
        0.6,
        33.76030379,
        47.5,
        20.5,
        1.1,
        28.6,
        65.9,
        18.9,
        0.2,
        30.2,
        65.5,
        23.3,
        2.7,
        23.9,
        64,
        24.7,
        0.1
      ),
      cl_load = c(
        0.058825,
        0.0543,
        0.0609,
        0.26985,
        0.26455,
        0.2171,
        0.0582,
        0.0669,
        0.119925,
        0.0057,
        0.0036,
        0.00195,
        0.09035,
        0.0849,
        0.0849,
        0.3773,
        0.4509,
        0.3311,
        0.2756,
        0.1602,
        0.1557,
        0.03185,
        0.010625,
        0.006175,
        0.06435,
        0.07245,
        0.07175,
        0.3315,
        0.19845,
        0.1659,
        0.10855,
        0.05355,
        0.064675,
        0.0065,
        0.0039,
        0.0026,
        0.1113,
        0.1393,
        0.1044,
        0.266175,
        0.185625,
        0.168,
        0.113025,
        0.105325,
        0.0927,
        0.0372,
        0.018,
        0.010075,
        0.09035,
        0.09035,
        0.0747,
        0.2391,
        0.22925,
        0.1656,
        0.0405,
        0.0663,
        0.06175,
        0.0048,
        0.0036,
        0.0021,
        0.1281,
        0.131625,
        0.097825,
        0.3939,
        0.2392,
        0.114,
        0.17225,
        0.125125,
        0.0669,
        0.015275,
        0.006175,
        0.0023375,
        0.11625,
        0.14465,
        0.0987,
        0.0084,
        0.0902,
        0.0039,
        0.1152,
        0.00715,
        0.118981278,
        0.2049,
        0.1164,
        0.0135,
        0.093775,
        0.2001,
        0.064659828,
        0.0018,
        0.0855,
        0.1671,
        0.06545,
        0.0125,
        0.094725,
        0.131725,
        0.099675,
        0.0024,
        0.177129284,
        0.2436,
        0.1083,
        0.0048,
        0.1089,
        0.15665,
        0.1068,
        0.0045,
        0.1344,
        0.2427,
        0.11266453,
        0.010075,
        0.0999,
        0.2445,
        0.0606,
        0.0012,
        0.1203,
        0.2004,
        0.0735,
        0.0126,
        0.117,
        0.2046,
        0.117,
        0.000985945,
        0.0933,
        0.0696,
        0.2268,
        0.0018,
        0.0917,
        0.15855,
        0.0639,
        0.00195,
        0.101280911,
        0.1425,
        0.0615,
        0.003025,
        0.0858,
        0.214175,
        0.0567,
        0.00065,
        0.1057,
        0.212875,
        0.075725,
        0.0081,
        0.0717,
        0.192,
        0.0741,
        3e-04
      )
    ),
    row.names = c(
      2L,
      3L,
      4L,
      6L,
      7L,
      8L,
      10L,
      11L,
      12L,
      14L,
      15L,
      16L,
      18L,
      19L,
      20L,
      22L,
      23L,
      24L,
      26L,
      27L,
      28L,
      30L,
      31L,
      32L,
      34L,
      35L,
      36L,
      38L,
      39L,
      40L,
      42L,
      43L,
      44L,
      46L,
      47L,
      48L,
      50L,
      51L,
      52L,
      54L,
      55L,
      56L,
      58L,
      59L,
      60L,
      62L,
      63L,
      64L,
      66L,
      67L,
      68L,
      70L,
      71L,
      72L,
      74L,
      75L,
      76L,
      78L,
      79L,
      80L,
      82L,
      83L,
      84L,
      86L,
      87L,
      88L,
      90L,
      91L,
      92L,
      94L,
      95L,
      96L,
      121L,
      122L,
      123L,
      124L,
      125L,
      126L,
      127L,
      128L,
      129L,
      130L,
      131L,
      132L,
      133L,
      134L,
      135L,
      136L,
      137L,
      138L,
      139L,
      140L,
      141L,
      142L,
      143L,
      144L,
      145L,
      146L,
      147L,
      148L,
      149L,
      150L,
      151L,
      152L,
      153L,
      154L,
      155L,
      156L,
      157L,
      158L,
      159L,
      160L,
      161L,
      162L,
      163L,
      164L,
      165L,
      166L,
      167L,
      168L,
      169L,
      170L,
      171L,
      172L,
      173L,
      174L,
      175L,
      176L,
      177L,
      178L,
      179L,
      180L,
      181L,
      182L,
      183L,
      184L,
      185L,
      186L,
      187L,
      188L,
      189L,
      190L,
      191L,
      192L
    ),
    class = "data.frame"
  )
$\endgroup$

1 Answer 1

1
$\begingroup$

You have to construct the interaction yourself before calling the test, i.e.

leach2$inter <- interaction(as.factor(leach2$soil_type), as.factor(leach2$treatment),
                            as.factor(leach2$days))

> table(leach2$inter)

  ESL.Control.4   FAH.Control.4  NCL .Control.4   WSL.Control.4       ESL.KCl.4 
              3               3               3               3               3 
      FAH.KCl.4      NCL .KCl.4       WSL.KCl.4        ESL.SM.4        FAH.SM.4 
              3               3               3               3               3 
      NCL .SM.4        WSL.SM.4        ESL.Tl.4        FAH.Tl.4       NCL .Tl.4 
              3               3               3               3               3 
       WSL.Tl.4  ESL.Control.11  FAH.Control.11 NCL .Control.11  WSL.Control.11 
              3               3               3               3               3 
     ESL.KCl.11      FAH.KCl.11     NCL .KCl.11      WSL.KCl.11       ESL.SM.11 
              3               3               3               3               3 
      FAH.SM.11      NCL .SM.11       WSL.SM.11       ESL.Tl.11       FAH.Tl.11 
              3               3               3               3               3 
     NCL .Tl.11       WSL.Tl.11  ESL.Control.18  FAH.Control.18 NCL .Control.18 
              3               3               3               3               3 
 WSL.Control.18      ESL.KCl.18      FAH.KCl.18     NCL .KCl.18      WSL.KCl.18 
              3               3               3               3               3 
      ESL.SM.18       FAH.SM.18      NCL .SM.18       WSL.SM.18       ESL.Tl.18 
              3               3               3               3               3 
      FAH.Tl.18      NCL .Tl.18       WSL.Tl.18 
              3               3               3 

However, it seems that you cannot apply the Friedman test to your data since you don't have exactly one observation in the response for each combination of levels of groups and blocks:

leach.fried <-
  friedman.test(cl_conc ~ inter|core_id, 
                data = leach2)
Error in friedman.test.default(mf[[1L]], mf[[2L]], mf[[3L]]) : 
  not an unreplicated complete block design
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.