| Library: | stats |
| See also: | gls linreg linregfs |
| Macro: | linregres | |
| Description: | linregres computes some residual analysis for a linear regression. |
| Usage: | {res,out} = linregres (x, y, yh) | |
| Input: | ||
| x | n x p regressors | |
| y | n x 1 | |
| yh | n x 1 | |
| Output: | ||
| xfs | n x 4 | |
| out | n x 2 | |
; loads the library stats
library("stats")
; reset random generator
randomize(0)
; generate x
x = normal(100, 3)
; generate y
y = 10*x[,3]+x[,1].*x[,2]
; do the forward selection
{xfs,bfs}=linregfs(x, y, 0.05)
; compute residual number
{res,out}=linregres(xfs, y, xfs*bfs)
; create a display fro plotting
disp = createdisplay(2,2)
; show residual plots
; residuals leverage
; standardized residuals Cook distance
show (disp, 1, 1, y~res[,1])
show (disp, 2, 1, y~res[,3])
show (disp, 1, 2, y~res[,2])
show (disp, 2, 2, y~res[,4])
shows the residual plots. From the standardized residuals we find three points in the bottom with an absolute value larger than 3. The leverage plot shows on the right and the left sets of points with a leverage larger than 0.04 (thus they are influential). The Cook distance plot shows no datapoints larger than 1 and we can not find outliers in x.
| Library: | stats |
| See also: | gls linreg linregfs |