logo

Standardizing Data in R: Viewing Standardized Residuals 📂R

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, $\mathbb{x} = ( 1, \cdots , 10 )$.

20190405\_102134.png 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.

20190405\_102338.png In reality, the above-standardized residuals are depicted as follows.

wrg.png

x<-1:10; x
z<-scale(x); z
c(z)
 
out<-lm(rating~.,data=attitude)
rstudent(out)
win.graph(); plot(rstudent(out),main='정규화된 잔차그림')