Вы находитесь на странице: 1из 14

SAS/IML

Departemen Statistika Fakultas Matematika dan IPA 2013

Overview
SAS/IML software:
a powerful and exible programming language (Interactive Matrix Language) in a dynamic, interactive environment The object of the language is data matrix Interactively or store statements in a module Automatically memory allocation and dimensioning of matrix Access built-in operators and call routines Run user-defined modules Can read, create, and update SAS dataset

Overview
SAS/IML software:
a programming language operates on matrices possesses a powerful vocabulary of operators uses operators that apply to entire matrices is interactive is dynamic processes data produces graphics

Introductory Interactive Session


> proc iml; IML Ready /* begin IML session */

Introductory Interactive Session


> start approx(x); > y=1; > do until(w<1e-3); > z=y; > y=.5#(z+x/z); > w=abs(y-z); > end; > return(y); > finish approx; /* begin module */ /* initialize y */ /* begin do loop */ /* set z=y */ /* estimate square root */ /* compute change in estimate */ /* end do loop */ /* return approximation */ /* end module */

Introductory Interactive Session


> t=approx({3,5,7,9}); > print t; T 1.7320508 2.236068 2.6457513 3 > quit; Exiting IML /* call function APPROX */ /* print matrix */

Creating Matrix
a=12; a=. ; a=hi there; a="Hello";

x={1 2 3 4 5 6}; y={1,2,3,4,5}; z={1 2, 3 4, 5 6}; w=3#z;


a=sqrt(b); y=inv(x); r=rank(x);

A Module for System of Equations


3x1 x2 + 2x3 = 8 2x1 2x2 + 3x3 = 2 4x1 + x2 4x3 = 9

x = A1c

A Module for System of Equations


> a = {3 -1 2, > 2 -2 3, > 4 1 -4}; > c={8, 2, 9}; > x=inv(a)*c;

A Module for Linear Regression


Model Linier: y = Xb + e

Penduga koefisien regresi linier:

b = (XX)-1 (Xy)
b = inv(x`*x)*(x`*y);

A Module for Linear Regression


> x={1 1 1, > 1 2 4, > 1 3 9, > 1 4 16, > 1 5 25}; > y={1,5,9,23,36}; > b = inv(x*x )*(x*y); > yhat=x*b; > r=y-yhat; > sse=ssq(r); > dfe=nrow(x)-ncol(x); > mse=sse/dfe;

A Module for Linear Regression


> start regress; > xpxi=inv(t(x)*x); > beta=xpxi*(t(x)*y); > yhat=x*beta; > resid=y-yhat; > sse=ssq(resid); > n=nrow(x); > dfe=nrow(x)-ncol(x); > mse=sse/dfe; > cssy=ssq(y-sum(y)/n); > rsquare=(cssy-sse)/cssy; > print,"Regression Results", > sse dfe mse rsquare; > stdb=sqrt(vecdiag(xpxi)*mse); for Linear Regression > t=beta/stdb; > prob=1-probf(t#t,1,dfe); > print,"Parameter Estimates",, > beta stdb t prob; > print,y yhat resid; > finish regress; /* begin module */ /* inverse of XX */ /* parameter estimate */ /* predicted values */ /* residuals */ /* SSE */ /* sample size */ /* error DF */ /* MSE */ /* corrected total SS */ /* RSQUARE */

/* std of estimates */34 Chapter 3. Tutorial: A Module /* parameter t-tests */ /* p-values */

/* end module */

A Module for Linear Regression


> run regress; /* execute module */
SSE 6.4 Regression Results DFE MSE RSQUARE 2 3.2 0.9923518 Parameter Estimates STDB T 3.8366652 0.6255432 2.9237940 -1.094468 0.4780914 4.1833001

BETA 2.4 -3.2 2

PROB 0.5954801 0.3879690 0.0526691

A Module for Linear Regression


Y 1 5 9 23 36 YHAT 1.2 4 10.8 21.6 36.4 RESID -0.2 1 -1.8 1.4 -0.4

Вам также может понравиться