在 SPSS 中运行重复测量方差分析时,可以在数据编辑器中将残差“保存”为新变量。
但是输出的值与 R 中给出的残差不匹配,并且似乎是主体间模型的残差。除非我错过了什么?SPSS是否给出了错误的残差?
R中的示例:
set.seed(1) # hopefully this keeps things the same every time!
# create a data frame with each line representing one subject,
# and create first and second observations for some experiment
DF <- data.frame(participant=factor(1:5), first=rnorm(5, 10, 5), second=rnorm(5, 20, 5))
DF
-
participant first second
1 1 6.867731 15.89766
2 2 10.918217 22.43715
3 3 5.821857 23.69162
4 4 17.976404 22.87891
5 5 11.647539 18.47306
-
# reshape it for an ANOVA in R
DFlong <- reshape(DF, direction="long", varying=c("first", "second"), v.names="value", idvar="participant", times=c(1, 2), timevar="group")
DFlong
-
participant group value
1.1 1 1 6.867731
2.1 2 1 10.918217
3.1 3 1 5.821857
4.1 4 1 17.976404
5.1 5 1 11.647539
1.2 1 2 15.897658
2.2 2 2 22.437145
3.2 3 2 23.691624
4.2 4 2 22.878907
5.2 5 2 18.473058
-
my.aov <- aov(value ~ group + Error( participant / group ), DFlong)
summary(my.aov)
-
Error: participant
Df Sum Sq Mean Sq F value Pr(>F)
Residuals 4 86.474 21.619
Error: participant:group
Df Sum Sq Mean Sq F value Pr(>F)
group 1 251.469 251.469 19.871 0.01118 *
Residuals 4 50.619 12.655
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
-
my.aov$"participant:group"$residuals
-
6 7 8 9 10
0.7066837 -1.0533061 -5.5440267 3.6252135 -2.2654355
-
# import into SPSS:
write.table(DF, "C:/test.txt", row.names=FALSE)
然后加载 SPSS,并运行:
GET DATA /TYPE = TXT
/FILE = 'C:\test.txt'
/DELCASE = LINE
/DELIMITERS = " "
/QUALIFIER = '"'
/ARRANGEMENT = DELIMITED
/FIRSTCASE = 2
/IMPORTCASE = ALL
/VARIABLES =
participant F1.0
first F16.14
second F16.13
.
CACHE.
EXECUTE.
DATASET NAME DataSet1 WINDOW=FRONT.
现在将变量类型更改为缩放(在“变量”选项卡中 - 我不知道此语法)。然后运行:
GLM
first second
/WSFACTOR = factor1 2 Polynomial
/METHOD = SSTYPE(3)
/SAVE = RESID
/CRITERIA = ALPHA(.05)
/WSDESIGN = factor1 .
或者,使用 GUI 执行上述 SPSS 命令:File->Read text data... 找到 C:\test.txt,导入它,记得指定文件具有变量名称作为第一个 case,然后运行:
分析->一般线性模型->重复测量...
将级别数设置为 2
将变量放入分析中,“第一”和“第二”。
打开“保存...”对话框,选中“残差->未标准化”
运行分析,SPSS 创建两个残差变量:
RES_1 RES_2 -3.78 -4.78 .27 1.76 -4.82 3.02 7.33 2.20 1.00 -2.20
请注意,这些值与 R 不同。那么 SPSS 是否弄错了?