我试图在一个形状数据集('数据')上运行一个manova,并使用一个独立的变量' river'有两个级别,' brazos'和'科罗拉多'。
data = structure(list(spec_num = 0:5, river = structure(c(1L, 1L, 1L,
1L, 1L, 1L), .Label = c("brazos", "colorado"), class = "factor"),
centroid = c(0.0196, 0.0244, 0.0245, 0.0211, 0.0255, 0.0295
), X1 = c(0.0123, 0.0056, 0.01715, 0.00763, 0.01647, 0.02392
), Y1 = c(0.00749, 0.00754, 0.00231, -0.00406, -3e-05, -0.01343
), X2 = c(0.00174, 0.01158, -0.01094, -0.00438, -0.00808,
0.00679), Y2 = c(-0.00735, -0.00205, 0.00333, -0.00293, 0.00615,
-0.00655), X3 = c(-0.00234, -0.01664, 0.00195, -0.01521,
-0.01525, -0.00034), Y3 = c(0.00666, 0.00079, 0.00865, 0.00503,
0.00223, -0.00031), X4 = c(0.00063, -0.00042, 0.00162, -0.00236,
0.00073, -4e-04), Y4 = c(0.0021, -0.00388, -0.00502, -0.00913,
0.00199, 0.01004), X5 = c(-0.00558, 0.00398, -0.00577, -0.00193,
-0.00024, 0.00619), Y5 = c(0.00281, 0.00569, -0.0016, 0.00274,
0.00182, -0.00261), X6 = c(0.00287, -0.00447, 0.00445, -0.00033,
-0.00293, 0.00219), Y6 = c(-0.00403, -0.00169, 0.00419, 0.00416,
-0.00347, 0.00222), X7 = c(-0.00328, 0.00196, 0.00242, -0.00038,
-0.00251, 0.00301), Y7 = c(-0.00065, 0.00082, 0.00287, -0.00213,
0.00324, 0.00317), X8 = c(0.00163, 0.00244, -0.00035, -0.00085,
0.00028, 0.00075), Y8 = c(0.00029, 0.00028, 0.00195, -0.00141,
-0.00322, -0.00032), X9 = c(-0.00011, -0.00011, -0.00104,
-0.00024, -0.0021, -0.00273), Y9 = c(-9e-05, 0.00098, 0.00215,
-0.00057, -0.00091, 0.00088), X10 = c(-0.00047, 0.00074,
-0.00096, 0.00013, -0.00017, -0.00036), Y10 = c(-5e-05, -1e-04,
-0.00162, -4e-05, 0.00011, -0.00011)), .Names = c("spec_num",
"river", "centroid", "X1", "Y1", "X2", "Y2", "X3", "Y3", "X4",
"Y4", "X5", "Y5", "X6", "Y6", "X7", "Y7", "X8", "Y8", "X9", "Y9",
"X10", "Y10"), row.names = c(NA, 6L), class = "data.frame")
然而,当我制作线性模型时,我得到了这个:
library(car)
shape = as.matrix(data[4:23])
model3 = lm(shape ~ river, data = data, contrasts(river))
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
我已经检查过NAs,
水平(数据$河)
返回,
[1] "brazos" "colorado"
所以我不明白可能会发生什么。我想我可能会补充一下&#39; brazos&#39;是19,而科罗拉多&#39;是20,但我认为这不应该导致错误。谢谢你的帮助!