280 likes | 439 Views
Statistical computing with SAS/IML. Presented by Jian Chen PhD (Applied Statistics) MS (Computer Science) Sr. Statistician, Credigy. SAS/IML. SAS Interactive Matrix Language: Beyond!. Outline. Overview of SAS/IML. Language nuts and bolts. An example in Bayesian Analysis.
E N D
Statistical computing with SAS/IML Presented by Jian ChenPhD (Applied Statistics) MS (Computer Science) Sr. Statistician, Credigy Jian Chen
SAS/IML SAS Interactive Matrix Language: Beyond! Jian Chen
Outline • Overview of SAS/IML. • Language nuts and bolts. • An example in Bayesian Analysis. • Applications. • References. Jian Chen
Features of SAS/IML • The simple SAS/IML program: Proc iml; Print ‘Hello World!’; Quit; • Is a programming language operating on matrices. • Has a complete set of control statements. • Has a powerful vocabulary of operators. • Can use operators that apply to entire matrices. • Can be interactive. Jian Chen
Features of SAS/IML (2-2) • Many Base SAS functions are accessible from SAS/IML and has many built-in functions. • Can define function or subroutine and write the core algorithm. • Can call a C program (or Fortran, Cobol, PL/I programs) within SAS/IML via the module() functions (Windows only). Jian Chen
With SAS/IML • Edit existing SAS data sets or create new ones. • Access external files with an extensive set of data processing commands for data input and output. Jian Chen
Numerical Functions and Algorithms • Subroutines: • Outlier detection and robust regression. • Performs numerical integration of scalar functions in one dimension over infinite, connected semi-infinite, and connected finite intervals • Optimization: for minimizing or maximizing a continuous nonlinear function f = f(x) of n parameters. • Produce graphics with a powerful set of graphics commands (Need SAS/Graph). • Kalman Filters. • Time Series Analysis. • Wavelet Analysis. • Genetic Algorithms – Experimental. • Sparse Matrices – Experimental. Jian Chen
An example • Problem: Assume we know Y(1),…,Y(n), what are the future values: Y(n+1), Y(n+2), ……? • The p-th autoregressive model: AR(p) where Jian Chen
Priors • Bayes Approach: • Under the Normal-Gamma prior where Jian Chen
Loss Function • Modified Higgins-Tsokos loss function where and C1 , C2 make the loss function continuous, that is: Jian Chen
Loss Function Jian Chen
Loss Function Jian Chen
The k-step Bayes prediction • The Bayesian predictive density of Wk (k-step ahead Bayes forecasting) is where Wk=(Y(n+1),Y(n+2),…,Y(n+k) ) and Sn=(Y(1),…,Y(n)); Jian Chen
The k-step Bayes prediction • where • Others are the parameters in prior or matrix from n observations. Jian Chen
Example • For Hölfer sunspot data, the shape of the joint pdf of future two-step ahead forecasting is graphed using (14.1) Jian Chen
Practical k-step ahead forecasting • Get the one-step ahead forecasting . • Apply one-step ahead forecasting method again with (Y(1), Y(2), …, Y(n), ) to get . • …… Jian Chen
K-th step ahead forecasting • The pdf of one-step ahead forecasting is: Jian Chen
K-th step ahead forecasting • where t-distribution is defined as Jian Chen
Bayes estimate under MHT loss • Bayes expected loss: Jian Chen
Bayes estimate under MHT loss • Bayes estimate (Bayes action) under MHT loss function. Jian Chen
Simulation and Calculation with SAS • Based on the assumption on priors, simulate the parameters in model (7.1). • Generate AR(p) series. • Calculate the one-step ahead Bayes estimate under MHT loss function. • Calculate the two-step ahead Bayes estimate under MHT loss function. Jian Chen
Simulation and Calculation with SAS SAS techniques used: • Simulation • Time Series (model identification and calculation). • SAS/IML: • Import from/export to SAS dataset. Interface with other SAS PROCs. • Matrix calculation. • Integration. • Optimization. Jian Chen
Integration • CALL QUAD (result, "fun", points <, EPS=eps> <, PEAK=peak><, SCALE=scale> <, MSG=msg> <, CYCLES=cycles> ) ; • CALL QUAD ( r, "fun", points) < EPS=eps> < PEAK=peak> < SCALE=scale> < MSG=msg> < CYCLES=cycles> ; • The QUAD subroutine quad is a numerical integrator based on adaptive Romberg-type integration techniques. Refer to Rice (1973), Sikorsky (1982), Sikorsky and Stenger (1984), and Stenger (1973a, 1973b, 1978). Jian Chen
Optimization • Optimization: The IML procedure offers a set of optimization subroutines for minimizing or maximizing a continuous nonlinear function f = f(x) of n parameters, where x = (x1, ... ,xn)’: • NLPCG Conjugate Gradient Method • NLPDD Double Dogleg Method • NLPNMS Nelder-Mead Simplex Method • NLPNRA Newton-Raphson Method • NLPNRR Newton-Raphson Ridge Method • NLPQN (Dual) Quasi-Newton Method • NLPQUA Quadratic Optimization Method • NLPTR Trust-Region Method Jian Chen
Applications • “Computing Group Sequential Boundaries Using the Lan-DeMets Method with SAS”. • Sample size and power analysis. • SAS for Monte Carlo Studies: A Guide for Quantitative Researchers: By Xitao Fan, Akos Felsovalyi, Stephen A. Sivo, and Sean C. Keenan: http://support.sas.com/publishing/bbu/companion_site/57323.html • A collection of SAS macro programs using SAS/IML software to generate, randomize and inspect orthogonal arrays for computer experiments and integration. http://sunsite.univie.ac.at/statlib/designs/oa.SAS Jian Chen
References • Jian Chen, Bayes Inferences and forecasting of Time Series, PhD thesis, UNC Charlotte. • SAS Online Documentation for SAS/IML: http://support.sas.com/onlinedoc/913/docMainpage.jsp • Sample programs installed with your installation: Located in directory: C:\Program Files\SAS\ SAS 9.1 \iml\sample Jian Chen