{ From user Lonnie, Model Using_regression at Thu, Aug 30, 2007 11:14 AM~~ } Softwareversion 4.0.0 { System Variables with non-default values: } {!40000|Att_previndexvalue Run: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16~~ ,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39~~ ,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62~~ ,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85~~ ,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100]} Typechecking := 1 Checking := 1 Saveoptions := 2 Savevalues := 0 Attribute Reference Attribute Date_bough Askattribute Recursive,Function,Yes Model Using_regression Title: Using Regression Description: Analytica User Group Webinar : Using Regression~ ~ Regression analysis is a statistical technique for curve fitting, dis~~ covering relationships in data, and testing hypotheses between variab~~ les. In this webinar, I will focus on generalized linear regression, ~~ which is provided by Analytica's Regression function, and examine man~~ y ways in which is can be used, including fitting simple lines to dat~~ a, polynomial regression, use of other non-linear terms, and fitting ~~ of autoregressive models (e.g., ARMA). I'll examine how we can assess~~ how likely it is the data might have been generated from the particu~~ lar form of the regression model used. We can also determine the leve~~ l of uncertainty in our inferred parameter values, and incorporate th~~ ese uncertainties into a model that uses the result of the regression~~ . The talk will cover Analytica 4.0 functions Regression, RegressionD~~ ist, RegressionFitProb, and RegressionNoise. ~ Author: Lonnie Chrisman, Ph.D.~ Lumina Decision Systems Date: Thu, Aug 30, 2007 9:42 AM Saveauthor: Lonnie Savedate: Thu, Aug 30, 2007 11:14 AM Defaultsize: 48,24 Diagstate: 1,1,0,853,580,17 Windstate: 2,24,31,536,410 Fontstyle: Arial, 15 Fileinfo: 0,Model Using_regression,2,2,0,0,W:\TestModels\Using Regress~~ ion.ANA Index Date1 Title: date Definition: [37.623K,37.624K,37.625K,37.628K,37.629K,37.63K,37.631K,37~~ .632K,37.636K,37.637K,37.638K,37.639K,37.642K,37.643K,37.644K,37.645K~~ ,37.646K,37.649K,37.65K,37.651K,37.652K,37.653K,37.656K,37.657K,37.65~~ 8K,37.659K,37.66K,37.663K,37.664K,37.665K,37.666K,37.667K,37.671K,37.~~ 672K,37.673K,37.674K,37.677K,37.678K,37.679K,37.68K,37.681K,37.684K,3~~ 7.685K,37.686K,37.687K,37.688K,37.691K,37.692K,37.693K,37.694K,37.695~~ K,37.698K,37.699K,37.7K,37.701K,37.702K,37.705K,37.706K,37.707K,37.70~~ 8K,37.709K,37.712K,37.713K,37.714K,37.715K,37.719K,37.72K,37.721K,37.~~ 722K,37.723K,37.726K,37.727K,37.728K,37.729K,37.73K,37.733K,37.734K,3~~ 7.735K,37.736K,37.737K,37.74K,37.741K,37.742K,37.743K,37.744K,37.747K~~ ,37.748K,37.749K,37.75K,37.751K,37.754K,37.755K,37.756K,37.757K,37.75~~ 8K,37.761K,37.762K,37.763K,37.764K,37.765K,37.769K,37.77K,37.771K,37.~~ 772K,37.775K,37.776K,37.777K,37.778K,37.779K,37.782K,37.783K,37.784K,~~ 37.785K,37.786K,37.789K,37.79K,37.791K,37.792K,37.793K,37.796K,37.797~~ K,37.798K,37.799K,37.8K,37.803K,37.804K,37.806K,37.807K,37.81K,37.811~~ K,37.812K,37.813K,37.814K,37.817K,37.818K,37.819K,37.82K,37.821K,37.8~~ 24K,37.825K,37.826K,37.827K,37.828K,37.831K,37.832K,37.833K,37.834K,3~~ 7.835K,37.838K,37.839K,37.84K,37.841K,37.842K,37.845K,37.846K,37.847K~~ ,37.848K,37.849K,37.852K,37.853K,37.854K,37.855K,37.856K,37.859K,37.8~~ 6K,37.861K] Nodelocation: 96,64,1 Nodesize: 48,24 Numberformat: 2,DD,2,2,0,0,2,0,$,0,"ABBREV",0 {!40000|Att_previndexvalue: [37.623K,37.624K,37.625K,37.628K,37.629K,~~ 37.63K,37.631K,37.632K,37.636K,37.637K,37.638K,37.639K,37.642K,37.643K~~ ,37.644K,37.645K,37.646K,37.649K,37.65K,37.651K,37.652K,37.653K,37.656K~~ ,37.657K,37.658K,37.659K,37.66K,37.663K,37.664K,37.665K,37.666K,37.667K~~ ,37.671K,37.672K,37.673K,37.674K,37.677K,37.678K,37.679K,37.68K,37.681K~~ ,37.684K,37.685K,37.686K,37.687K,37.688K,37.691K,37.692K,37.693K,37.694K~~ ,37.695K,37.698K,37.699K,37.7K,37.701K,37.702K,37.705K,37.706K,37.707K~~ ,37.708K,37.709K,37.712K,37.713K,37.714K,37.715K,37.719K,37.72K,37.721K~~ ,37.722K,37.723K,37.726K,37.727K,37.728K,37.729K,37.73K,37.733K,37.734K~~ ,37.735K,37.736K,37.737K,37.74K,37.741K,37.742K,37.743K,37.744K,37.747K~~ ,37.748K,37.749K,37.75K,37.751K,37.754K,37.755K,37.756K,37.757K,37.758K~~ ,37.761K,37.762K,37.763K,37.764K,37.765K,37.769K,37.77K,37.771K,37.772K~~ ,37.775K,37.776K,37.777K,37.778K,37.779K,37.782K,37.783K,37.784K,37.785K~~ ,37.786K,37.789K,37.79K,37.791K,37.792K,37.793K,37.796K,37.797K,37.798K~~ ,37.799K,37.8K,37.803K,37.804K,37.806K,37.807K,37.81K,37.811K,37.812K~~ ,37.813K,37.814K,37.817K,37.818K,37.819K,37.82K,37.821K,37.824K,37.825K~~ ,37.826K,37.827K,37.828K,37.831K,37.832K,37.833K,37.834K,37.835K,37.838K~~ ,37.839K,37.84K,37.841K,37.842K,37.845K,37.846K,37.847K,37.848K,37.849K~~ ,37.852K,37.853K,37.854K,37.855K,37.856K,37.859K,37.86K,37.861K]} Variable Stock_price Title: Stock Price Description: Data used for regression demonstration.~ The data here is the stock price of AAPL since the beginning of the y~~ ear. Definition: Table(Date1)(~ 83.8,85.66,85.05,85.47,92.56999999999999,97,95.8,94.62000000000001,97~~ .09999999999999,94.95,89.06999999999999,88.5,86.79000000000001,85.7,8~~ 6.7,86.25,85.38,85.94,85.55,85.73,84.74,84.75,83.94,84.15000000000001~~ ,86.15000000000001,86.18000000000001,83.27,84.88,84.7,85.3,85.2099999~~ 9999999,84.83,85.90000000000001,89.2,89.51000000000001,89.06999999999~~ 999,88.51000000000001,83.93000000000001,84.61,87.06,85.41,86.31999999~~ 999999,88.19,87.72,88,87.97,89.87000000000001,88.40000000000001,90,89~~ .56999999999999,89.59,91.13,91.48,93.87000000000001,93.95999999999999~~ ,93.52,95.84999999999999,95.45999999999999,93.24,93.75,92.91,93.65000~~ 000000001,94.5,94.27,94.68000000000001,93.65000000000001,94.25,92.59,~~ 92.19,90.24,91.43000000000001,90.34999999999999,90.40000000000001,90.~~ 27,90.97,93.51000000000001,93.24,95.34999999999999,98.84,99.92,99.8,9~~ 9.47,100.39,100.4,100.81,103.92,105.06,106.88,107.34,108.74,109.36,10~~ 7.52,107.34,109.44,110.02,111.98,113.54,112.89,110.69,113.62,114.35,1~~ 18.77,121.19,118.4,121.33,122.67,123.64,124.07,124.49,120.19,120.38,1~~ 17.5,118.75,120.5,125.09,123.66,121.55,123.9,123,122.34,119.65,121.89~~ ,120.56,122.04,121.26,127.17,132.75,132.3,130.33,132.35,132.39,134.07~~ ,137.73,138.1,138.91,138.12,140,143.75,143.7,134.89,137.26,146,143.85~~ ,141.43,131.76,135,136.49,131.85,135.25,135.03,134.01,126.39,125,127.~~ 79,124.03,119.9,117.05,122.06,122.22,127.57,132.51,131.07,135.3,132.2~~ 5,126.82,134.08) Nodelocation: 208,64,1 Nodesize: 48,24 Defnstate: 2,607,68,416,303,0,MIDM Valuestate: 2,28,11,829,604,1,MIDM Variable Lr_basis Title: LR Basis Definition: Table(Self)(~ 1,@date1) Indexvals: ['b','m'] Nodelocation: 96,136,1 Nodesize: 48,24 Defnstate: 2,56,250,416,303,0,MIDM Valuestate: 2,40,50,571,568,0,MIDM Reformval: [Self,Date1] Chance Lr_c Title: LR c Definition: RegressionDist( stock_price, LR_Basis, date1, LR_Basis ) Nodelocation: 208,136,1 Nodesize: 48,24 Valuestate: 2,87,58,615,485,1,SAMP Reformval: [Undefined,Undefined,Undefined,Undefined,1] {!40000|Att_resultslicestate: [Lr_basis,2,Sys_localindex('STEP'),1]} {!40000|Att_coordinateindex: Lr_basis} Chance Lr_stock_price Title: LR Stock Price Definition: sum( Lr_c * Lr_basis, Lr_basis ) + normal(0,LR_Noise) Nodelocation: 320,136,1 Nodesize: 48,24 Valuestate: 2,131,58,730,560,1,CONF Reformval: [Date1,Undefined,2] Variable Compare1 Definition: [STOCK_PRICE,LR_STOCK_PRICE] Indexvals: ['Stock Price','LR Stock Price'] Nodelocation: 440,72,1 Nodesize: 48,24 Nodeinfo: 1,1,1,1,1,1,0,0,0,0 Valuestate: 2,120,130,679,429,1,CONF Reformval: [Date1,Self,2] Att__totalsindex: Variable Self {!40000|Att_previndexvalue: [Stock_price,Lr_stock_price]} {!40000|Att_resultslicestate: [Self,-1,Sys_localindex('PROBABILITY'),1~~ ,Date1,1]} Variable R Title: R Definition: Correlation(Stock_price,@date1,date1) Nodelocation: 440,136,1 Nodesize: 48,24 Variable Cr_basis Title: CR Basis Definition: Index K := "c" & 0..3;~ @date1 ^ (@K-1) Nodelocation: 96,240,1 Nodesize: 48,24 Reformval: [Date1,Sys_localindex('K')] Chance Cr_c Title: CR c Definition: RegressionDist(Stock_price,Cr_basis,Date1,Cr_basis.K) Nodelocation: 208,240,1 Nodesize: 48,24 Chance Cr_stock_price Title: CR Stock Price Definition: Normal( sum( Cr_c * Cr_basis, Cr_basis.K ), Cr_noise ) Nodelocation: 320,240,1 Nodesize: 48,24 Valuestate: 2,184,194,416,303,1,MIDM Variable Compare2 Definition: [STOCK_PRICE,CR_STOCK_PRICE] Indexvals: ['Stock Price','CR Stock Price'] Nodelocation: 440,240,1 Nodesize: 48,24 Nodeinfo: 1,1,1,1,1,1,0,0,0,0 Valuestate: 2,76,51,766,569,1,CONF Reformval: [Date1,Self] Att__totalsindex: Variable Self {!40000|Att_previndexvalue: [Stock_price,Cr_stock_price]} {!40000|Att_resultslicestate: [Self,-1,Sys_localindex('PROBABILITY'),1~~ ,Date1,1]} Constant Window_size Title: Window size Definition: 10 Nodelocation: 96,344,1 Nodesize: 48,24 Index Ar_k Title: AR K Definition: 0..Window_size Nodelocation: 208,344,1 Nodesize: 48,24 {!40000|Att_previndexvalue: [0,1,2,3,4,5,6,7,8,9,10]} Variable Ar_basis Title: AR Basis Definition: if AR_K=0 then 1~ else Stock_price[@date1 = @[Date1=Ar_I] - Ar_k] Nodelocation: 312,344,1 Nodesize: 48,24 Valuestate: 2,30,37,860,533,0,MIDM Reformval: [Ar_k,Ar_i] Index Ar_i Title: AR I Definition: subset( @date1>window_size) Nodelocation: 96,408,1 Nodesize: 48,24 Numberformat: 2,DD,2,2,0,0,4,0,$,0,"ABBREV",0 {!40000|Att_previndexvalue: [37.638K,37.639K,37.642K,37.643K,37.644K,37.645K~~ ,37.646K,37.649K,37.65K,37.651K,37.652K,37.653K,37.656K,37.657K,37.658K~~ ,37.659K,37.66K,37.663K,37.664K,37.665K,37.666K,37.667K,37.671K,37.672K~~ ,37.673K,37.674K,37.677K,37.678K,37.679K,37.68K,37.681K,37.684K,37.685K~~ ,37.686K,37.687K,37.688K,37.691K,37.692K,37.693K,37.694K,37.695K,37.698K~~ ,37.699K,37.7K,37.701K,37.702K,37.705K,37.706K,37.707K,37.708K,37.709K~~ ,37.712K,37.713K,37.714K,37.715K,37.719K,37.72K,37.721K,37.722K,37.723K~~ ,37.726K,37.727K,37.728K,37.729K,37.73K,37.733K,37.734K,37.735K,37.736K~~ ,37.737K,37.74K,37.741K,37.742K,37.743K,37.744K,37.747K,37.748K,37.749K~~ ,37.75K,37.751K,37.754K,37.755K,37.756K,37.757K,37.758K,37.761K,37.762K~~ ,37.763K,37.764K,37.765K,37.769K,37.77K,37.771K,37.772K,37.775K,37.776K~~ ,37.777K,37.778K,37.779K,37.782K,37.783K,37.784K,37.785K,37.786K,37.789K~~ ,37.79K,37.791K,37.792K,37.793K,37.796K,37.797K,37.798K,37.799K,37.8K~~ ,37.803K,37.804K,37.806K,37.807K,37.81K,37.811K,37.812K,37.813K,37.814K~~ ,37.817K,37.818K,37.819K,37.82K,37.821K,37.824K,37.825K,37.826K,37.827K~~ ,37.828K,37.831K,37.832K,37.833K,37.834K,37.835K,37.838K,37.839K,37.84K~~ ,37.841K,37.842K,37.845K,37.846K,37.847K,37.848K,37.849K,37.852K,37.853K~~ ,37.854K,37.855K,37.856K,37.859K,37.86K,37.861K]} Variable Ar_y Title: AR Y Definition: Stock_price[Date1=Ar_i] Nodelocation: 424,344,1 Nodesize: 48,24 Valuestate: 2,162,170,694,436,1,MIDM Chance Ar_c Title: AR c Definition: RegressionDist(Ar_y,Ar_basis,Ar_i,Ar_k) Nodelocation: 312,408,1 Nodesize: 48,24 Chance Ar_stock_price Title: AR Stock Price Definition: Normal(Sum( Ar_c * Ar_basis,Ar_k ), Ar_noise ) Nodelocation: 424,408,1 Nodesize: 48,24 Valuestate: 2,56,66,416,303,1,MIDM Variable Compare3 Definition: [AR_Y,AR_STOCK_PRICE] Indexvals: ['AR Y','AR Stock Price'] Nodelocation: 544,408,1 Nodesize: 48,24 Nodeinfo: 1,1,1,1,1,1,0,0,0,0 Valuestate: 2,17,31,801,547,1,CONF Reformval: [Ar_i,Self] Att__totalsindex: Variable Self {!40000|Att_previndexvalue: [Ar_y,Ar_stock_price]} {!40000|Att_resultslicestate: [Self,-1,Sys_localindex('PROBABILITY'),1~~ ,Ar_i,1]} Library Multivariate_distrib Title: Multivariate Distributions Description: A library of multivariate distributions.~ ~ In a multivariate distribution, each sample is a vector. This vector~~ is identified by an index, identified by the I parameter of the func~~ tions in this library. A Mid value from a distribution function will~~ therefore be indexed by I, whlie a Sample from a distribution functi~~ on is indexed by both I and Run. These distribution functions can al~~ so be used from within the Random function to generate a single monte~~ -carlo sample, which will be indexed by I.~ ~ This library also contains functions for generating correlated distri~~ butions. Correlate_with, for example, allows you to generate a univa~~ rite distribution with an arbitrary marginal distribution that has a ~~ specified rank correlation with an arbitrary reference distribution. ~~ Several functions may be used for generating serial correlations, w~~ here each distribution along an index is correlated with the previous~~ point along that index. Author: Lonnie Chrisman, Ph.D.~ Lumina Decision Systems~ ~ With contributions by:~ John Bowers, US FDA.~ Max Henrion, Lumina Decision Systems Date: Fri, Aug 01, 2003 7:12 PM Saveauthor: Lonnie Savedate: Thu, Jul 26, 2007 8:47 PM Defaultsize: 48,24 Nodelocation: 768,72,0 Nodesize: 56,32 Nodeinfo: 1,1,1,1,1,1,0,0,0,0 Diagstate: 1,42,10,649,1076,17 Windstate: 2,401,199,483,316 Function Regressiondist( Y : Numeric[I] ; B : Numeric[I,K] ; I,K : Ind~~ ex; C : optional Numeric[K] ;~ S : optional Numeric[I,Run] ;~ singleSampleMethod : optional hidden scalar ) Title: RegressionDist(Y,B,I,K) Description: RegressionDist returns linear regression coefficients as ~~ a distribution.~ ~ Suppose you have data where Y was produced as:~ Y = Sum( C*B, K ) + Normal(0,S)~ ~ S is the measurement noise. You have the data (B[I,K] and Y[I]). Yo~~ u might or might not know the measurement noise S. So you perform a ~~ linear regression to obtain an estimate of C. Because your estimate ~~ is obtained from a finite amount of data, your estimate of C is itsel~~ f uncertain. This function returns the coefficients C as a distribut~~ ion (i.e., in Sample mode, it returns a sampling of coefficients inde~~ xed by Run and K), reflecting the uncertainty in the estimation of th~~ ese parameters.~ ~ If you know the noise level S in advance, then you can use historical~~ data as a starting point for building a predictive model of Y, as fo~~ llows:~ ~ { Your model of the dependent variables: }~ Variable Y := your historical dependent data, indexed by I~ Variable B := your historical independent data, indexed by I,K~ Variable X := { indexed by K. Maybe others. Possibly uncertain }~ Variable S := { the known noise level }~ Chance C := RegressionDist(Y,B,I,K)~ Variable Predicted_Y := Sum(C*X,K) + Normal(0,S)~ ~ If you don't know the noise level, then you need to estimate it. You'~~ ll need it for the normal term of Predicted_Y anyway, and you'll need~~ to do a regression to find it. So you can pass these optional param~~ eters into RegressionDist. The last three lines above become:~ Variable E_C := Regression(Y,B,I,K)~ Variable S := RegressionNoise( Y,B,I,K,E_C )~ Chance C := RegressionDist(Y,B,I,K,E_C)~ Variable Predicted_Y := Sum(C*X,K) + Normal(0,S)~ ~ If you use RegressionNoise to compute S, you should use Mid(Regressio~~ nNoise(...)) for the S parameter. However, when computing S for your~~ prediction, don't RegressionNoise in context. Better is if you don'~~ t know the measurement noise in advance, don't supply it as a paramet~~ er. Definition: if IsNotSpecified(C) Then C := Regression(Y,B,I,K);~ If IsNotSpecified(S) Then S := Mid(RegressionNoise(Y,B,I,K,C))~ Else S:=Mean(S);~ Index K2 := K;~ var cv := Invert( Sum( B*B[K=K2]/S^2,I),K,K2);~ cv := Average( [cv,Transpose(cv,K,K2)]); {for round off errs}~ ~ Gaussian(C,cv,K,K2,singleSampleMethod:singleSampleMethod) Nodelocation: 152,680,1 Nodesize: 112,20 Windstate: 2,115,1,561,882 Paramnames: Y,B,I,K,C,S Function Gaussian(meanVec : numeric[I],covar : numeric[I,J]; I,J:Index~~ Type ;~ Over : ... optional atomic ;~ singleSampleMethod : optional hidden scalar ) Title: Gaussian( m, cv, i, j ) Description: A multi-variate Gaussian distribution based on a mean vec~~ tor and covariance matrix. The covariance matrix must symmetric and ~~ positive-definite. The meanVec is indexed by I. The covariance matr~~ ix is 2-D, indexed by I & J. Indexes I & J should be the same length~~ . Definition: var S := Decompose(covar,I,J);~ var U := ifall J then 0 else 0;~ var Z := Normal(U,1,singleSampleMethod:singleSampleMethod);~ sum( S*Z,J ) + meanVec Nodelocation: 112,72,1 Nodesize: 80,16 Windstate: 2,96,299,486,314 Paramnames: meanVec,covar,I,J,Over Function Dirichlet(alpha : Numeric[I]; I:IndexType ;~ Over : ... optional atomic ;~ singleSampleMethod : optional hidden scalar) Title: Dirichlet ( a, i ) Description: A Dirichlet distribution with parameters alpha_i>0~ Each sample of a Dirichlet distribution produces a random vector whos~~ e elements sum to 1. It is commonly used to represent second order p~~ robability information.~ ~ The Dirichlet distribution has a density given by ~ k * Product( X^(alpha-1), I)~ where k is a normalization factor equal to~ GammaFn( sum(alpha,I )) / Sum(GammaFn(alpha),I)~ ~ The parameters, alpha, can be interpreted as observation counts. The~~ mean is given by the relative values of alpha (normalized to 1), but~~ the variance narrows as the alphas get larger, just as your confiden~~ ce in a distribution would narrow as you get more samples.~ ~ The Dirichlet lends itself to easy Bayesian updating. If you have a ~~ prior of alpha0, and you observe N Definition: var a:=Gamma(alpha,singleSampleMethod:singleSampleMethod);~~ ~ a/sum(a,I) Nodelocation: 272,120,1 Nodesize: 58,16 Windstate: 2,26,18,624,485 Paramnames: alpha,I,Over Function Binormal(MeanVec :numeric[I]; Sdeviations : positive[I]; I:In~~ dexType; correlationCoef : numeric atomic;~ Over : ... optional atomic ;~ singleSampleMethod : optional hidden scalar) Title: BiNormal (m, s, i, c ) Description: A 2-D Normal (or Bi-variate Gaussian) distribution with t~~ he indicated individual standard deviations (>0) and the indicated co~~ rrelation coefficient. The index, I, must have exactly 2 elements, S~~ deviations must be indexed by I. Definition: if size(I)<>2 then ~ Error("Index to BiNormal must have 2 elements")~ else begin~ var s := product(Sdeviations,I) * correlationCoef;~ Index J:=CopyIndex(I);~ Gaussian( meanVec, If I<>J Then s else Sdeviations^2, I,J,~ singleSampleMethod: singleSampleMethod )~ end Nodelocation: 288,72,1 Nodesize: 78,16 Windstate: 2,2,24,525,540 Paramnames: MeanVec,Sdeviations,I,correlationCoef,Over Function Multinomial(N:Positive ; theta:NonNegative ; I : IndexType;~ Over : ... optional atomic ;~ singleSampleMethod : hidden optional scalar ) Title: Multinomial (n, theta, i ) Description: Returns the Multinomial Distribution.~ ~ The multinomial distribution is a generalization of the Binomial dist~~ ribution to N possible outcomes. For example, if you were to roll a ~~ fair die N times, an outcome would be the number of times each of the~~ six numbers appears. Theta would be the probability of each outcome~~ , where sum(theta,I)=1, and index I is the list of possible outcome. ~~ If theta doesn't sum to 1, it is normalized.~ ~ Each sample is a vector indexed by I indicating the number of times t~~ he corresponding outcome (die number) occurred during that sample poi~~ nt. Each sample will have the property that sum( result, I ) = N. Definition: var z := n;~ var k := size(I);~ ~ var j:=cumulate(1,I) in I do begin~ Index I2 := j..k;~ var theta2 := Slice(theta,I,I2); /* unnormalized sub-process */~ var p := theta2/sum(theta2, I2);~ p := if IsNan(p) then 0 else p;~ var xj := Binomial(z,p[I2=j],~ singleSampleMethod:singleSampleMethod);~~ ~ z := z - xj;~ xj~ end~ Nodelocation: 117,120,1 Nodesize: 85,16 Windstate: 2,75,167,476,522 Paramnames: N,theta,I,Over Function Correlate_dists(dists : Context[I,RunIndex] ; rankcorrs : num~~ eric array[I,J] ; ~ I,J : IndexType;~ RunIndex : optional Index = Run ) Title: Correlate Dists (d, rc, i, j ) Description: Reorders the samples in dists so as to match the desired ~~ rank correlations between distributions as closely as possible. Rank~~ Corrs must be positive definite, and the diagonal should contain all ~~ ones.~ ~ The result will be distributions having the same margins as the origi~~ nal input, but with rank correlations close to those of the rankcorrs~~ matrix. Definition: if not IsSampleEvalMode and Handle(RunIndex)=Handle(Run) T~~ hen~ dists {Mid mode}~ Else begin~ var u := if Handle(RunIndex)=Handle(run) ~ Then Sample(Gaussian(0,rankcorrs,I,J))~ Else Random(Gaussian(0,rankcorrs,I,J),Over:RunIndex);~ var dsort := sortIndex(dists,RunIndex);~ var urank := Rank(u,RunIndex);~ dists[RunIndex=dsort[RunIndex=urank]]~ end Nodelocation: 136,336,1 Nodesize: 100,16 Windstate: 2,301,193,494,399 Paramnames: dists,rankcorrs,I,J,RunIndex Function Correlate_with( S, ref : Context[RunIndex] ; rc : scalar ; ~ RunIndex : optional Index = Run ) Title: Correlate With (s, ref, rc ) Description: Reorders the samples of S so that the result is correlate~~ d with the reference sample with a rank correlation close to rankcorr~~ . ~ ~ Example: To generate a logNormal distribution that is highly correlat~~ ed with Ch1, use, e.g.,: Correlate_With( LogNormal(2,3), Ch1, 0.8 )~ ~ Note: This achieves a given unweighted rank correlation. If you have~~ a non-default SampleWeighting of points, the weighted rank correlato~~ n may differ. Definition: if IsSampleEvalMode or Handle(runIndex)<>Handle(Run) Then ~~ begin~ Index q := 1..2;~ var u := If Handle(RunIndex)=Handle(Run) ~ Then binormal( 0, 1, q, rc )~ Else Random(binormal(0,1,q,rc),Over:RunIndex);~ var rrank := Rank(ref,RunIndex);~ var u1sort := sortIndex(u[q=1],RunIndex);~ var u2rank := Rank(u[q=2],RunIndex);~ var ssort := sortIndex(S,RunIndex);~ S[RunIndex=ssort[RunIndex=u2rank[RunIndex=~ u1sort[Ru~~ nIndex=rrank]]]]~ end ~ else {mid mode}~ S Nodelocation: 128,256,1 Nodesize: 96,16 Windstate: 2,205,170,545,485 Paramnames: S,ref,rc,RunIndex Function Uniformspherical(I : IndexType ; R : optional Numeric[I] ;~ Over : ... optional atomic ;~ singleSampleMethod : optional hidden scalar ) Title: Uniform Spherical (i, r ) Description: Generates points uniformly on a sphere (or circle or hype~~ rsphere).~ Each sample generated is indexed by I -- so if I has 3 elements, the ~~ points will lie on a sphere.~ ~ The mid value is a bit strange here since there isn't really a median~~ that lies on the sphere. Obviously the center of the sphere is the ~~ middle value, but that isn't in the allowable range. So, an arbitrar~~ y point on the sphere is used. Definition: if IsNotSpecified(R) then R:=1;~ var u := Normal(0,1,over:I,~ singleSampleMethod:singleSampleMethod); ~ var d := sqrt( sum(u^2,I) );~ if d=0 then Array(I,R/sqrt(size(I))) else r*u/d Nodelocation: 328,168,1 Nodesize: 86,16 Windstate: 2,151,227,476,424 Paramnames: I,R,Over Function Multiuniform(corr : Numeric[I,J] ; I,J : IndexType ; lb,ub : ~~ optional Numeric[I,J] ;~ Over : ... optional atomic ;~ singleSampleMethod : hidden optional scalar ) Title: MultiUniform ( c, i, j, lb, ub ) Description: The multi-variate uniform distribution.~ Generates vector samples (indexed by I) such that each component has ~~ a uniform marginal distribution, and such that each component have th~~ e pair-wise correlations given by corr. Indexes I and J must have th~~ e same number of elements, corr needs to be symmetric and must obey a~~ certain semidefinite condition (namely that the transformed matrix [~~ 2*sin(30*cov) ] is positive semidefinite. In most cases, this rough~~ ly the same as corr being, or not being, positive semidefinite). Lb ~~ and ub can be used to specify upper and lower bounds, either for all ~~ components, or individually if these bounds are indexed by I. If lb ~~ & ub are omitted, each component will have marginal Uniform(0,1).~ ~ The correlation specified in corr is true sample correlation - not ra~~ nk correlation. ~ ~ The transformation here is based on:~ * Falk, M. (1999), "A simple approach to the generation of uniformly ~~ distributed random variables with prescribed correlations," Comm. in ~~ Stats - Simulation and Computation 28: 785-791. Definition: if IsNotSpecified(lb) then lb:=0;~ if IsNotSpecified(ub) then ub := 1;~ var R := if I=J then 1 else 2*sin(30*corr);~ var g := Gaussian(0,R,I,J,~ singleSampleMethod:singleSampleMethod);~~ ~ Cumnormal( g ) * (ub-lb) + lb Nodelocation: 132,168,1 Nodesize: 100,16 Windstate: 2,67,106,608,611 Paramnames: corr,I,J,lb,ub,Over Module Depricated_multi_var Title: Depricated multi-variate stuff Description: Functions found in this module are here for legacy reason~~ s. They existed in older versions of the Multivariate library, but h~~ ave been become obsolete for whatever reason. Author: Lonnie Date: Mon, Apr 30, 2007 3:49 PM Defaultsize: 48,24 Nodelocation: 80,888,1 Nodesize: 56,32 Function Samplecovariance(X ; I : Index ; J : optional Index ; R : In~~ dex) Title: Sample Covariance Description: This function is obsolete. In Analytica 4.0, the builtin~~ function Variance can be used to compute a covariance matrix. The e~~ quivalent of this function would be: Variance( X, R, CoVarDim:I, CoV~~ arDim2:J ).~ ~ Returns a covariance matrix based on the sampled data, X, indexed by ~~ I and R. (I is the dimensionality of X, R corresponds to the samples~~ ). The result will be indexed by I and J -- supply J to be the same ~~ length as I.~ ~ Note that the mean is simply Average(X,R), and doen't warrant a separ~~ ate function. Definition: var I2 := if IsNotSpecified(J) ~ Then (Index K/((identifier of I)&"2") := I do VarTerm(K~~ )) ~ Else VarTerm(J);~ var Z:=X-Average(X,R);~ var Zt := Z[@I=@I2];~ Sum(Z*Zt,R)/(size(R)-1) Nodelocation: 80,48,1 Nodesize: 48,24 Windstate: 2,222,299,476,297 Paramnames: X,I,J,R Function Samplecorrelation(X : array[I,R] ; I,J,R : IndexType) Title: sample correlation Description: This function is obsolete. A covariance matrix can be co~~ mputed in Analytica 4.0+ using the built-in function Correlation. Th~~ e equivalent of this function is Correlation(X,X[@I=@J],R).~ ~ Returns a correlation matrix based on data in X, where each data poin~~ t is a vector indexed by I, and the entries in the correlation matrix~~ are the pair-wise correlations of the columns of data. A second ind~~ ex, J, of size identical to I, is required in order to index the 2-di~~ mensional result. Definition: var z:=x-average(x,R);~ var zt := slice(z,I,cumulate(1,J));~ sum(z*zt,R) / sqrt(sum(z^2,R) * sum(zt^2,R))~ Nodelocation: 208,48,1 Nodesize: 48,24 Windstate: 2,70,24,523,377 Paramnames: X,I,J,R Close Depricated_multi_var Text Te1 Description: Parametric Multivariate Distributions Nodelocation: 160,40,-1 Nodesize: 136,12 Text Te2 Description: Creating an array of mutually correlated distributions: Nodelocation: 232,312,-1 Nodesize: 200,16 Text Te3 Description: Creating a single univariate distribution correlated wit~~ h another existing dist: Nodelocation: 296,224,-1 Nodesize: 268,12 Function Normal_correl(m, s, r, y: Numeric ;~ over : optional atomic ;~ singleSampleMethod : optional hidden scalar ) Title: Normal_correl(m, s, r, y) Description: Generates a normal distribution with mean m, standard dev~~ iation s, and correlation r with normally distributed value y. In a ~~ deterministic context, it will return m.~ ~ If y is not normally distributed, the result will also not be normal,~~ and the correlation will be approximate. It generalizes appropriatel~~ y if any of the parameters are arrays:The result array will have the ~~ union of the indexes of the parameters. Definition: IF r<-1 OR r>1 THEN Error('Correlation parameter r in func~~ tion Normal_correl(m, s, r, y) is outside the expected range [-1, 1].~~ ');~ IFOnly IsSampleEvalMode ~ THEN m + s * (Sqrt(1-r^2) ~ * Normal(Sameindexes( 0, m ), Sameindexes( 1~~ , s ),~ singleSampleMethod:singleSampl~~ eMethod ) ~ + r * (y - Mean(y))/Sdeviation(y))~ ELSE m Nodelocation: 352,256,1 Nodesize: 108,16 Windstate: 2,102,90,503,416 Paramnames: m,s,r,y,over Module Multivariate_interna Title: Multivariate Internal Functions Author: Lonnie Date: Tue, May 01, 2007 9:29 PM Defaultsize: 48,24 Nodelocation: 200,888,1 Nodesize: 52,32 Function Sameindexes(x, y) Title: SameIndexes(x,y) Description: Returns an array with the same indexes as y, and value x ~~ in each cell. Definition: IF y=y THEN x ELSE x Nodelocation: 120,64,1 Nodesize: 80,20 Paramnames: x,y Close Multivariate_interna Function Multinormal(m, s: Numeric; cm: ArrayType[i, j]; i , j: IndexT~~ ype ;~ Over : ... optional atomic ;~ singleSampleMethod : optional hidden scalar ) Title: Multinormal(m,s,c,i,j) Description: A multi-variate normal (or Gaussian) distribution with me~~ an m, standard deviation s, and correlation matrix cm. m and s may ~~ be scalar or indexed by i. cm must be symmetric, positive-definite, a~~ nd indexed by i & j, which must be the same length.~ ~ Multinormal uses a correlation matrix. Compare with Gaussian, which ~~ also defines a multi-variate normal but which uses a covariance matri~~ x. Definition: Gaussian(m,cm*s*s[@i=@j],i,j,over,singleSampleMethod) Nodelocation: 472,72,1 Nodesize: 84,16 Windstate: 2,391,248,512,343 Paramnames: m,s,cm,i,j,Over Text Te4 Description: Reshaped distributions: Nodelocation: 136,392,-1 Nodesize: 100,16 Function Dist_reshape(x : Numeric[R] ; newdist : all Numeric[R] ; ~ R : optional Index = Run ) Title: Dist_reshape(x, newdist) Description: Reshapes the probability distribution of uncertain quanti~~ ty x so that it has the same marginal probability distribution (i.e, ~~ same set of sample values) as newdist, but retains the same ranks as ~~ x. Thus:~ Rank(Sample(x), Run) ~ = Rank(Sample(Reshape_dist(x, y)), Run)~ In a Mid context, it simply returns the mid value of newdist, with an~~ y indexes of x.~ ~ The result retains any rank correlations that x may have with other p~~ redecessor variables. So, the rank-order correlation between a third~~ variable z and x will be the same as the rank-order correlation betw~~ een z and a reshaped version of x, i.e.~ RankCorrel(x, z) = RankCorrel(Reshape_Dist(x, y), z)~ ~ The operation may optionally be applied along an index other than Run~~ . Definition: IFOnly IsSampleEvalMode or Handle(R)<>Handle(Run) THEN BEG~~ IN~ VAR dsort := SortIndex(newdist, Run);~ VAR xranks := Rank(x, Run);~ newdist[Run = dsort[Run=xranks]]~ END~ ELSE newdist * (x=x) Nodelocation: 152,416,1 Nodesize: 116,16 Windstate: 2,102,90,646,469 Paramnames: x,newdist,R Text Te5 Description: Arrays with serial correlation Nodelocation: 208,476,-1 Nodesize: 168,12 Function Normal_serial_correl(m, s, r: Numeric; i: IndexType ;~ over : ... optional atomic;~ singleSampleMethod : optional hidden scalar ) Title: Normal_serial_correl(m,s,r,i) Description: Generates an array over index i of normal distributions w~~ ith mean m, standard deviation s, and correlation r between successiv~~ e values over index i. You can give each distribution a different m~~ ean and/or standard deviation if m and/or s are arrays indexed by i. ~~ If r is indexed by i, r[i=k] specifies the correlation between result~~ [i=k] and result[i=k-1]. (Then the first correlation, slice(r, i, 1)~~ is ignored.) Definition: Var x := Normal(0, 1,singleSampleMethod:singleSampleMethod~~ );~ (FOR j := i DO ~ x := Normal_correl( 0, 1, r[i = j],x,~ singleSampleMethod:singleSampl~~ eMethod ) ) ~ * s + m Nodelocation: 160,504,1 Nodesize: 120,16 Windstate: 2,353,325,540,383 Paramnames: m,s,r,i,over Function Normal_additive_gro(x, m, s, r: Numeric; i: IndexType ;~ over : ... optional atomic ;~ singleSampleMethod : optional hidden scalar ) Title: Normal_additive_gro(x,m,s,r,i) Description: Adds a normally distributed percent growth g with mean m ~~ and standard deviation s to x for each value of index i. The growth g~~ for each i has serial correlation r with g for i-1. Definition: x *( 1 + Cumulate(Normal_serial_correl(m, s, r, i,~ singleSampleMethod:singleSampleMethod), i~~ )) Nodelocation: 159,544,1 Nodesize: 119,16 Windstate: 2,102,90,519,306 Paramnames: x,m,s,r,i,over Function Normal_compound_gro(x, m, s, r: Numeric; t: IndexType ;~ over : ... optional atomic;~ singleSampleMethod : optional hidden scalar ) Title: Normal_compound_gro(x,m,s,r,t) Description: An array of values over time index t, starting from with ~~ value x, and with compound growth applied for each time interval, wit~~ h normal uncertainty with mean m and standard deviation s The growth~~ g for each i has correlation r with g for i-1. Definition: x * Cumproduct(IF t = Slice(t, 1) THEN 1 ELSE Normal_seria~~ l_correl(m, s, r, t, singleSampleMethod:singleSampleMethod ) + 1, t)~~ Nodelocation: 159,584,1 Nodesize: 119,16 Windstate: 2,102,90,529,366 Paramnames: x,m,s,r,t,over Function Dist_serial_correl(x; r; i: IndexType ;~ over : ... optional atomic;~ singleSampleMethod : optional hidden scalar ) Title: Dist_serial_correl(x,r,i) Description: Generates an array y over index i where each y[i] has a m~~ arginal distribution identical to x, and serial rank correlation of ~~ r with y[i-1]. If x is indexed by i, each y[i] has the same margin~~ al distribution as x[i], but with samples reordered to have the speci~~ fied rank correlation r between successive values. If r is indexed b~~ y i, r[i=k] specifies the rank correlation between y[i=k] and y[i=k-1~~ ]. Then the first correlation, r[i=1], is ignored.~ ~ In Mid context, it returns Mid(x).~ ~ Note: The result retains no probabilistic dependence on x. Definition: Dist_reshape(Normal_serial_correl( 0, 1, r, i, singleSampl~~ eMethod:singleSampleMethod ), x) Nodelocation: 408,504,1 Nodesize: 120,16 Windstate: 2,302,78,477,447 Paramnames: x,r,i,over Function Dist_additive_growth(x, g, r: Numeric; i: IndexType;~ over : ... optional atomic;~ singleSampleMethod : optional hidden scalar ) Title: Dist_additive_growth(x,g,r,i) Description: Generates an array of values over index i, with the first~~ equal to x, and successive values adding an uncertain growth with pr~~ obability distribution g, and serial correlation r between growth[i =~~ k] and growth[i=k-1]. x, g, and r each may be indexed by i if you w~~ ant them to vary over i. Definition: x + Cumulate(Dist_serial_correl( g, r, i, singleSampleMeth~~ od : singleSampleMethod), i) Nodelocation: 407,544,1 Nodesize: 119,16 Windstate: 2,102,90,506,300 Paramnames: x,g,r,i,over Function Dist_compound_growth(x, g, r; i: IndexType ;~ over : ... optional atomic ;~ singleSampleMethod : optional hidden scalar ) Title: Dist_compound_growth(x,g,r,i) Description: Starts with x and applies a compound growth g for each va~~ lue of index i. The growth g for each i has correlation r with g for ~~ i-1. Definition: x * Cumproduct(~ IF i = Slice(i, 1) THEN 1 ~ ELSE (Dist_serial_correl( g, r, i, ~ singleSampleMethod:singleSampleMe~~ thod ) + 1)~ , i) Nodelocation: 407,584,1 Nodesize: 119,16 Windstate: 2,102,90,489,307 Paramnames: x,g,r,i,over Text Te6 Description: Distributions on Linear Regression coefficients Nodelocation: 296,632,-1 Nodesize: 256,12 Function Regressionnoise( Y : Numeric[I] ; B : Numeric[I,K] ; I,K : In~~ dex; C : optional Numeric[K] ) Title: RegressionNoise(Y,B,I,K,C) Description: When you have data, Y[I] and B[I,K], generated from an un~~ derlying model with unknown coefficients C[k] and S of the form:~ ~ Y = Sum( C*B, I) + Normal(0,S)~ ~ This function computes an estimate for S. ~ ~ When using in conjunction with RegressionDist, it is most efficient t~~ o provide the optional parameter C to both routines, where C is the e~~ xpected value of the regression coefficients, obtained from calling R~~ egression(Y,B,I,K). Doing so avoids an unnecessary call to the built~~ in Regression function. Definition: if IsNotSpecified(C) Then C := Regression(Y,B,I,K);~ Var resid := Y - Sum(C*B,K);~ sqrt( Sum(resid^2,I) / (size(I)-size(K)) );~ Nodelocation: 384,680,1 Nodesize: 104,20 Windstate: 2,332,211,498,542 Paramnames: Y,B,I,K,C Function Regressionfitprob( Y : Numeric[I] ; B : Numeric[I,K] ; I,K : ~~ Index; C : optional Numeric[K] ; ~ S : optional Numeric[I] ) Title: RegressionFitProb(Y,B,I,K,C) Description: Once you've obtained regression coefficients C (indexed b~~ y K) by calling the Regression function, this function returns the pr~~ obability that a fit this poor would occur by chance, given the assum~~ ption that the data was generated by a process of the form:~ ~ Y = Sum( C*B,K) + Normal(0,S)~ ~ If this result is very close to zero, it probably indicates that the ~~ assumption of linearity is bad. If it is very close to one, then it ~~ validates the assumption of linearity.~ ~ This is not a distribution function - it does not return a sample whe~~ n evaluated in Sample mode. However, it does complement the multivar~~ iate RegressionDist function also included in this library.~ ~ To use, first call the Regression function, then you must either know~~ the measurement knows a priori, or obtain it using the RegressionNoi~~ se function.~ ~ Var E_C := Regression(Y,B,I,K);~ Var S := RegressionNoise(Y,B,I,K,C);~ Var PrThisPoor := RegressionFitProb(Y,B,I,K,E_C,S) Definition: var resid := Y - sum(C*B,K);~ var n := size(I);~ var chi2 := sum( resid^2 / Mean(S)^2, I);~ GammaI( n/2 - 1, chi2/2 ) Nodelocation: 152,744,1 Nodesize: 112,20 Windstate: 2,287,69,586,548 Paramnames: Y,B,I,K,C,S Close Multivariate_distrib Variable Lr_noise Definition: Regressionnoise( Stock_price, Lr_basis, Date1, Lr_basis, L~~ r_c ) Nodelocation: 568,72,1 Nodesize: 48,24 Nodeinfo: 1,1,1,1,1,1,0,0,0,0 Variable Cr_noise Title: CR Noise Definition: RegressionNoise(Stock_price,Cr_basis,Date1,Cr_basis.K,Cr_c~~ ) Nodelocation: 320,192,1 Nodesize: 48,24 Variable Ar_noise Title: AR Noise Definition: RegressionNoise(Ar_y,Ar_basis,Ar_i,Ar_k,Ar_c) Nodelocation: 312,472,1 Nodesize: 48,24 Variable Lr_confidence Title: LR Confidence Definition: Regressionfitprob( Stock_price, Lr_basis,Date1, Lr_basis,L~~ r_c,Lr_noise ) Nodelocation: 560,144,1 Nodesize: 48,24 Variable Cr_confidence Title: CR Confidence Definition: RegressionFitProb(Stock_price,Cr_basis,Date1,Cr_basis.K,Cr~~ _c,Cr_noise) Nodelocation: 560,240,1 Nodesize: 48,24 Variable Ar_confidence Title: AR Confidence Definition: RegressionFitProb(Ar_y,Ar_basis,Ar_i,Ar_k,Ar_c,Ar_noise) Nodelocation: 544,344,1 Nodesize: 48,24 Valuestate: 2,67,67,416,303,0,MIDM Index Date2 Title: date2 Definition: Concat( CopyIndex(date1),~ dateadd( Slice(date1,size(date1)), 1..100, "wd" ) ) Nodelocation: 736,144,1 Nodesize: 48,24 Numberformat: 2,DD,2,2,0,0,4,0,$,0,"ABBREV",0 {!40000|Att_previndexvalue: [37.623K,37.624K,37.625K,37.628K,37.629K,37.63K~~ ,37.631K,37.632K,37.636K,37.637K,37.638K,37.639K,37.642K,37.643K,37.644K~~ ,37.645K,37.646K,37.649K,37.65K,37.651K,37.652K,37.653K,37.656K,37.657K~~ ,37.658K,37.659K,37.66K,37.663K,37.664K,37.665K,37.666K,37.667K,37.671K~~ ,37.672K,37.673K,37.674K,37.677K,37.678K,37.679K,37.68K,37.681K,37.684K~~ ,37.685K,37.686K,37.687K,37.688K,37.691K,37.692K,37.693K,37.694K,37.695K~~ ,37.698K,37.699K,37.7K,37.701K,37.702K,37.705K,37.706K,37.707K,37.708K~~ ,37.709K,37.712K,37.713K,37.714K,37.715K,37.719K,37.72K,37.721K,37.722K~~ ,37.723K,37.726K,37.727K,37.728K,37.729K,37.73K,37.733K,37.734K,37.735K~~ ,37.736K,37.737K,37.74K,37.741K,37.742K,37.743K,37.744K,37.747K,37.748K~~ ,37.749K,37.75K,37.751K,37.754K,37.755K,37.756K,37.757K,37.758K,37.761K~~ ,37.762K,37.763K,37.764K,37.765K,37.769K,37.77K,37.771K,37.772K,37.775K~~ ,37.776K,37.777K,37.778K,37.779K,37.782K,37.783K,37.784K,37.785K,37.786K~~ ,37.789K,37.79K,37.791K,37.792K,37.793K,37.796K,37.797K,37.798K,37.799K~~ ,37.8K,37.803K,37.804K,37.806K,37.807K,37.81K,37.811K,37.812K,37.813K~~ ,37.814K,37.817K,37.818K,37.819K,37.82K,37.821K,37.824K,37.825K,37.826K~~ ,37.827K,37.828K,37.831K,37.832K,37.833K,37.834K,37.835K,37.838K,37.839K~~ ,37.84K,37.841K,37.842K,37.845K,37.846K,37.847K,37.848K,37.849K,37.852K~~ ,37.853K,37.854K,37.855K,37.856K,37.859K,37.86K,37.861K,37.862K,37.863K~~ ,37.864K,37.865K,37.868K,37.869K,37.87K,37.871K,37.872K,37.875K,37.876K~~ ,37.877K,37.878K,37.879K,37.882K,37.883K,37.884K,37.885K,37.886K,37.889K~~ ,37.89K,37.891K,37.892K,37.893K,37.896K,37.897K,37.898K,37.899K,37.9K~~ ,37.903K,37.904K,37.905K,37.906K,37.907K,37.91K,37.911K,37.912K,37.913K~~ ,37.914K,37.917K,37.918K,37.919K,37.92K,37.921K,37.924K,37.925K,37.926K~~ ,37.927K,37.928K,37.931K,37.932K,37.933K,37.934K,37.935K,37.938K,37.939K~~ ,37.94K,37.941K,37.942K,37.945K,37.946K,37.947K,37.948K,37.949K,37.952K~~ ,37.953K,37.954K,37.955K,37.956K,37.959K,37.96K,37.961K,37.962K,37.963K~~ ,37.966K,37.967K,37.968K,37.969K,37.97K,37.973K,37.974K,37.975K,37.976K~~ ,37.977K,37.98K,37.981K,37.982K,37.983K,37.984K,37.987K,37.988K,37.989K~~ ,37.99K,37.991K,37.994K,37.995K,37.996K,37.997K,37.998K,38.001K]} Chance Cr_future_price Title: CR Future Price Definition: var b := @date2 ^ (@Cr_basis.K-1);~ Normal( sum( CR_c * b, Cr_basis.K ), Cr_noise ) Nodelocation: 696,240,1 Nodesize: 48,24 Valuestate: 2,4,22,868,599,1,CONF Reformval: [Date2,Undefined,2] Variable Stock_price2 Title: Stock Price2 Definition: IgnoreWarnings( Stock_price[ Date1 = Date2 ] ) Nodelocation: 696,304,1 Nodesize: 48,24 Valuestate: 2,120,130,416,303,0,MIDM Variable Compare4 Definition: [CR_FUTURE_PRICE,STOCK_PRICE2] Indexvals: ['CR Future Price','Stock Price2'] Nodelocation: 336,64,1 Nodesize: 48,24 Nodeinfo: 1,1,1,1,1,1,0,0,0,0 Valuestate: 2,136,146,695,459,1,MIDM Reformval: [Date2,Self] Variable Begin_forecast Title: begin forecast Definition: 1 jun 2007 Nodelocation: 672,368,1 Nodesize: 48,24 Numberformat: 2,DD,2,2,0,0,4,0,$,0,"ABBREV",0 Chance Ar_future_price Title: AR Future Price Definition: var y := IgnoreWarnings( Ar_stock_price[Ar_I=Date2] );~ for i := @[date2=begin_forecast]..size(date2) do (~ y[@Date2=i] := 1;~ var b := y[@date2 = i - Ar_k ];~ y[@date2=i] := Normal( Sum( Ar_c * b, Ar_K), Ar_Noise )~ );~ y Nodelocation: 672,432,1 Nodesize: 48,24 Valuestate: 2,22,38,819,613,1,CONF Reformval: [Date2,Undefined,2] Variable Compare5 Definition: [STOCK_PRICE2,AR_FUTURE_PRICE] Indexvals: ['Stock Price2','AR Future Price'] Nodelocation: 672,64,1 Nodesize: 48,24 Nodeinfo: 1,1,1,1,1,1,0,0,0,0 Valuestate: 2,49,49,816,576,1,CONF Reformval: [Date2,Self] Att__totalsindex: Variable Self {!40000|Att_resultslicestate: [Self,-1,Sys_localindex('PROBABILITY'),1~~ ,Date2,1]} Index K2 Title: K2 Definition: CopyIndex(Cr_basis.K) Nodelocation: 72,488,1 Nodesize: 48,24 Displayoutputs: Variable My_basis Variable Prod_basis Title: Prod Basis Definition: Cr_basis * Cr_basis[.K=K2] Nodelocation: 176,488,1 Nodesize: 48,24 Valuestate: 2,457,50,416,303,0,MIDM Reformval: [K2,Sys_localindex('K')] Displayoutputs: Variable My_basis {!40000|Att_resultslicestate: [Date1,7,Sys_localindex('K'),1,K2,1]} Index K Title: K Definition: 1..size(K2)*size(Cr_basis.K) Nodelocation: 176,544,1 Nodesize: 48,24 Displayoutputs: Variable My_basis Library Concatenation_udfs Title: Concatenation UDFs Description: This library contains functions to make various instances~~ of concatenation more convenient. Concat3 thru Concat10 are general~~ izations of the built-in Concat function which concatenate from 3 to ~~ 10 arrays in a single call (while the built-in Concat concatenates tw~~ o arrays). ConcatRows concatenates all the rows of a single array. Author: David Kendall & Lonnie Chrisman Date: Mon, Jan 26, 2004 8:49 AM Saveauthor: Lonnie Savedate: Sat, Mar 05, 2005 6:46 PM Defaultsize: 48,24 Nodelocation: 896,64,1 Nodesize: 48,24 Nodeinfo: 1,0,0,1,1,1,0,0,0,0 Diagstate: 1,39,36,798,452,23 Function Concat3(A1, A2, A3: ArrayType; I1, I2, I3, J: IndexType ) Title: Concat3 Description: Concatenates three arrays, A1, A2, and A3. I1, I2, and I~~ 3 are the indexes that are joined; J is the index of the new array; J~~ usually is the concatenation of I1, I2, and I3 Definition: Index I12 := Concat(I1,I2);~ Concat( Concat( A1,A2,I1,I2,I12 ), A3, I12, I3, J ) Nodelocation: 88,112,1 Nodesize: 48,26 Windstate: 2,56,56,986,596 Paramnames: A1,A2,A3,I1,I2,I3,J Function Concat4(A1, A2, A3, A4: ArrayType; I1, I2, I3, I4, J: IndexTy~~ pe ) Title: Concat4 Description: Concatenates four arrays, A1, A2, A3, and A4. I1, I2, I3~~ , and I4 are the indexes that are joined; J is the index of the new a~~ rray; J usually is the concatenation of I1, I2, I3, and I4. Definition: Index I12 := Concat(I1,I2);~ Index I123:= Concat(I12, I3);~ Concat(~ Concat(~ Concat( A1,A2,I1,I2,I12 ), ~ A3, I12, I3, I123), ~ A4, I123, I4, J);~ Nodelocation: 192,112,1 Nodesize: 48,24 Windstate: 2,30,30,986,596 Paramnames: A1,A2,A3,A4,I1,I2,I3,I4,J Att__cloakdefn: 0 Function Concat9(A1, A2, A3, A4, A5, A6, A7, A8, A9: ArrayType; I1, I2~~ , I3, I4, I5, I6, I7, I8, I9, J: IndexType) Title: Concat9 Description: Concatenates nine arrays, A1, ..., A9. I1, ..., I9 are t~~ he indexes joined; J is the index of the new array; J usually is the ~~ concatenation of I1, ..., I9. Definition: Index I12 := Concat(I1,I2);~ Index I123 := Concat(I12, I3);~ Index I1234 := Concat(I123, I4);~ Index I12345 := Concat(I1234, I5);~ Index I123456 := Concat(I12345, I6);~ Index I1234567 := Concat(I123456, I7);~ Index I12345678 := Concat(I1234567, I8);~ Concat(~ Concat(~ Concat(~ Concat(~ Concat( ~ Concat(~ Concat(~ Concat( A1,A2,I1,I2,I12 ), ~ A3, I12, I3, I123), ~ A4, I123, I4, I1234),~ A5, I1234, I5, I12345),~ A6, I12345, I6, I123456),~ A7, I123456, I7, I1234567),~ A8, I1234567, I8, I12345678),~ A9, I12345678, I9, J); Nodelocation: 88,280,1 Nodesize: 48,24 Windstate: 2,27,120,469,638 Paramnames: A1,A2,A3,A4,A5,A6,A7,A8,A9,I1,I2,I3,I4,I5,I6,I7,I8,I9,J Att__cloakdefn: 0 Function Concat5(A1, A2, A3, A4, A5: ArrayType; I1, I2, I3, I4, I5, J:~~ IndexType ) Title: Concat5 Description: Concatenates five arrays, A1, ..., A5. I1, ..., I5 are t~~ he indexes joined; J is the index of the new array; J usually is the ~~ concatenation of I1, ..., I5. Definition: Index I12 := Concat(I1,I2);~ Index I123:= Concat(I12, I3);~ Index I1234 := Concat(I123, I4);~ Concat(~ Concat(~ Concat(~ Concat( A1,A2,I1,I2,I12 ), ~ A3, I12, I3, I123), ~ A4, I123, I4, I1234),~ A5, I1234, I5, J); Nodelocation: 88,168,1 Nodesize: 48,24 Windstate: 2,160,160,986,596 Paramnames: A1,A2,A3,A4,A5,I1,I2,I3,I4,I5,J Function Concat6(A1, A2, A3, A4, A5, A6: ArrayType; I1, I2, I3, I4, I5~~ , I6, J: IndexType ) Title: Concat6 Description: Concatenates six arrays, A1, ..., A6. I1, ..., I6 are th~~ e indexes joined; J is the index of the new array; J usually is the c~~ oncatenation of I1, ..., I6. Definition: Index I12 := Concat(I1,I2);~ Index I123:= Concat(I12, I3);~ Index I1234 := Concat(I123, I4);~ Index I12345 := Concat(I1234, I5);~ Concat(~ Concat(~ Concat(~ Concat(~ Concat( A1,A2,I1,I2,I12 ), ~ A3, I12, I3, I123), ~ A4, I123, I4, I1234),~ A5, I1234, I5, I12345),~ A6, I12345, I6, J); Nodelocation: 192,168,1 Nodesize: 48,24 Windstate: 2,644,94,602,712 Paramnames: A1,A2,A3,A4,A5,A6,I1,I2,I3,I4,I5,I6,J Att__cloakdefn: 0 Function Concat7(A1, A2, A3, A4, A5, A6, A7: ArrayType; I1, I2, I3, I4~~ , I5, I6, I7, J: IndexType ) Title: Concat7 Description: Concatenates seven arrays, A1, ..., A7. I1, ..., I7 are ~~ the indexes joined; J is the index of the new array; J usually is the~~ concatenation of I1, ..., I7. Definition: Index I12 := Concat(I1,I2);~ Index I123:= Concat(I12, I3);~ Index I1234 := Concat(I123, I4);~ Index I12345 := Concat(I1234, I5);~ Index I123456 := Concat(I12345, I6);~ Concat(~ Concat(~ Concat(~ Concat(~ Concat(~ Concat( A1,A2,I1,I2,I12 ), ~ A3, I12, I3, I123), ~ A4, I123, I4, I1234),~ A5, I1234, I5, I12345),~ A6, I12345, I6, I123456),~ A7, I123456, I7, J); Nodelocation: 88,224,1 Nodesize: 48,24 Windstate: 2,580,98,551,565 Paramnames: A1,A2,A3,A4,A5,A6,A7,I1,I2,I3,I4,I5,I6,I7,J Function Concat8(A1, A2, A3, A4, A5, A6, A7, A8: ArrayType; I1, I2, I3~~ , I4, I5, I6, I7, I8, J: IndexType ) Title: Concat8 Description: Concatenates eight arrays, A1, ..., A8. I1, ..., I8 are ~~ the indexes joined; J is the index of the new array; J usually is the~~ concatenation of I1, ..., I8. Definition: Index I12 := Concat(I1,I2);~ Index I123:= Concat(I12, I3);~ Index I1234 := Concat(I123, I4);~ Index I12345 := Concat(I1234, I5);~ Index I123456 := Concat(I12345, I6);~ Index I1234567 := Concat(I123456, I7);~ Concat(~ Concat(~ Concat(~ Concat(~ Concat(~ Concat(~ Concat( A1,A2,I1,I2,I12 ), ~ A3, I12, I3, I123), ~ A4, I123, I4, I1234),~ A5, I1234, I5, I12345),~ A6, I12345, I6, I123456),~ A7, I123456, I7, I1234567),~ A8, I1234567, I8, J); Nodelocation: 192,224,1 Nodesize: 48,24 Windstate: 2,12,98,561,737 Paramnames: A1,A2,A3,A4,A5,A6,A7,A8,I1,I2,I3,I4,I5,I6,I7,I8,J Att__cloakdefn: 0 Function Concat10(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10: ArrayType; ~~ I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, J: IndexType) Title: Concat10 Description: Concatenates ten arrays, A1, ..., A10. I1, ..., I10 are ~~ the indexes joined; J is the index of the new array; J usually is the~~ concatenation of I1, ..., I10. Definition: Index I12 := Concat(I1,I2);~ Index I123 := Concat(I12, I3);~ Index I1234 := Concat(I123, I4);~ Index I12345 := Concat(I1234, I5);~ Index I123456 := Concat(I12345, I6);~ Index I1234567 := Concat(I123456, I7);~ Index I12345678 := Concat(I1234567, I8);~ Index I123456789 := Concat(I12345678, I9);~ Concat(~ Concat(~ Concat(~ Concat(~ Concat(~ Concat( ~ Concat(~ Concat(~ Concat( A1,A2,I1,I2,I12 ), ~ A3, I12, I3, I123), ~ A4, I123, I4, I1234),~ A5, I1234, I5, I12345),~ A6, I12345, I6, I123456),~ A7, I123456, I7, I1234567),~ A8, I1234567, I8, I12345678),~ A9, I12345678, I9, I123456789),~ A10, I123456789, I10, J); Nodelocation: 192,280,1 Nodesize: 48,24 Windstate: 2,542,93,632,744 Paramnames: A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,I1,I2,I3,I4,I5,I6,I7,I8,I9,~~ I10,J Att__cloakdefn: 0 Function Concatrows(A : ArrayType ; RowIndex,ColIndex,ResultIndex : In~~ dexType) Title: ConcatRows (A,I,J,K) Description: Takes an array, A indexed by RowIndex & ColIndex, and con~~ catenates each row, henceforth flattening the array by one dimension.~~ The result is indexed by ResultIndex, which must be an index with si~~ ze(RowIndex) * size(ColIndex) elements. Definition: index L := [ identifier of RowIndex, identifier of ColInde~~ x, "val"];~ slice(Mdarraytotable(A,ResultIndex,L),L,3) Nodelocation: 304,112,1 Nodesize: 48,24 Windstate: 2,30,320,478,260 Paramnames: A,RowIndex,ColIndex,ResultIndex Close Concatenation_udfs Variable My_basis Title: My basis Definition: var iK := ....;~ var jK := ...;~ Prod_basis[@K2=ik, @Lr_basis.K = jK ] Nodelocation: 288,544,1 Nodesize: 48,24 Valuestate: 2,14,12,415,411,0,MIDM Reformval: [Date1,K] Displayinputs: Index K2, Variable Prod_basis, Index K Close Using_regression