问题描述
在寻找与R相关的解决方案时,我发现R和SPSS(版本24)在简单的线性模型中计算标准化残差时存在一些不一致之处.
While looking for a R related solution I found some inconsistency between R and SPSS (ver. 24) in computing standardized residuals in a simple linear model.
似乎SPSS所说的标准残差与R 学生残差
It appears that what SPSS calls standarized residuals matches R studentized residuals
我想假设某个地方存在软件错误,但显然这两个程序之间存在差异.
I'm far for assuming there is a software bug somewhere, but clearly things differ between those two programs.
看看这个例子
#generate data in R
set.seed(111)
y = rnorm(20, 0, 1)
x = rnorm(20, 1, 1)
#calculate and standarized residuals
zresid<- rstandard(lm(y ~ x))
sresid<- rstudent(lm( y ~ x))
#make data frame
sampleData <- data.frame(y, x, zresid, sresid)
#save data for SPSS
library(foreign)
write.foreign(sampleData, "~/sampleData.sav", package="SPSS")
然后,在SPSS中,在所有窗口中单击以导入数据,并设置保存的线性回归ZRE和SRE残差.
Then, in SPSS click your way through all the windows to import data and set up a linear regression ZRE and SRE residuals saved.
#load data to spss via syntax
GET DATA /TYPE=TXT
/FILE="~\sampleData.sav"
/DELCASE=LINE
/DELIMITERS=","
/ARRANGEMENT=DELIMITED
/FIRSTCASE=1
/DATATYPEMIN PERCENTAGE=95.0
/VARIABLES=
y F8.0
x F8.0
zresid F8.0
sresid F8.0
/MAP.
RESTORE.
#run a simple regression with standarized residuals (ZRESID) and studentized residuals (SRESID)
REGRESSION
/MISSING LISTWISE
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT y
/METHOD=ENTER x
/SAVE ZRESID SRESID.
我生气(或愚蠢)还是这里确实出了什么问题?
Am I mad (or dumb) or indeed something is wrong here?
推荐答案
我做了更多的事情:结论如下:
I did a bit more:Here are the conclusions:
r stats::rstandard = MASS::stdres = SPSS studentized residual
r z score of resid or residuals = SPSS z score of unstandardized residual
这是我的代码:
#generate data in R
set.seed(111)
y = rnorm(20, 0, 1)
x = rnorm(20, 1, 1)
#calculate and standarized residuals
stats_rstudent = stats::rstudent(lm( y ~ x))
stats_rstandard = stats::rstandard(lm(y ~ x))
MASS_stdres = MASS::stdres(lm( y ~ x))
scale_resid = as.vector(scale(resid(lm(y ~ x)),center=T,scale=T))
scale_residuals = as.vector(scale(residuals(lm(y ~ x)),center=T,scale=T))
#make data frame
sampleData <- data.frame(y, x, stats_rstudent, stats_rstandard, MASS_stdres, scale_resid, scale_residuals)
#save data for SPSS
library(foreign)
write.foreign(sampleData, "sampleData.sav", package="SPSS")
SPSS语法:
REGRESSION
/MISSING LISTWISE
/CRITERIA=PIN(.05) POUT(.10)
/NOORIGIN
/DEPENDENT y
/METHOD=ENTER x
/SAVE RESID ZRESID SRESID.
* calc z score of resid.
descriptives RES_1_Unstandardized_Residual/save.
formats stats_rstudent(f11.6).
formats stats_rstandard(f11.6).
formats MASS_stdres(f11.6).
formats scale_resid(f11.6).
formats scale_residuals(f11.6).
formats ZRE_1_Standardized_Residual(f11.6).
formats SRE_1Studentized_Residual(f11.6).
formats RES_1_Unstandardized_Residual(f11.6).
formats Zscore_RES_1_Unstandardized_Residual(f11.6).
这篇关于SPSS中的标准残差不进行R rstandard(lm())处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!