使用 anova_test() 时出现错误消息 - str2lang(x) 中的错误:<text>:1:8:意外输入 1:cbind(1_

Error message when using anova_test() - Error in str2lang(x) : <text>:1:8: unexpected input 1: cbind(1_

提问人:strangecharm 提问时间:7/12/2023 最后编辑:r2evansstrangecharm 更新时间:7/12/2023 访问量:35

问:

当使用新数据运行以前工作的代码时,我收到以下错误:

res.aov <- anova_test(
  data = c1_l1, dv = value, wid = Month,
  within = c(buffer, TimePeriod),
  effect.size = "ges",
  detailed = TRUE,
)
# Error in str2lang(x) : <text>:1:10: unexpected input
# 1: cbind(100_

显然,这表明数据是问题所在,但我不明白为什么会这样。数据已使用与以前相同的过程重新创建,以相同的方式准备,据我所知,它们采用相同的格式和语法。

数据:

> dput(head(c1_l1))
structure(list(buffer = c(2, 3, 4, 5, 6, 7), date = structure(c(18270, 
18270, 18270, 18270, 18270, 18270), class = "Date"), Year = structure(c(3L, 
3L, 3L, 3L, 3L, 3L), levels = c("2016", "2017", "2020"), class = "factor"), 
    Month = c(1, 1, 1, 1, 1, 1), TimePeriod = structure(c(2L, 
    2L, 2L, 2L, 2L, 2L), levels = c("1", "2"), class = "factor"), 
    variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L), levels = c("lst_c1_l1_lst", 
    "lst_c1_l1_single_lst", "lst_c2_l1_lst", "lst_c2_l1_single_lst", 
    "lst_c2_l2_lst"), class = "factor"), value = c(39.42118494, 
    39.46416636, 39.48439384, 39.49212885, 39.23692955, 39.2688776
    )), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))
> str(lst)
'data.frame':   2400 obs. of  7 variables:
 $ buffer    : num  200 200 200 200 200 300 300 300 300 300 ...
 $ date      : Date, format: "2020-01-09" "2020-01-09" "2020-01-09" ...
 $ Year      : Factor w/ 3 levels "2016","2017",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ Month     : num  1 1 1 1 1 1 1 1 1 1 ...
 $ TimePeriod: Factor w/ 2 levels "1","2": 2 2 2 2 2 2 2 2 2 2 ...
 $ variable  : Factor w/ 5 levels "lst_c1_l1_lst",..: 1 2 3 4 5 1 2 3 4 5 ...
 $ value     : num  39.4 39.4 39.7 39.7 39.7 ...

法典:

# Some of the below are not used - subsetted from larger R file
library(ggplot2)
library(ggpubr)
library(tidyverse)
library(rstatix)
library(ez)
library(dplyr)

lst <- read.csv("./Data/By metric/LST/landsat_lsts_long.csv", encoding="UTF-8", check.names = FALSE)
str(lst)

lst$buffer <- as.numeric(lst$buffer)
lst$date <- as.Date(lst$date, format = "%d/%m/%Y")
lst$Year <- as.factor(lst$Year)
lst$Month <- as.numeric(lst$Month)
lst$TimePeriod <- as.factor(lst$TimePeriod)
lst$variable <- as.factor(lst$variable)
#lst$weather_variable <- as.factor(lst$weather_variable)

str(lst)

c1_l1 <- as_tibble(filter(lst, variable == "lst_c1_l1_lst"))

res.aov <- anova_test(
  data = c1_l1, dv = value, wid = Month,
  within = c(buffer, TimePeriod),
  effect.size = "ges",
  detailed = TRUE,
)
get_anova_table(res.aov, correction = "auto")

谁能解释错误或提出解决方案?

编辑

较大的数据示例(2400 行中的 500 行):

> dput(lst[1:500, ])
structure(list(buffer = c(200, 200, 200, 200, 200, 300, 300, 
300, 300, 300, 400, 400, 400, 400, 400, 500, 500, 500, 500, 500, 
600, 600, 600, 600, 600, 700, 700, 700, 700, 700, 800, 800, 800, 
800, 800, 900, 900, 900, 900, 900, 1000, 1000, 1000, 1000, 1000, 
1100, 1100, 1100, 1100, 1100, 1200, 1200, 1200, 1200, 1200, 1300, 
1300, 1300, 1300, 1300, 1400, 1400, 1400, 1400, 1400, 1500, 1500, 
1500, 1500, 1500, 1600, 1600, 1600, 1600, 1600, 1700, 1700, 1700, 
1700, 1700, 1800, 1800, 1800, 1800, 1800, 1900, 1900, 1900, 1900, 
1900, 2000, 2000, 2000, 2000, 2000, 100, 100, 100, 100, 100, 
200, 200, 200, 200, 200, 300, 300, 300, 300, 300, 400, 400, 400, 
400, 400, 500, 500, 500, 500, 500, 600, 600, 600, 600, 600, 700, 
700, 700, 700, 700, 800, 800, 800, 800, 800, 900, 900, 900, 900, 
900, 1000, 1000, 1000, 1000, 1000, 1100, 1100, 1100, 1100, 1100, 
1200, 1200, 1200, 1200, 1200, 1300, 1300, 1300, 1300, 1300, 1400, 
1400, 1400, 1400, 1400, 1500, 1500, 1500, 1500, 1500, 1600, 1600, 
1600, 1600, 1600, 1700, 1700, 1700, 1700, 1700, 1800, 1800, 1800, 
1800, 1800, 1900, 1900, 1900, 1900, 1900, 2000, 2000, 2000, 2000, 
2000, 100, 100, 100, 100, 100, 200, 200, 200, 200, 200, 300, 
300, 300, 300, 300, 400, 400, 400, 400, 400, 500, 500, 500, 500, 
500, 600, 600, 600, 600, 600, 700, 700, 700, 700, 700, 800, 800, 
800, 800, 800, 900, 900, 900, 900, 900, 1000, 1000, 1000, 1000, 
1000, 1100, 1100, 1100, 1100, 1100, 1200, 1200, 1200, 1200, 1200, 
1300, 1300, 1300, 1300, 1300, 1400, 1400, 1400, 1400, 1400, 1500, 
1500, 1500, 1500, 1500, 1600, 1600, 1600, 1600, 1600, 1700, 1700, 
1700, 1700, 1700, 1800, 1800, 1800, 1800, 1800, 1900, 1900, 1900, 
1900, 1900, 2000, 2000, 2000, 2000, 2000, 100, 100, 100, 100, 
100, 200, 200, 200, 200, 200, 300, 300, 300, 300, 300, 400, 400, 
400, 400, 400, 500, 500, 500, 500, 500, 600, 600, 600, 600, 600, 
700, 700, 700, 700, 700, 800, 800, 800, 800, 800, 900, 900, 900, 
900, 900, 1000, 1000, 1000, 1000, 1000, 1100, 1100, 1100, 1100, 
1100, 1200, 1200, 1200, 1200, 1200, 1300, 1300, 1300, 1300, 1300, 
1400, 1400, 1400, 1400, 1400, 1500, 1500, 1500, 1500, 1500, 1600, 
1600, 1600, 1600, 1600, 1700, 1700, 1700, 1700, 1700, 1800, 1800, 
1800, 1800, 1800, 1900, 1900, 1900, 1900, 1900, 2000, 2000, 2000, 
2000, 2000, 100, 100, 100, 100, 100, 200, 200, 200, 200, 200, 
300, 300, 300, 300, 300, 400, 400, 400, 400, 400, 500, 500, 500, 
500, 500, 600, 600, 600, 600, 600, 700, 700, 700, 700, 700, 800, 
800, 800, 800, 800, 900, 900, 900, 900, 900, 1000, 1000, 1000, 
1000, 1000, 1100, 1100, 1100, 1100, 1100, 1200, 1200, 1200, 1200, 
1200, 1300, 1300, 1300, 1300, 1300, 1400, 1400, 1400, 1400, 1400, 
1500, 1500, 1500, 1500, 1500, 1600, 1600, 1600, 1600, 1600, 1700, 
1700, 1700, 1700, 1700, 1800, 1800, 1800, 1800, 1800, 1900, 1900, 
1900, 1900, 1900, 2000, 2000, 2000, 2000, 2000, 100, 100, 100, 
100, 100), date = structure(c(18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 18270, 
18270, 18270, 18270, 18270, 18270, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 17182, 
17182, 17182, 17182, 17182, 17182, 17182, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 18302, 
18302, 18302, 18302, 18302, 18302, 18302, 18302, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 
18334, 18334, 18334, 18334, 18334, 18334, 18334, 18334, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 
17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230, 17230
), class = "Date"), Year = structure(c(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, 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, 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, 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, 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69002203, 39.46416636, 39.46416636, 39.73204192, 39.73204192, 
    39.73204192, 39.48439384, 39.48439384, 39.75312025, 39.75312025, 
    39.75312025, 39.49212885, 39.49212885, 39.77773065, 39.77773065, 
    39.77773065, 39.23692955, 39.23692955, 39.50876672, 39.50876672, 
    39.50876672, 39.2688776, 39.2688776, 39.5308463, 39.5308463, 
    39.5308463, 39.26009488, 39.26009488, 39.51862556, 39.51862556, 
    39.51862556, 39.23362907, 39.23362907, 39.49314495, 39.49314495, 
    39.49314495, 39.22544967, 39.22544967, 39.48686828, 39.48686828, 
    39.48686828, 39.22921385, 39.22921385, 39.49069941, 39.49069941, 
    39.49069941, 39.22121268, 39.22121268, 39.47842417, 39.47842417, 
    39.47842417, 39.25855237, 39.25855237, 39.5177284, 39.5177284, 
    39.5177284, 39.31654836, 39.31654836, 39.57357954, 39.57357954, 
    39.57357954, 39.29034224, 39.29034224, 39.54928469, 39.54928469, 
    39.54928469, 39.21842964, 39.21842964, 39.48037064, 39.48037064, 
    39.48037064, 39.18790111, 39.18790111, 39.43845258, 39.43845258, 
    39.43845258, 39.15256059, 39.15256059, 39.41036294, 39.41036294, 
    39.41036294, 39.11216125, 39.11216125, 39.36755125, 39.36755125, 
    39.36755125, 39.08030747, 39.08030747, 39.33167812, 39.33167812, 
    39.33167812, 39.12993955, 39.12993955, 39.39689619, 39.39689619, 
    39.39689619, 43.8048763, 43.8048763, 44.17214494, 44.17214494, 
    44.17214494, 43.77706328, 43.77706328, 44.14471764, 44.14471764, 
    44.14471764, 43.76715395, 43.76715395, 44.12919958, 44.12919958, 
    44.12919958, 43.6734276, 43.6734276, 44.03295273, 44.03295273, 
    44.03295273, 43.43969325, 43.43969325, 43.79043297, 43.79043297, 
    43.79043297, 43.46617317, 43.46617317, 43.82164862, 43.82164862, 
    43.82164862, 43.45817407, 43.45817407, 43.81200158, 43.81200158, 
    43.81200158, 43.49256715, 43.49256715, 43.86329877, 43.86329877, 
    43.86329877, 43.49382639, 43.49382639, 43.86636556, 43.86636556, 
    43.86636556, 43.48534435, 43.48534435, 43.85745411, 43.85745411, 
    43.85745411, 43.38213544, 43.38213544, 43.75286456, 43.75286456, 
    43.75286456, 43.3023932, 43.3023932, 43.6661483, 43.6661483, 
    43.6661483, 43.24328463, 43.24328463, 43.60471125, 43.60471125, 
    43.60471125, 43.09468321, 43.09468321, 43.44744563, 43.44744563, 
    43.44744563, 42.94489759, 42.94489759, 43.29081306, 43.29081306, 
    43.29081306, 42.85892867, 42.85892867, 43.19730725, 43.19730725, 
    43.19730725, 42.76776694, 42.76776694, 43.10273585, 43.10273585, 
    43.10273585, 42.68127243, 42.68127243, 43.01059651, 43.01059651, 
    43.01059651, 42.66140238, 42.66140238, 42.99118471, 42.99118471, 
    42.99118471, 43.70369864, 43.70369864, 44.07106004, 44.07106004, 
    44.07106004, 36.70611252, 36.70611252, 36.9107136, 36.9107136, 
    36.9107136, 36.72775555, 36.72775555, 36.92395327, 36.92395327, 
    36.92395327, 36.74749898, 36.74749898, 36.93449529, 36.93449529, 
    36.93449529, 36.6533153, 36.6533153, 36.83617274, 36.83617274, 
    36.83617274, 36.44506508, 36.44506508, 36.63608161, 36.63608161, 
    36.63608161, 36.43721713, 36.43721713, 36.62929251, 36.62929251, 
    36.62929251, 36.43733177, 36.43733177, 36.62324992, 36.62324992, 
    36.62324992, 36.43583453, 36.43583453, 36.61967969, 36.61967969, 
    36.61967969, 36.40827146, 36.40827146, 36.589868, 36.589868, 
    36.589868, 36.3907843, 36.3907843, 36.57116139, 36.57116139, 
    36.57116139, 36.35854057, 36.35854057, 36.54628954, 36.54628954, 
    36.54628954, 36.40712661, 36.40712661, 36.59210861, 36.59210861, 
    36.59210861, 36.43340117, 36.43340117, 36.60861537, 36.60861537, 
    36.60861537, 36.31455504, 36.31455504, 36.48974973, 36.48974973, 
    36.48974973, 36.22447072, 36.22447072, 36.39436863, 36.39436863, 
    36.39436863, 36.21140555, 36.21140555, 36.38112795, 36.38112795, 
    36.38112795, 36.19563266, 36.19563266, 36.35853431, 36.35853431, 
    36.35853431, 36.16204925, 36.16204925, 36.32527651, 36.32527651, 
    36.32527651, 36.16206731, 36.16206731, 36.3293186, 36.3293186, 
    36.3293186, 36.43714217, 36.43714217, 36.622595, 36.622595, 
    36.622595, 28.09393998, 28.09393998, 28.15452004, 28.15452004, 
    28.15452004, 28.05127491, 28.05127491, 28.10864511, 28.10864511, 
    28.10864511, 28.02972073, 28.02972073, 28.04448871, 28.04448871, 
    28.04448871, 28.03610704, 28.03610704, 28.04071712, 28.04071712, 
    28.04071712, 28.02902252, 28.02902252, 27.99060337, 27.99060337, 
    27.99060337, 28.05021483, 28.05021483, 28.01166398, 28.01166398, 
    28.01166398, 28.03387381, 28.03387381, 27.9922879, 27.9922879, 
    27.9922879, 27.96075552, 27.96075552, 27.90532568, 27.90532568, 
    27.90532568, 27.92236376, 27.92236376, 27.87621457, 27.87621457, 
    27.87621457, 27.88527292, 27.88527292, 27.87611205, 27.87611205, 
    27.87611205, 27.84768492, 27.84768492, 27.85894957, 27.85894957, 
    27.85894957, 27.83940352, 27.83940352, 27.84847982, 27.84847982, 
    27.84847982, 27.81627322, 27.81627322, 27.82635454, 27.82635454, 
    27.82635454, 27.7815786, 27.7815786, 27.77298566, 27.77298566, 
    27.77298566, 27.76044908, 27.76044908, 27.73830099, 27.73830099, 
    27.73830099, 27.74557724, 27.74557724, 27.73498831, 27.73498831, 
    27.73498831, 27.67807817, 27.67807817, 27.73279985, 27.73279985, 
    27.73279985, 27.68961021, 27.68961021, 27.7333632, 27.7333632, 
    27.7333632, 27.72383966, 27.72383966, 27.77542992, 27.77542992, 
    27.77542992, 27.94160345, 27.94160345, 27.97709364, 27.97709364, 
    27.97709364, 32.44370349, 32.44370349, 32.50556817, 32.50556817, 
    32.50556817, 32.36811356, 32.36811356, 32.43038012, 32.43038012, 
    32.43038012, 32.38152433, 32.38152433, 32.43476867, 32.43476867, 
    32.43476867, 32.36183697, 32.36183697, 32.40781406, 32.40781406, 
    32.40781406, 32.29013031, 32.29013031, 32.33402053, 32.33402053, 
    32.33402053, 32.33718591, 32.33718591, 32.3814359, 32.3814359, 
    32.3814359, 32.33472529, 32.33472529, 32.38747789, 32.38747789, 
    32.38747789, 32.3284777, 32.3284777, 32.38604191, 32.38604191, 
    32.38604191, 32.31624064, 32.31624064, 32.37249513, 32.37249513, 
    32.37249513, 32.30115037, 32.30115037, 32.35506708, 32.35506708, 
    32.35506708, 32.22876705, 32.22876705, 32.28006241, 32.28006241, 
    32.28006241, 32.16531796, 32.16531796, 32.21779251, 32.21779251, 
    32.21779251, 32.13354855, 32.13354855, 32.18199623, 32.18199623, 
    32.18199623, 32.04679917, 32.04679917, 32.08793194, 32.08793194, 
    32.08793194, 31.95865036, 31.95865036, 31.99349115, 31.99349115, 
    31.99349115, 31.89786652, 31.89786652, 31.92950005, 31.92950005, 
    31.92950005, 31.8230681, 31.8230681, 31.85623561, 31.85623561, 
    31.85623561, 31.746572, 31.746572, 31.78002994, 31.78002994, 
    31.78002994, 31.72857776, 31.72857776, 31.7725018, 31.7725018, 
    31.7725018, 32.4731662, 32.4731662, 32.53562016, 32.53562016, 
    32.53562016)), row.names = c(NA, 500L), class = "data.frame")
r anova rstatix

评论

0赞 Allan Cameron 7/12/2023
请提供足够的数据,以便我们运行您的代码并重现错误。目前,我们得到Error: Variable Month has only one level. Remove it from the model.
0赞 strangecharm 7/12/2023
还行。最好的方法是什么?我去了 dput(lst[1:500, ])
0赞 r2evans 7/12/2023
显然(可能由 )通过组合字符串来创建一个表达式,请参阅 github.com/kassambara/rstatix/blob/...。这在我看来既不合理也不安全。factorial_designanova_testcbind

答:

2赞 r2evans 7/12/2023 #1

BLUF:需要 和 中的因子,并使用这些值来形成名称,因此第一个 in 不得以数字开头。anova_testwid=within=within=

如何找到这个问题:

  1. 在源代码中查找,并看到该包通过字符串连接形成表达式(在 factorial_design 中找到)。当您不控制数据时,这通常是一个坏主意,您在这里的问题就是一个很好的例子。(我建议你根据这个问题提交错误报告cbind

  2. debugonce(factorial_design),然后评估您对 的调用。由于 中的字符串形成表达式使用 ,我们将逐步完成,直到定义为止。anova_testfactorial_designwide.dv.name

  3. 看值:

    wide.dv.name
    # [1] "100_1, 100_2, 1000_1, 1000_2, 1100_1, 1100_2, 1200_1, 1200_2, 1300_1, 1300_2, 1400_1, 1400_2, 1500_1, 1500_2, 1600_1, 1600_2, 1700_1, 1700_2, 1800_1, 1800_2, 1900_1, 1900_2, 200_1, 200_2, 2000_1, 2000_2, 300_1, 300_2, 400_1, 400_2, 500_1, 500_2, 600_1, 600_2, 700_1, 700_2, 800_1, 800_2, 900_1, 900_2"
    lm_formula
    # [1] "cbind(100_1, 100_2, 1000_1, 1000_2, 1100_1, 1100_2, 1200_1, 1200_2, 1300_1, 1300_2, 1400_1, 1400_2, 1500_1, 1500_2, 1600_1, 1600_2, 1700_1, 1700_2, 1800_1, 1800_2, 1900_1, 1900_2, 200_1, 200_2, 2000_1, 2000_2, 300_1, 300_2, 400_1, 400_2, 500_1, 500_2, 600_1, 600_2, 700_1, 700_2, 800_1, 800_2, 900_1, 900_2) ~ 1"
    

好吧,这显然不好,R 不喜欢以数字开头的变量。它们由 形成。wide

查看问题值等,这些值由 和 组成,您的参数为 。阅读 的文档,我们看到100_1bufferMonthwithin=anova_test

  within: (optional) within-subjects factor variables

我们的(和)不是因素。由于如果(形成的字符串的前导部分)以数字字符以外的字符开头,则不太可能发生此问题,因此我们将重点关注此问题。我们可以尝试形成一个(不改变内容),但我怀疑它是否有效,因为那里似乎没有任何验证代码可以区分数字和因子:bufferTimePeriodbufferfactor

c1_l1$bufferf <- factor(c1_l1$buffer)
res.aov <- anova_test(
  data = c1_l1, dv = value, wid = Month,
  within = c(bufferf, TimePeriod),
  effect.size = "ges",
  detailed = TRUE,
)
# Error in str2lang(x) : <text>:1:10: unexpected input
# 1: cbind(100_

好的,确认。让我们试着用一个字母作为前缀。我将快进进行以下更改:buffer

  • buffer:在字母前面加上一个字母并转换为因子
  • TimePeriod和 :转换为因子Month
c1_l1$buffer_chr <- factor(paste0("b", c1_l1$buffer))
c1_l1$TimePeriod_fct <- factor(c1_l1$TimePeriod)
c1_l1$Month_fct <- factor(c1_l1$Month)
res.aov <- anova_test(
  data = c1_l1, dv = value, wid = Month_fct,
  within = c(buffer_chr, TimePeriod_fct),
  effect.size = "ges",
  detailed = TRUE,
)
# Error in eigen(SSPE, only.values = TRUE)$values >= sqrt(.Machine$double.eps) : 
#   invalid comparison with complex values

但坦率地说,这是一个完全不同的错误,可以通过更完整的数据或通过分析/探索的其他方面来解决。

评论

0赞 strangecharm 7/12/2023
感谢您对正在发生的事情进行彻底的分析。当我阅读时,我想我可以用字母替换缓冲区数字,但这显然是行不通的。不过,我不明白为什么现在会发生这个错误,而以前没有?我是否应该尝试 RStatix 以外的其他软件包,它可能(应该)使用另一种底层方法?
0赞 strangecharm 7/12/2023
很高兴提交错误报告 - 我会在下周初提交。
1赞 r2evans 7/12/2023
我不知道为什么它以前没有犯错,但现在却犯了。我认为这个错误()的问题已经解决,祝你好运解决你的下一个问题。:-)cbind(100_
0赞 strangecharm 7/12/2023
替代包似乎是“car”和“ez”,还是基本 R?
0赞 strangecharm 7/12/2023
R对我来说只不过是下一个问题...... :)