Date post: | 18-Dec-2015 |
Category: |
Documents |
Upload: | allan-freeman |
View: | 216 times |
Download: | 0 times |
Jian Chen 1
Presented by
Jian ChenPhD (Applied Statistics)
MS (Computer Science)
Sr. Statistician, Credigy
Statistical computing with SAS/IML
Jian Chen 2
SAS/IML
SAS Interactive Matrix Language:
Beyond!
Jian Chen 3
Outline
• Overview of SAS/IML.
• Language nuts and bolts.
• An example in Bayesian Analysis.
• Applications.
• References.
Jian Chen 4
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 5
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 6
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 7
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 8
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
)1(,...,...,1)()()(1
nttitYtYp
ii
0/1),0(~))'(),...,1(( 21 INn
Jian Chen 9
Priors• Bayes Approach:• Under the Normal-Gamma prior
where
)()|(),( 21
e12 )(
)()'(22/
1 )|(
Q
p e
Jian Chen 10
Loss Function• Modified Higgins-Tsokos loss function
where and C1 , C2 make the loss function continuous, that is:
0,, 21 aaa
ac
ac
aIfaa
eaea
L
aa
ˆ
ˆ
|-ˆ|1
),ˆ(
2
1
21
)-ˆ(2
)-ˆ(1
12
Jian Chen 11
Loss Function
1
1
21
212
21
211
12
12
aa
eaeac
aa
eaeac
aaaa
aaaa
Jian Chen 12
Loss Function
Jian Chen 13
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));
)2(
|)(|
~)('~'2
)|(
2/1'
2''
QXX
YYQXXQ
SWf
ff
kn
ffff
nk
Jian Chen 14
The k-step Bayes prediction
– where
– Others are the parameters in prior or matrix from n observations.
)'()'(~ 1 YXQXXQ
Jian Chen 15
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 16
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 .
• ……
)1(~ nY
)1(~ nY
)2(~ nY
Jian Chen 17
K-th step ahead forecasting
• The pdf of one-step ahead forecasting is:
nnnffn
nff
ff
YYQYXQXXQXYQc
QYXQXXXb
XQXXXa
where
nna
bac
a
btt
'''0
1''0
''
''0
1'
'1'
2
2
)())((2
)()(
)(1
)2,)2(
,(
Jian Chen 18
K-th step ahead forecasting• where t-distribution is defined as
)(
))(
1()2(
)21
()(~
),,(
2
12
xt
a
x
axfX
a
Jian Chen 19
Bayes estimate under MHT loss• Bayes expected loss:
dtcdtc
dtaa
eaea
dSpxYLx
axn
na
bac
a
b
ax
nna
bac
a
b
ax
ax nna
bac
a
b
xaxa
nn
)()(
)()1(
)|(),()(
)2,)2(
,(2
)2,)2(
,(1
)2,)2(
,(21
)-(2
)-(1
1
2
2
2
2
2
2
12
Jian Chen 20
Bayes estimate under MHT loss
– Bayes estimate (Bayes action) under MHT loss function.
)(min)1(ˆ xnYMHT
Jian Chen 21
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 22
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 23
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 24
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 25
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 26
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 27