我正在尝试在单向 MANOVA 中计算平方和叉积矩阵 (W) 的范围内和总和。我有一个治疗矩阵tm:
n x1 x2
1 6 7
1 5 9
1 8 6
...
2 3 3
2 1 6
2 2 3
...
3 2 3
3 2 3
3 5 1
...
我还在自己的变量中拥有每个单独的观察结果,例如:
x111 = x[1,1]
x112 = x[2,1]
...
这也在创建向量的变量中:
# creating vectors
t11 = c(x111, x111_2) # 6,7
t12 = c(x112, x112_2) # 5,9
t13 = c(x113, x113_2) # 8,6
t14 = c(x114, x114_2) # 4,9
t15 = c(x115, x115_2) # 7,9
t21 = c(x211, x211_2) # 3,3
t22 = c(x212, x212_2) # 1,6
t23 = c(x213, x213_2) # 2,3
t31 = c(x311, x311_2) # 2,3
t32 = c(x312, x312_2) # 5,1
t33 = c(x313, x313_2) # 3,1
t34 = c(x314, x314_2) # 2,3
>dput(t11)
c(6,7)
我正在尝试计算 W(平方和叉积矩阵的内和总和)。
手段是
> x1 # treatment 1
[1] 6 8
> x2 # treatment 2
[1] 2 4
> x3 # treatment 3
[1] 3 2
> x # overall mean
X1 X2
[1,] 4 5
我的代码是:
W = (t(t11)-t(x1))*(t11-x1)
+(t(t12)-t(x1))%*%(t12-x1)
+(t(t13)-t(x1))%*%(t13-x1)
+(t(t14)-t(x1))%*%(t14-x1)
+(t(t15)-t(x1))%*%(t15-x1)
+(t(t21)-t(x2))%*%(t21-x2)
+(t(t22)-t(x2))%*%(t22-x2)
+(t(t23)-t(x2))%*%(t23-x2)
+(t(t31)-t(x3))%*%(t31-x3)
+(t(t32)-t(x3))%*%(t32-x3)
+(t(t33)-t(x3))%*%(t33-x3)
+(t(t34)-t(x3))%*%(t34-x3)
我得到的结果是:
Error in (t(t11) - t(x1)) * (t11 - x1) + (t(t12) - t(x1)) %*% :
non-conformable arrays
当我隔离每个语句时,我得到了这个:
> (t(t11)-t(x1))%*%(t11-x1)
[,1]
[1,] 1
> (t(t12)-t(x1))%*%(t12-x1)
[,1]
[1,] 2
为什么这些语句评估为 1x1 矩阵?当我手动计算 2x1 和 1x2 运算(减法和乘法)时,我得到的都是 2x2。这是一个在线计算器