我试图使用WSR2包进行单向ANOVA引导 . 该函数需要矩阵或列表作为输入 . 我已经做了两个,我仍然得到矩阵或列表形式所需的数据错误 . 列表和矩阵是从数据框的两个变量进行的 . 一个是连续变量(年龄),一个是分组变量,它是原始数据框中的有序因子(响应性) . 我将因子转换为数字变量来构造列表和矩阵 . 我错误地构建了列表或矩阵吗?由于我对编码很陌生,因此无法找到解决方案源代码的解决方案 . (从这里你可以检索这个函数的源代码https://rdrr.io/rforge/WRS2/src/R/t1waybt.R

这里有一些关于这两个变量的信息 . 嗯,年龄只是参与者的年龄:) . 这些参与者可根据他们的响应能力分为3组 . 响应变量的“级别”是0,1和2.在0的组中有31个参与者;在该组中有1 120名参与者,在该组中有2 109名参与者 . 我想知道不同的群体是否按年龄顺序不同 .

这是我用来构建(a)矩阵和(b)列表的代码

#turning factor into numeric variable
Responders2 #ordered "responsiveness" factor from data frame
[1] 1 1 1 1 1 1 1 1 1 ... 
[107] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0...
[160] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2... 
Levels: 0 < 1 < 2

is.factor(Responders2)
[1] TRUE

Responders3 = c(0,1,2)[as.numeric(Responders2)] #turning ordered"responsiveness" factor into numeric variable for list or matrix

is.numeric(Responders3)
[1] TRUE

#(a) building matrix
Responsiveness_Age <- cbind(Age = c(Responding$Alter), Responsiveness =
c(Responders3))
Responsiveness_Age

   Age Responsiveness
[1,]  24         1
..........

[120,]  27       1
[121,]  60       0
.......
[151,]  27       0
[152,]  24       2
.......
[260,]  20       2


is.matrix(Responsiveness_Age) #checking if it really is recognized as a matrix
[1] TRUE

#using WRS2 function to conduct oneway ANOVA with bootstrapping and trimmed
means on matrix

library(WRS2)

t1waybt(Age ~ Responsiveness, Responsiveness_Age, tr = 0.2, nboot = 2000)

Error in t1waybt(Age ~ Responsiveness, Responsiveness_Age, tr = 0.2, nboot =
2000) : Data must be stored in a matrix or in list mode.

#(b) building a list
Responsiveness_Age1 <- list(Alter, Responders3) 
names(Responsiveness_Age1) <-c("Age", "Responsiveness")
typeof(Responsiveness_Age1$Age)
[1] "double"

typeof(Responsiveness_Age1$Responsiveness)
[1] "double"

as.integer(Responsiveness_Age1$Age)
[1] 24 25 24......

as.integer(Responsiveness_Age1$Responsiveness)
[1] 1 1 1.....
[107] ..... 0 0 0 0 0 0 0 0 0 0 0 0 0..... 2 2 2 2 2 2 2.....

typeof(Responsiveness_Age1$Age)
[1] "double"

typeof(Responsiveness_Age1$Responsiveness) #could it be, that the problem is evoked because the list elements are "double"?
[1] "double"

Responsiveness_Age1
$Age
[1] 24 25 24...
$Responsiveness
[1] 1 1 1 .....
[107] ...0 0 0 0 0 0 0 0 0 ......2 2 2 2 2 2......

is.list(Responsiveness_Age1)
[1] TRUE

#conducting one way ANOVA with trimmed means and bootstrap on list
t1waybt(Responsiveness ~ Age, Responsiveness_Age1, tr = 0.2, nboot = 2000)

Error in t1waybt(Responsiveness ~ Age, Responsiveness_Age1, tr = 0.2,  : 
Data must be stored in a matrix or in list mode.

谢谢你的任何提示!