问题
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.
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.
Have a look at this example
#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")
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?
回答1:
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
Here are my codes:
#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 syntax:
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).
回答2:
Not very familiar with SPSS, but I ran the model R and Stata, getting the same residuals. So the problem is on the SPSS end. My guess is that it looks like you have called a stepwise regression command in SPSS. Could you try simply:
REGRESSION
/DEPENDENT y
/METHOD=ENTER x
/SAVE ZRESID SRESID.
And see if that works?
回答3:
Following @JKP suggestion I went though SPSS Algorithm manual and on page 853 (Regression Algorithm chapter) we can find, that Standardized Residuals saved via simple regression analysis are computed as follows:
来源:https://stackoverflow.com/questions/40062482/standarized-residuals-in-spss-not-maching-r-rstandardlm