Standardizing Data in R: Viewing Standardized Residuals
Code
R is specialized for statistics, so there often comes a need to calculate the Z-score $\displaystyle z:= {{x - \mu} \over {\sigma}}$. For this, using the built-in scale()
function can be very convenient.
Let’s standardize a vector, for example, $\mathbf{x} = ( 1, \cdots , 10 )$.
If you dislike seeing messy outputs like center(mean) or scale(standard deviation), just take the vector.
On the other hand, one of the most common occurrences of standardization is when viewing residual plots after regression analysis. Of course, if you are somewhat familiar with R, it’s not too difficult to check standardized residuals, but using the rstudent()
function allows you to get the desired result in just one line.
In reality, the above-standardized residuals are depicted as follows.
x<-1:10; x
z<-scale(x); z
c(z)
out<-lm(rating~.,data=attitude)
rstudent(out)
win.graph(); plot(rstudent(out),main='정규화된 잔차그림')