From your data, it seems that, for example, you're trying to compare the effect of using runnels at the OVFA locations to not using them at the OFVD locations (since they're at similar elevations?), in which case, maybe it makes sense to consider OVFA and OVFD a single observational unit, and do the same for the other triples of locations. If so, here is something you could try:
original data, saved as "ovf" table
ovf <-
structure(list(ID = 55:108, Site = c("OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF"), X = c("OVFA", "OVFA", "OVFA",
"OVFA", "OVFA", "OVFA", "OVFA", "OVFA", "OVFA", "OVFD", "OVFD",
"OVFD", "OVFD", "OVFD", "OVFD", "OVFD", "OVFD", "OVFD", "OVFE",
"OVFE", "OVFE", "OVFE", "OVFE", "OVFE", "OVFE", "OVFE", "OVFE",
"OVFF", "OVFF", "OVFF", "OVFF", "OVFF", "OVFF", "OVFF", "OVFF",
"OVFF", "OVFG", "OVFG", "OVFG", "OVFG", "OVFG", "OVFG", "OVFG",
"OVFG", "OVFG", "OVFH", "OVFH", "OVFH", "OVFH", "OVFH", "OVFH",
"OVFH", "OVFH", "OVFH"), Treatment = c("Runnel", "Runnel", "Runnel",
"Runnel", "Runnel", "Runnel", "Runnel", "Runnel", "Runnel", "Reference",
"Reference", "Reference", "Reference", "Reference", "Reference",
"Reference", "Reference", "Reference", "Runnel", "Runnel", "Runnel",
"Runnel", "Runnel", "Runnel", "Runnel", "Runnel", "Runnel", "Reference",
"Reference", "Reference", "Reference", "Reference", "Reference",
"Reference", "Reference", "Reference", "Reference", "Reference",
"Reference", "Reference", "Reference", "Reference", "Reference",
"Reference", "Reference", "Runnel", "Runnel", "Runnel", "Runnel",
"Runnel", "Runnel", "Runnel", "Runnel", "Runnel"), Zone = c("Center",
"Center", "Center", "Down", "Down", "Down", "Up", "Up", "Up",
"Center", "Center", "Center", "Down", "Down", "Down", "Up", "Up",
"Up", "Center", "Center", "Center", "Down", "Down", "Down", "Up",
"Up", "Up", "Center", "Center", "Center", "Down", "Down", "Down",
"Up", "Up", "Up", "Center", "Center", "Center", "Down", "Down",
"Down", "Up", "Up", "Up", "Center", "Center", "Center", "Down",
"Down", "Down", "Up", "Up", "Up"), Meter = c(NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA), Redox = c(-54.1, -119.8, -130, -44.6, -114.3, -148.9,
38, -41.2, -17.8, -132.9, -228.1, -133.7, -89.8, -139.1, -124,
-18.8, -104.6, -68.4, -193.6, -203, -215.5, -108.3, -206.6, -182.6,
-8.9, -117.8, -91.5, -239.1, -212.2, -204, -167.3, -130.6, -152.3,
-9.3, -90.8, -88.5, -267.5, -247.3, -163.6, -155.7, -124.4, -120,
-65.33, -94.9, -113.3, -238.6, -180.5, -150.6, -179.3, -104.5,
-164.8, -45.2, -78.8, -87.7), Redox.s.e. = c(31.1, 29.7, 51.2,
40.2, 22.8, 40.8, 37.1, 38.8, 64.9, 45.4, 23.7, 33.4, 20.4, 25.3,
24.6, 29.5, 22.8, 32.2, 22.3, 13.9, 11.9, 31.3, 15.7, 4.7, 31.2,
24.4, 22.5, 15.1, 31.6, 16, 46.2, 24.9, 21.8, 44.9, 21.2, 34,
14.1, 9.2, 15.5, 11.3, 14.1, 15.9, 45.7, 29.1, 21.6, 29.8, 45.5,
16.5, 54.9, 38.5, 26.6, 69.4, 39.1, 28.5), Moisture = c(86.7,
86.3, 87.1, 86.5, 87.5, 89, 86.4, 88.5, 87.6, 86.6, 86.4, 86.2,
83.1, 83.9, 81.2, 82.6, 83.5, 83.4, 84.5, 85.6, 82.4, 82.9, 85.1,
84.9, 83.9, 86.5, 84.9, 83.2, 87.2, 84.8, 80.4, 83, 83.2, 83.5,
84.8, 85, 85.9, 82.5, 83, 84.8, 77.8, 81.5, 82.9, 85.8, 86.1,
84.1, 83.1, 81.4, 82.4, 80.1, 81.9, 82.9, 86, 83.4), Moisture.s.e. = c(0.82,
0.88, 0.32, 0.93, 0.64, 0.53, 1.3, 0.94, 0.63, 1.3, 0.21, 1.2,
4.5, 1.4, 1.4, 1.3, 0.5, 1.9, 0.65, 0.7, 1.8, 1, 0.69, 1.1, 1.3,
0.4, 1.4, 1.2, 1.2, 2.1, 2.4, 1.5, 2.1, 2.7, 0.53, 1.5, 0.67,
2, 1, NA, 1.1, 1, 1.3, 0.43, 0.58, 1.1, 0.48, 1.5, 2.2, 1.1,
1.6, 0.52, 0.51, 1.9), OM = c(NA, 62.5, 45.1, NA, 68, 50.2, NA,
67.4, 47.7, NA, 57, 47.6, NA, 68.2, 52.7, NA, 43.1, 49.7, NA,
50.5, 54.6, NA, 46.9, 53, NA, 64.5, 58.2, NA, 29.5, 48.9, NA,
48.6, 51, NA, 66.8, 45.1, NA, 21, 55.3, NA, 39, 54.2, NA, 62.6,
43.9, NA, 39.6, 54.1, NA, 33.9, 48.5, NA, 61.4, 49.7), OM.s.e. = c(NA,
1.3, 5.7, NA, 2.3, 6.4, NA, 6.5, 12.5, NA, 5.3, 1.2, NA, 3.3,
4.4, NA, 2.7, 3.7, NA, 3, 5.8, NA, 4, 1.8, NA, 2.4, 9.3, NA,
1.5, 2.8, NA, 3.7, 5.3, NA, 2.8, 8.1, NA, 7, 4.6, NA, 6.9, 4.8,
NA, 17.1, 6.3, NA, 0.7, 7.1, NA, 3.9, 3.9, NA, 10.3, 3.7), Salinity = c(40.8,
25, 20.4, 34, 24.2, 21.7, 39.5, 16.5, 17, 40.6, 26.2, 26, 43.5,
26.3, 23, 34.5, 27.3, 25.7, 45.5, 18.7, 18.5, 35, 23.8, 18.4,
33.5, 21.7, 19.6, 31.5, 57, 26.6, 38, 26.8, 22.7, 34, 22.7, 23.3,
37.2, 40.4, 23.7, NA, 29, 24.3, 26.6, 15, 20, 33.7, 24, 23.2,
22, 29.5, 21.3, 33, 14, 25.7), Salinity.s.e. = c(5.8, 1.3, 2.4,
3.8, 1.2, 0.94, 5.5, 4.6, 7, 4.4, 1.1, 1.3, 8.5, 2.3, 4.3, 0.5,
1, 2.2, 1, 3.3, 3.4, NA, 2.4, 4.1, 0.5, 3, 2.7, 1, 1.6, 1, 2,
2, 2.7, NA, 1.1, 1.4, 2.8, 2.6, 1.6, NA, 0, 2.6, 2.1, NA, 6,
0.9, 4.9, 3.1, NA, 0.5, 4, NA, 3, 2.2), K = c(0.0119, 0.0104,
0.00982, 0.013, 0.00968, 0.00922, 0.00975, 0.0103, 0.00978, 0.0115,
0.00886, 0.00847, 0.011, 0.00887, 0.00916, 0.0109, 0.00993, 0.00863,
0.0123, 0.012, 0.00968, 0.0113, 0.0103, 0.0098, 0.014, 0.0118,
0.00885, 0.0107, 0.00936, 0.00847, 0.0106, 0.009, 0.00939, 0.0097,
0.0094, 0.0097, 0.0106, 0.00978, 0.008, 0.0122, 0.0111, 0.00926,
0.0119, 0.0098, 0.00921, 0.0104, 0.0101, 0.0106, 0.0097, 0.0097,
0.00899, 0.0119, 0.0116, 0.0107), K.s.e. = c(0.000476, 0.000375,
0.000487, 0.000878, 0.000279, 0.000236, 0.00085, 0.000454, 0.000375,
0.000608, 0.000219, 0.000193, 0.00041, 0.000213, 0.000318, 0.000986,
0.000301, 0.000256, 0.000717, 0.000996, 0.000342, 0.000781, 0.000481,
0.000247, 0.000957, 0.000728, 0.00031, 0.000568, 0.000256, 0.000208,
0.000516, 0.000297, 0.000363, 0.000649, 0.000268, 0.000325, 0.000204,
0.000191, 0.000202, 0.00095, 0.00061, 0.000304, 0.000921, 0.000216,
0.000292, 0.000698, 0.000433, 0.000546, NA, 0.000473, 0.000302,
0.000447, 0.000636, 0.000407), S = c(0.282, 0.283, 0.261, 0.289,
0.29, 0.272, 0.271, 0.257, 0.246, 0.253, 0.294, 0.238, 0.304,
0.309, 0.271, 0.293, 0.35, 0.298, 0.244, 0.324, 0.246, 0.256,
0.282, 0.23, 0.299, 0.311, 0.274, 0.257, 0.285, 0.25, 0.244,
0.297, 0.254, 0.249, 0.298, 0.293, 0.246, 0.332, 0.234, 0.231,
0.354, 0.262, 0.239, 0.333, 0.24, 0.193, 0.319, 0.227, 0.253,
0.326, 0.243, 0.204, 0.294, 0.252), Ss.e = c(0.00854, 0.0126,
0.00682, 0.0267, 0.0142, 0.00758, 0.0387, 0.0198, 0.00986, 0.00769,
0.00843, 0.00636, 0.0253, 0.011, 0.00597, 0.0131, 0.0141, 0.0112,
0.00864, 0.0172, 0.00633, 0.0118, 0.0145, 0.00561, 0.0164, 0.0119,
0.00532, 0.00736, 0.0106, 0.00612, 0.0102, 0.00727, 0.00534,
0.0186, 0.015, 0.00931, 0.00541, 0.0087, 0.00496, 0.0224, 0.0151,
0.00499, 0.00844, 0.00796, 0.011, 0.0257, 0.00784, 0.00917, NA,
0.0157, 0.00828, 0.00978, 0.0149, 0.015), Year = structure(c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L), levels = c("0", "1", "2"), class = "factor"),
Elevation = c(0.472, 0.472, 0.472, NA, NA, NA, NA, NA, NA,
0.399, 0.399, 0.399, NA, NA, NA, NA, NA, NA, 0.393, 0.393,
0.393, NA, NA, NA, NA, NA, NA, 0.382, 0.382, 0.382, NA, NA,
NA, NA, NA, NA, 0.272, 0.272, 0.272, NA, NA, NA, NA, NA,
NA, 0.29, 0.29, 0.29, NA, NA, NA, NA, NA, NA), Depth.of.Dieback = c(0.056,
0.056, 0.056, NA, NA, NA, NA, NA, NA, 0.058, 0.058, 0.058,
NA, NA, NA, NA, NA, NA, 0.098, 0.098, 0.098, NA, NA, NA,
NA, NA, NA, 0.067, 0.067, 0.067, NA, NA, NA, NA, NA, NA,
0.181, 0.181, 0.181, NA, NA, NA, NA, NA, NA, 0.142, 0.142,
0.142, NA, NA, NA, NA, NA, NA)), row.names = c(NA, -54L), class = "data.frame")
As @vedoa did, first create a column that contains IDs for the observational units:
library(tidyverse)
library(rstatix)
ovf_small <-
ovf |>
# limit to columns of relevant to post
select(X, Treatment, Zone, Year, K) |>
# consider pairs of X values at similar elevation as representing an
# observational unit
mutate(
WID =
case_when(
# regular expression "last letter is _ or _": (_|_)$
str_detect(X, '(A|D)$') ~ 'AD',
str_detect(X, '(E|F)$') ~ 'EF',
# assign remaining X values to 'GH'
TRUE ~ 'GH'
)
) |>
# convert from data frame to tibble for easier inspection
as_tibble()
Inspect ovf_small
:
ovf_small
#> # A tibble: 54 × 6
#> X Treatment Zone Year K WID
#> <chr> <chr> <chr> <fct> <dbl> <chr>
#> 1 OVFA Runnel Center 0 0.0119 AD
#> 2 OVFA Runnel Center 1 0.0104 AD
#> 3 OVFA Runnel Center 2 0.00982 AD
#> 4 OVFA Runnel Down 0 0.013 AD
#> 5 OVFA Runnel Down 1 0.00968 AD
#> 6 OVFA Runnel Down 2 0.00922 AD
#> 7 OVFA Runnel Up 0 0.00975 AD
#> 8 OVFA Runnel Up 1 0.0103 AD
#> 9 OVFA Runnel Up 2 0.00978 AD
#> 10 OVFD Reference Center 0 0.0115 AD
#> # ℹ 44 more rows
Apply anova_test()
:
ovf_small |>
anova_test(
dv = K,
wid = WID,
# factors associated with each observational unit
within = c(Zone, Treatment, Year)
)
View output:
#> ANOVA Table (type III tests)
#>
#> $ANOVA
#> Effect DFn DFd F p p<.05 ges
#> 1 Zone 2 4 0.703 0.547 0.032
#> 2 Treatment 1 2 4.547 0.167 0.223
#> 3 Year 2 4 50.609 0.001 * 0.532
#> 4 Zone:Treatment 2 4 1.529 0.321 0.097
#> 5 Zone:Year 4 8 0.304 0.867 0.024
#> 6 Treatment:Year 2 4 0.177 0.844 0.019
#> 7 Zone:Treatment:Year 4 8 0.370 0.824 0.035
#>
#> $`Mauchly's Test for Sphericity`
#> Effect W p p<.05
#> 1 Zone 0.528 0.727
#> 2 Year 0.449 0.670
#> 3 Zone:Treatment 0.097 0.312
#> 4 Treatment:Year 0.006 0.080
#>
#> $`Sphericity Corrections`
#> Effect GGe DF[GG] p[GG] p[GG]<.05 HFe DF[HF] p[HF]
#> 1 Zone 0.679 1.36, 2.72 0.515 1.620 3.24, 6.48 0.547
#> 2 Year 0.645 1.29, 2.58 0.009 * 1.313 2.63, 5.25 0.001
#> 3 Zone:Treatment 0.526 1.05, 2.1 0.341 0.608 1.22, 2.43 0.338
#> 4 Treatment:Year 0.502 1, 2.01 0.716 0.507 1.01, 2.03 0.718
#> p[HF]<.05
#> 1
#> 2 *
#> 3
#> 4
Created on 2024-05-21 with reprex v2.0.2
Full reprex
ovf <-
structure(list(ID = 55:108, Site = c("OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF", "OVF",
"OVF", "OVF", "OVF", "OVF", "OVF"), X = c("OVFA", "OVFA", "OVFA",
"OVFA", "OVFA", "OVFA", "OVFA", "OVFA", "OVFA", "OVFD", "OVFD",
"OVFD", "OVFD", "OVFD", "OVFD", "OVFD", "OVFD", "OVFD", "OVFE",
"OVFE", "OVFE", "OVFE", "OVFE", "OVFE", "OVFE", "OVFE", "OVFE",
"OVFF", "OVFF", "OVFF", "OVFF", "OVFF", "OVFF", "OVFF", "OVFF",
"OVFF", "OVFG", "OVFG", "OVFG", "OVFG", "OVFG", "OVFG", "OVFG",
"OVFG", "OVFG", "OVFH", "OVFH", "OVFH", "OVFH", "OVFH", "OVFH",
"OVFH", "OVFH", "OVFH"), Treatment = c("Runnel", "Runnel", "Runnel",
"Runnel", "Runnel", "Runnel", "Runnel", "Runnel", "Runnel", "Reference",
"Reference", "Reference", "Reference", "Reference", "Reference",
"Reference", "Reference", "Reference", "Runnel", "Runnel", "Runnel",
"Runnel", "Runnel", "Runnel", "Runnel", "Runnel", "Runnel", "Reference",
"Reference", "Reference", "Reference", "Reference", "Reference",
"Reference", "Reference", "Reference", "Reference", "Reference",
"Reference", "Reference", "Reference", "Reference", "Reference",
"Reference", "Reference", "Runnel", "Runnel", "Runnel", "Runnel",
"Runnel", "Runnel", "Runnel", "Runnel", "Runnel"), Zone = c("Center",
"Center", "Center", "Down", "Down", "Down", "Up", "Up", "Up",
"Center", "Center", "Center", "Down", "Down", "Down", "Up", "Up",
"Up", "Center", "Center", "Center", "Down", "Down", "Down", "Up",
"Up", "Up", "Center", "Center", "Center", "Down", "Down", "Down",
"Up", "Up", "Up", "Center", "Center", "Center", "Down", "Down",
"Down", "Up", "Up", "Up", "Center", "Center", "Center", "Down",
"Down", "Down", "Up", "Up", "Up"), Meter = c(NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA), Redox = c(-54.1, -119.8, -130, -44.6, -114.3, -148.9,
38, -41.2, -17.8, -132.9, -228.1, -133.7, -89.8, -139.1, -124,
-18.8, -104.6, -68.4, -193.6, -203, -215.5, -108.3, -206.6, -182.6,
-8.9, -117.8, -91.5, -239.1, -212.2, -204, -167.3, -130.6, -152.3,
-9.3, -90.8, -88.5, -267.5, -247.3, -163.6, -155.7, -124.4, -120,
-65.33, -94.9, -113.3, -238.6, -180.5, -150.6, -179.3, -104.5,
-164.8, -45.2, -78.8, -87.7), Redox.s.e. = c(31.1, 29.7, 51.2,
40.2, 22.8, 40.8, 37.1, 38.8, 64.9, 45.4, 23.7, 33.4, 20.4, 25.3,
24.6, 29.5, 22.8, 32.2, 22.3, 13.9, 11.9, 31.3, 15.7, 4.7, 31.2,
24.4, 22.5, 15.1, 31.6, 16, 46.2, 24.9, 21.8, 44.9, 21.2, 34,
14.1, 9.2, 15.5, 11.3, 14.1, 15.9, 45.7, 29.1, 21.6, 29.8, 45.5,
16.5, 54.9, 38.5, 26.6, 69.4, 39.1, 28.5), Moisture = c(86.7,
86.3, 87.1, 86.5, 87.5, 89, 86.4, 88.5, 87.6, 86.6, 86.4, 86.2,
83.1, 83.9, 81.2, 82.6, 83.5, 83.4, 84.5, 85.6, 82.4, 82.9, 85.1,
84.9, 83.9, 86.5, 84.9, 83.2, 87.2, 84.8, 80.4, 83, 83.2, 83.5,
84.8, 85, 85.9, 82.5, 83, 84.8, 77.8, 81.5, 82.9, 85.8, 86.1,
84.1, 83.1, 81.4, 82.4, 80.1, 81.9, 82.9, 86, 83.4), Moisture.s.e. = c(0.82,
0.88, 0.32, 0.93, 0.64, 0.53, 1.3, 0.94, 0.63, 1.3, 0.21, 1.2,
4.5, 1.4, 1.4, 1.3, 0.5, 1.9, 0.65, 0.7, 1.8, 1, 0.69, 1.1, 1.3,
0.4, 1.4, 1.2, 1.2, 2.1, 2.4, 1.5, 2.1, 2.7, 0.53, 1.5, 0.67,
2, 1, NA, 1.1, 1, 1.3, 0.43, 0.58, 1.1, 0.48, 1.5, 2.2, 1.1,
1.6, 0.52, 0.51, 1.9), OM = c(NA, 62.5, 45.1, NA, 68, 50.2, NA,
67.4, 47.7, NA, 57, 47.6, NA, 68.2, 52.7, NA, 43.1, 49.7, NA,
50.5, 54.6, NA, 46.9, 53, NA, 64.5, 58.2, NA, 29.5, 48.9, NA,
48.6, 51, NA, 66.8, 45.1, NA, 21, 55.3, NA, 39, 54.2, NA, 62.6,
43.9, NA, 39.6, 54.1, NA, 33.9, 48.5, NA, 61.4, 49.7), OM.s.e. = c(NA,
1.3, 5.7, NA, 2.3, 6.4, NA, 6.5, 12.5, NA, 5.3, 1.2, NA, 3.3,
4.4, NA, 2.7, 3.7, NA, 3, 5.8, NA, 4, 1.8, NA, 2.4, 9.3, NA,
1.5, 2.8, NA, 3.7, 5.3, NA, 2.8, 8.1, NA, 7, 4.6, NA, 6.9, 4.8,
NA, 17.1, 6.3, NA, 0.7, 7.1, NA, 3.9, 3.9, NA, 10.3, 3.7), Salinity = c(40.8,
25, 20.4, 34, 24.2, 21.7, 39.5, 16.5, 17, 40.6, 26.2, 26, 43.5,
26.3, 23, 34.5, 27.3, 25.7, 45.5, 18.7, 18.5, 35, 23.8, 18.4,
33.5, 21.7, 19.6, 31.5, 57, 26.6, 38, 26.8, 22.7, 34, 22.7, 23.3,
37.2, 40.4, 23.7, NA, 29, 24.3, 26.6, 15, 20, 33.7, 24, 23.2,
22, 29.5, 21.3, 33, 14, 25.7), Salinity.s.e. = c(5.8, 1.3, 2.4,
3.8, 1.2, 0.94, 5.5, 4.6, 7, 4.4, 1.1, 1.3, 8.5, 2.3, 4.3, 0.5,
1, 2.2, 1, 3.3, 3.4, NA, 2.4, 4.1, 0.5, 3, 2.7, 1, 1.6, 1, 2,
2, 2.7, NA, 1.1, 1.4, 2.8, 2.6, 1.6, NA, 0, 2.6, 2.1, NA, 6,
0.9, 4.9, 3.1, NA, 0.5, 4, NA, 3, 2.2), K = c(0.0119, 0.0104,
0.00982, 0.013, 0.00968, 0.00922, 0.00975, 0.0103, 0.00978, 0.0115,
0.00886, 0.00847, 0.011, 0.00887, 0.00916, 0.0109, 0.00993, 0.00863,
0.0123, 0.012, 0.00968, 0.0113, 0.0103, 0.0098, 0.014, 0.0118,
0.00885, 0.0107, 0.00936, 0.00847, 0.0106, 0.009, 0.00939, 0.0097,
0.0094, 0.0097, 0.0106, 0.00978, 0.008, 0.0122, 0.0111, 0.00926,
0.0119, 0.0098, 0.00921, 0.0104, 0.0101, 0.0106, 0.0097, 0.0097,
0.00899, 0.0119, 0.0116, 0.0107), K.s.e. = c(0.000476, 0.000375,
0.000487, 0.000878, 0.000279, 0.000236, 0.00085, 0.000454, 0.000375,
0.000608, 0.000219, 0.000193, 0.00041, 0.000213, 0.000318, 0.000986,
0.000301, 0.000256, 0.000717, 0.000996, 0.000342, 0.000781, 0.000481,
0.000247, 0.000957, 0.000728, 0.00031, 0.000568, 0.000256, 0.000208,
0.000516, 0.000297, 0.000363, 0.000649, 0.000268, 0.000325, 0.000204,
0.000191, 0.000202, 0.00095, 0.00061, 0.000304, 0.000921, 0.000216,
0.000292, 0.000698, 0.000433, 0.000546, NA, 0.000473, 0.000302,
0.000447, 0.000636, 0.000407), S = c(0.282, 0.283, 0.261, 0.289,
0.29, 0.272, 0.271, 0.257, 0.246, 0.253, 0.294, 0.238, 0.304,
0.309, 0.271, 0.293, 0.35, 0.298, 0.244, 0.324, 0.246, 0.256,
0.282, 0.23, 0.299, 0.311, 0.274, 0.257, 0.285, 0.25, 0.244,
0.297, 0.254, 0.249, 0.298, 0.293, 0.246, 0.332, 0.234, 0.231,
0.354, 0.262, 0.239, 0.333, 0.24, 0.193, 0.319, 0.227, 0.253,
0.326, 0.243, 0.204, 0.294, 0.252), Ss.e = c(0.00854, 0.0126,
0.00682, 0.0267, 0.0142, 0.00758, 0.0387, 0.0198, 0.00986, 0.00769,
0.00843, 0.00636, 0.0253, 0.011, 0.00597, 0.0131, 0.0141, 0.0112,
0.00864, 0.0172, 0.00633, 0.0118, 0.0145, 0.00561, 0.0164, 0.0119,
0.00532, 0.00736, 0.0106, 0.00612, 0.0102, 0.00727, 0.00534,
0.0186, 0.015, 0.00931, 0.00541, 0.0087, 0.00496, 0.0224, 0.0151,
0.00499, 0.00844, 0.00796, 0.011, 0.0257, 0.00784, 0.00917, NA,
0.0157, 0.00828, 0.00978, 0.0149, 0.015), Year = structure(c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 3L), levels = c("0", "1", "2"), class = "factor"),
Elevation = c(0.472, 0.472, 0.472, NA, NA, NA, NA, NA, NA,
0.399, 0.399, 0.399, NA, NA, NA, NA, NA, NA, 0.393, 0.393,
0.393, NA, NA, NA, NA, NA, NA, 0.382, 0.382, 0.382, NA, NA,
NA, NA, NA, NA, 0.272, 0.272, 0.272, NA, NA, NA, NA, NA,
NA, 0.29, 0.29, 0.29, NA, NA, NA, NA, NA, NA), Depth.of.Dieback = c(0.056,
0.056, 0.056, NA, NA, NA, NA, NA, NA, 0.058, 0.058, 0.058,
NA, NA, NA, NA, NA, NA, 0.098, 0.098, 0.098, NA, NA, NA,
NA, NA, NA, 0.067, 0.067, 0.067, NA, NA, NA, NA, NA, NA,
0.181, 0.181, 0.181, NA, NA, NA, NA, NA, NA, 0.142, 0.142,
0.142, NA, NA, NA, NA, NA, NA)), row.names = c(NA, -54L), class = "data.frame")
library(tidyverse)
library(rstatix)
ovf_small <-
ovf |>
# limit to columns of relevant to post
select(X, Treatment, Zone, Year, K) |>
# consider pairs of X values at similar elevation as representing an
# observational unit
mutate(
WID =
case_when(
# regular expression "last letter is _ or _": (_|_)$
str_detect(X, '(A|D)$') ~ 'AD',
str_detect(X, '(E|F)$') ~ 'EF',
# assign remaining X values to 'GH'
TRUE ~ 'GH'
)
) |>
# convert from data frame to tibble for easier inspection
as_tibble()
ovf_small
#> # A tibble: 54 × 6
#> X Treatment Zone Year K WID
#> <chr> <chr> <chr> <fct> <dbl> <chr>
#> 1 OVFA Runnel Center 0 0.0119 AD
#> 2 OVFA Runnel Center 1 0.0104 AD
#> 3 OVFA Runnel Center 2 0.00982 AD
#> 4 OVFA Runnel Down 0 0.013 AD
#> 5 OVFA Runnel Down 1 0.00968 AD
#> 6 OVFA Runnel Down 2 0.00922 AD
#> 7 OVFA Runnel Up 0 0.00975 AD
#> 8 OVFA Runnel Up 1 0.0103 AD
#> 9 OVFA Runnel Up 2 0.00978 AD
#> 10 OVFD Reference Center 0 0.0115 AD
#> # ℹ 44 more rows
ovf_small |>
anova_test(
dv = K,
wid = WID,
# factors associated with each observational unit
within = c(Zone, Treatment, Year)
)
#> ANOVA Table (type III tests)
#>
#> $ANOVA
#> Effect DFn DFd F p p<.05 ges
#> 1 Zone 2 4 0.703 0.547 0.032
#> 2 Treatment 1 2 4.547 0.167 0.223
#> 3 Year 2 4 50.609 0.001 * 0.532
#> 4 Zone:Treatment 2 4 1.529 0.321 0.097
#> 5 Zone:Year 4 8 0.304 0.867 0.024
#> 6 Treatment:Year 2 4 0.177 0.844 0.019
#> 7 Zone:Treatment:Year 4 8 0.370 0.824 0.035
#>
#> $`Mauchly's Test for Sphericity`
#> Effect W p p<.05
#> 1 Zone 0.528 0.727
#> 2 Year 0.449 0.670
#> 3 Zone:Treatment 0.097 0.312
#> 4 Treatment:Year 0.006 0.080
#>
#> $`Sphericity Corrections`
#> Effect GGe DF[GG] p[GG] p[GG]<.05 HFe DF[HF] p[HF]
#> 1 Zone 0.679 1.36, 2.72 0.515 1.620 3.24, 6.48 0.547
#> 2 Year 0.645 1.29, 2.58 0.009 * 1.313 2.63, 5.25 0.001
#> 3 Zone:Treatment 0.526 1.05, 2.1 0.341 0.608 1.22, 2.43 0.338
#> 4 Treatment:Year 0.502 1, 2.01 0.716 0.507 1.01, 2.03 0.718
#> p[HF]<.05
#> 1
#> 2 *
#> 3
#> 4
Created on 2024-05-21 with reprex v2.0.2