{ From user Lonnie, Model Statistical_function at Thu, Aug 16, 2007 11:38 AM~~ } Softwareversion 4.0.0 { System Variables with non-default values: } Samplesize := 200 Sampletype := 2 Typechecking := 1 Checking := 1 Saveoptions := 2 Savevalues := 0 Sampleweighting := adj_wt Windstate Sampleweighting: 2,102,90,481,381 {!40000|Att_contlinestyle Graph_primary_valdim: 1} Attribute Reference Attribute Date_bough Askattribute Recursive,Function,Yes Model Statistical_function Title: Statistical Functions in Analytica 4.0 Description: Analytica User Group session #3~ Statistical Functions in Analytica 4.0~ Aug 16, 2007~ ~ A statistical function is a function that process a data set containi~~ ng many sample points, computing a "statistic" that summarizes the da~~ ta. Simple examples are Mean and Variance, but more complex examples ~~ may return matrices or tables. In this talk, I'll review statistical ~~ functions that are built into Analytica 4.0. In Analytica 4.0, all bu~~ ilt-in statistical functions can now be applied to historical data se~~ ts over an arbitrary index, as well as to uncertain samples (the Run ~~ index), eliminating the need for separate function libraries. I will ~~ demonstrate this use, as well as several new statistical functions, e~~ .g., Pdf, Cdf, Covariance. I will explain how the domain attribute sh~~ ould be utilized to indicate that numeric-valued data is discrete (su~~ ch as integer counts, for example), and how various statistical funct~~ ions (e.g., Frequency, GetFract, Pdf, Cdf, etc) make use of this info~~ rmation. In the process, I'll demonstrate numerous examples using the~~ se functions, such things as inferring sample covariance or correlati~~ on matricies from data, quickly histogramming arbitrary data and usin~~ g the coordinate index setting to plot it, or using a weighted Freque~~ ncy for rapid aggregation. ~ ~ In addition, all statistical functions in Analytica 4.0 can compute w~~ eighted statistics, where each point is assigned a different weight. ~~ I'll cover the basics of sample weighting, and demonstrate some simpl~~ e examples of using this for computing a Bayesian posterior and for i~~ mportance sampling from an extreme distribution. ~ Author: Lonnie Date: Thu, Aug 16, 2007 8:42 AM Saveauthor: Lonnie Savedate: Thu, Aug 16, 2007 11:38 AM Defaultsize: 48,24 Diagstate: 1,1,0,550,300,17 Windstate: 2,20,36,620,415 Fontstyle: Arial, 15 Fileinfo: 0,Model Statistical_function,2,2,0,0,W:\TestModels\User Grou~~ p Webinar - Statistical Functions.ANA Module Historical_data Title: Historical Data Author: Lonnie Date: Thu, Aug 16, 2007 9:55 AM Defaultsize: 48,24 Nodelocation: 72,48,1 Nodesize: 48,24 Diagstate: 1,1,0,504,395,17 Index Trading_date Title: Trading Date Definition: [37.847K,37.846K,37.845K,37.842K,37.841K,37.84K,37.839K,37~~ .838K,37.835K,37.834K,37.833K,37.832K,37.831K,37.828K,37.827K,37.826K~~ ,37.825K,37.824K,37.821K,37.82K,37.819K,37.818K,37.817K,37.814K,37.81~~ 3K,37.812K,37.811K,37.81K,37.807K,37.806K,37.804K,37.803K,37.8K,37.79~~ 9K,37.798K,37.797K,37.796K,37.793K,37.792K,37.791K,37.79K,37.789K,37.~~ 786K,37.785K,37.784K,37.783K,37.782K,37.779K,37.778K,37.777K,37.776K,~~ 37.775K,37.772K,37.771K,37.77K,37.769K,37.765K,37.764K,37.763K,37.762~~ K,37.761K,37.758K,37.757K,37.756K,37.755K,37.754K,37.751K,37.75K,37.7~~ 49K,37.748K,37.747K,37.744K,37.743K,37.742K,37.741K,37.74K,37.737K,37~~ .736K,37.735K,37.734K,37.733K,37.73K,37.729K,37.728K,37.727K,37.726K,~~ 37.723K,37.722K,37.721K,37.72K,37.719K,37.715K,37.714K,37.713K,37.712~~ K,37.709K,37.708K,37.707K,37.706K,37.705K,37.702K,37.701K,37.7K,37.69~~ 9K,37.698K,37.695K,37.694K,37.693K,37.692K,37.691K,37.688K,37.687K,37~~ .686K,37.685K,37.684K,37.681K,37.68K,37.679K,37.678K,37.677K,37.674K,~~ 37.673K,37.672K,37.671K,37.667K,37.666K,37.665K,37.664K,37.663K,37.66~~ K,37.659K,37.658K,37.657K,37.656K,37.653K,37.652K,37.651K,37.65K,37.6~~ 49K,37.646K,37.645K,37.644K,37.643K,37.642K,37.639K,37.638K,37.637K,3~~ 7.636K,37.632K,37.631K,37.63K,37.629K,37.628K,37.625K,37.624K,37.623K~~ ] Nodelocation: 96,48,1 Nodesize: 48,24 Numberformat: 2,DD,2,2,0,0,2,0,$,0,"ABBREV",0 {!40000|Att_graphindexrange: 1,,0,,,0} {!40000|Att_previndexvalue: [37.847K,37.846K,37.845K,37.842K,37.841K,37.84K~~ ,37.839K,37.838K,37.835K,37.834K,37.833K,37.832K,37.831K,37.828K,37.827K~~ ,37.826K,37.825K,37.824K,37.821K,37.82K,37.819K,37.818K,37.817K,37.814K~~ ,37.813K,37.812K,37.811K,37.81K,37.807K,37.806K,37.804K,37.803K,37.8K~~ ,37.799K,37.798K,37.797K,37.796K,37.793K,37.792K,37.791K,37.79K,37.789K~~ ,37.786K,37.785K,37.784K,37.783K,37.782K,37.779K,37.778K,37.777K,37.776K~~ ,37.775K,37.772K,37.771K,37.77K,37.769K,37.765K,37.764K,37.763K,37.762K~~ ,37.761K,37.758K,37.757K,37.756K,37.755K,37.754K,37.751K,37.75K,37.749K~~ ,37.748K,37.747K,37.744K,37.743K,37.742K,37.741K,37.74K,37.737K,37.736K~~ ,37.735K,37.734K,37.733K,37.73K,37.729K,37.728K,37.727K,37.726K,37.723K~~ ,37.722K,37.721K,37.72K,37.719K,37.715K,37.714K,37.713K,37.712K,37.709K~~ ,37.708K,37.707K,37.706K,37.705K,37.702K,37.701K,37.7K,37.699K,37.698K~~ ,37.695K,37.694K,37.693K,37.692K,37.691K,37.688K,37.687K,37.686K,37.685K~~ ,37.684K,37.681K,37.68K,37.679K,37.678K,37.677K,37.674K,37.673K,37.672K~~ ,37.671K,37.667K,37.666K,37.665K,37.664K,37.663K,37.66K,37.659K,37.658K~~ ,37.657K,37.656K,37.653K,37.652K,37.651K,37.65K,37.649K,37.646K,37.645K~~ ,37.644K,37.643K,37.642K,37.639K,37.638K,37.637K,37.636K,37.632K,37.631K~~ ,37.63K,37.629K,37.628K,37.625K,37.624K,37.623K]} Variable Stock_price Title: Stock Price Definition: Table(Trading_date,Stock)(~ 119.9,28.1,4.65,19.18,23.22,~ 124.03,28.27,4.7,19.35,23.8,~ 127.79,28.63,4.73,19.72,24.02,~ 125,28.71,4.68,19.99,23.98,~ 126.39,29.3,4.74,20.09,23.92,~ 134.01,30,5,20.2,24.68,~ 135.03,29.55,5,19.68,24.13,~ 135.25,29.54,4.96,20.08,24.13,~ 131.85,28.96,4.91,19.66,23.91,~ 136.49,29.52,5.14,20.09,24.3,~ 135,29.3,5.1,19.79,23.8,~ 131.76,28.99,5.1,19.12,23.62,~ 141.43,29.4,4.89,19.58,23.85,~ 143.85,29.39,4.92,19.62,23.54,~ 146,29.98,4.98,20.01,24,~ 137.26,30.71,5.24,20.58,24.5,~ 134.89,30.8,5.23,20.64,24.53,~ 143.7,31.19,5.29,20.78,24.72,~ 143.75,31.16,5.33,20.61,24.55,~ 140,31.51,5.4,20.6,25.26,~ 138.12,30.92,5.28,20.41,25.06,~ 138.91,30.78,5.29,20.38,26.33,~ 138.1,30.03,5.34,20.2,25.95,~ 137.73,29.82,5.37,20.4,25.97,~ 134.07,30.07,5.43,20.5,26,~ 132.39,29.49,5.38,19.98,24.57,~ 132.35,29.33,5.32,19.72,24.97,~ 130.33,29.87,5.33,20.16,24.96,~ 132.3,29.97,5.38,20.4,24.68,~ 132.75,29.99,5.33,20.49,24.6,~ 127.17,30.02,5.22,20.07,24.59,~ 121.26,29.74,5.19,19.92,24.27,~ 122.04,29.47,5.26,19.71,23.74,~ 120.56,29.83,5.16,19.85,23.92,~ 121.89,29.87,5.07,19.69,23.79,~ 119.65,29.52,5.01,19.16,23.38,~ 122.34,29.49,5.02,19.48,23.48,~ 123,29.49,5.08,19.39,23.7,~ 123.9,30.22,5.13,19.68,24.29,~ 121.55,30.01,5.05,19.53,23.94,~ 123.66,30.46,5.1,19.88,24.1,~ 125.09,30.51,5.05,19.79,24.17,~ 120.5,30.49,5.05,19.86,24.24,~ 118.75,30.52,5.08,19.64,23.23,~ 117.5,30.39,4.99,19.3,22.67,~ 120.38,29.85,4.92,18.84,22.2,~ 120.19,30.02,4.96,19.21,21.93,~ 124.49,30.05,5.04,19.06,21.83,~ 124.07,29.62,4.97,18.73,21.31,~ 123.64,30.29,5.02,19.35,21.49,~ 122.67,30.58,5.07,19.48,21.96,~ 121.33,30.72,5.11,19.67,22.16,~ 118.4,30.59,5.18,19.66,22.36,~ 121.19,30.69,5.1,19.38,22.18,~ 118.77,31.11,5.12,19.42,22.08,~ 114.35,30.79,5.06,19.31,22.3,~ 113.62,30.48,5.16,19.24,22.16,~ 110.69,30.17,5.15,18.75,21.97,~ 112.89,30.58,5.38,19.16,22.67,~ 113.54,30.69,5.38,19.37,22.99,~ 111.98,31.05,5.39,19.32,22.63,~ 110.02,30.83,5.29,19.25,22.7,~ 109.44,30.98,5.3,19.05,22.23,~ 107.34,31.07,5.12,18.99,22.18,~ 107.52,30.9,5.14,18.84,22.01,~ 109.36,30.97,5.22,18.94,22.12,~ 108.74,30.89,5.15,18.98,22.28,~ 107.34,30.58,5.13,18.49,22.21,~ 106.88,30.78,5.2,18.83,22.47,~ 105.06,30.75,5.22,18.95,22.15,~ 103.92,30.71,5.22,19.05,21.96,~ 100.81,30.56,5.24,19.03,21.9,~ 100.4,30.97,5.18,19.02,21.74,~ 100.39,30.61,5.15,18.86,21.93,~ 99.47,30.4,5.09,18.59,21.8,~ 99.8,29.94,5.22,18.8,21.5,~ 99.92,30.12,5.26,19.1,21.87,~ 98.84,29.1,5.25,18.95,22.09,~ 95.34999999999999,28.99,5.27,18.9,22.26,~ 93.24,28.79,5.94,18.82,21.94,~ 93.51000000000001,28.78,5.92,18.94,21.91,~ 90.97,29.02,5.93,19,22.16,~ 90.27,28.69,5.89,18.76,21.81,~ 90.40000000000001,28.6,5.94,18.73,21.35,~ 90.34999999999999,28.85,5.95,18.89,20.98,~ 91.43000000000001,28.73,5.86,18.9,20.69,~ 90.24,28.61,5.8,18.63,20.46,~ 92.19,28.54,5.9,18.7,20.5,~ 92.59,28.11,5.9,18.59,20.47,~ 94.25,28.4,5.93,18.85,20.68,~ 93.65000000000001,28.57,5.93,18.57,20.1,~ 94.68000000000001,28.55,5.93,18.67,19.58,~ 94.27,28.5,5.86,18.56,19.38,~ 94.5,27.87,5.79,18.36,19.31,~ 93.65000000000001,27.74,5.8,18.14,19.13,~ 92.91,27.87,6.01,18.13,19.13,~ 93.75,27.75,5.96,18.16,19.09,~ 93.24,27.64,6.05,18.17,18.86,~ 95.45999999999999,27.72,6.06,18.49,19.06,~ 95.84999999999999,28.22,6.22,18.39,19.29,~ 93.52,28.02,6.19,18.24,19.27,~ 93.95999999999999,28.27,6.31,18.49,19.16,~ 93.87000000000001,28.52,6.49,18.17,19.34,~ 91.48,27.84,6.2,17.55,18.99,~ 91.13,27.83,6.22,17.18,19.11,~ 89.59,27.33,6.24,16.7,19.15,~ 89.56999999999999,27.28,6.22,16.72,19.14,~ 90,27.4,6.31,16.88,19.23,~ 88.40000000000001,26.72,6.15,16.65,19.12,~ 89.87000000000001,27.44,6.31,17.07,19.48,~ 87.97,27.29,6.27,16.63,19.1,~ 88,27.32,6.21,16.69,19.23,~ 87.72,27.61,6.17,16.49,19.12,~ 88.19,27.83,6.25,16.88,19.4,~ 86.31999999999999,27.55,6.07,16.37,19.11,~ 85.41,27.76,6.06,16.71,19.22,~ 87.06,28.09,6.04,16.77,19.59,~ 84.61,28.17,6.13,16.43,19.86,~ 83.93000000000001,27.87,5.98,16.29,20.03,~ 88.51000000000001,29.07,6.27,16.82,20.85,~ 89.06999999999999,28.9,6.27,16.82,20.76,~ 89.51000000000001,29.39,6.27,17.27,20.97,~ 89.2,29.35,6.28,17.2,20.88,~ 85.90000000000001,28.83,6.38,16.98,21.18,~ 84.83,28.74,6.29,16.7,21.23,~ 85.20999999999999,29.46,6.31,16.91,21.31,~ 85.3,29.4,6.4,16.77,21.14,~ 84.7,29.01,6.4,16.62,20.87,~ 84.88,28.94,6.42,16.65,20.8,~ 83.27,28.98,6.48,16.7,21.03,~ 86.18000000000001,29.26,6.59,16.71,21.36,~ 86.15000000000001,29.37,6.59,16.91,21.51,~ 84.15000000000001,29.51,6.53,17.02,21.31,~ 83.94,29.61,6.64,17.16,21.28,~ 84.75,30.19,6.63,17.42,21.23,~ 84.74,30.56,6.55,17.05,21.11,~ 85.73,30.86,6.64,17.16,20.96,~ 85.55,30.48,6.43,17.16,20.93,~ 85.94,30.53,6.35,17.27,20.89,~ 85.38,30.6,6.33,17.15,20.53,~ 86.25,30.45,6.34,16.98,20.6,~ 86.7,31.09,6.15,17.14,20.84,~ 85.7,30.74,5.66,17.12,20.55,~ 86.79000000000001,30.72,5.75,17,20.79,~ 88.5,31.11,5.77,17.27,20.82,~ 89.06999999999999,31,5.79,17.12,20.65,~ 94.95,31.1,5.99,17.52,21.04,~ 97.09999999999999,31.16,6.06,17.3,22.3,~ 94.62000000000001,31.21,6.06,17.5,22.13,~ 95.8,30.7,6.14,17.39,21.92,~ 97,29.66,6,17.77,21.52,~ 92.56999999999999,29.96,5.73,17.82,21.03,~ 85.47,29.93,5.65,17.86,21.01,~ 85.05,29.64,5.6,17.64,21.1,~ 85.66,29.81,5.69,17.68,21.17,~ 83.8,29.86,5.54,17.51,20.35~ ) Nodelocation: 208,48,1 Nodesize: 48,24 Defnstate: 2,574,8,453,729,0,MIDM Valuestate: 2,413,22,552,575,1,MIDM Graphsetup: {!40000|Att_contlinestyle Graph_primary_valdim:4}~ {!40000|Graph_symbolsizekey:0}~ {!40000|Att_graphvaluerange Stock_price:1,,,,0} Reformdef: [Stock,Trading_date] Reformval: [Trading_date,Undefined] {!40000|Att_xrole: -5} {!40000|Att_yrole: -3} {!40000|Att_coordinateindex: Stock} Index Stock Title: Stock Definition: ['AAPL','MSFT','SUNW','ORCL','INTC'] Nodelocation: 96,112,1 Nodesize: 48,24 {!40000|Att_previndexvalue: ['AAPL','MSFT','SUNW','ORCL','INTC']} Variable Mean_sp Title: mean sp Definition: Mean( Stock_price, Trading_date ) Nodelocation: 208,112,1 Nodesize: 48,24 Valuestate: 2,409,36,416,303,0,MIDM Variable Correlation_sp Title: correlation sp Definition: Correlation( Stock_price, Stock_price[Stock=Stock2], Tradi~~ ng_date ) Nodelocation: 208,184,1 Nodesize: 48,24 Valuestate: 2,419,79,416,303,0,MIDM Reformval: [Stock,Stock2] Index Stock2 Title: Stock2 Definition: CopyIndex(Stock) Nodelocation: 96,184,1 Nodesize: 48,24 {!40000|Att_previndexvalue: ['AAPL','MSFT','SUNW','ORCL','INTC']} Variable Cov_mat Title: cov mat Definition: Covariance( Stock_price, Stock_price[Stock=Stock2], Tradin~~ g_date ) Nodelocation: 208,240,1 Nodesize: 48,24 Valuestate: 2,499,105,416,303,0,MIDM Reformval: [Stock,Stock2] 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: 344,64,0 Nodesize: 60,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 : In~~ dex; 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 Chance Simulated_sp Title: Simulated SP Definition: Gaussian( Mean_sp, Cov_mat, Stock, Stock2 ) Nodelocation: 208,304,1 Nodesize: 48,24 Valuestate: 2,236,144,552,403,1,SAMP Reformval: [Undefined,Undefined,Undefined,Undefined,Undefined,1] {!40000|Att_xrole: -2} {!40000|Att_yrole: -3} {!40000|Att_coordinateindex: Stock} Function Some_statistic( X : ContextSamp[I] ; I : optional Index = Run~~ ) Title: some statistic Definition: Variance(X,I) / Mean(X,I) Nodelocation: 352,160,1 Nodesize: 48,24 Windstate: 2,527,133,476,224 Paramnames: X,I Variable Va2 Definition: Some_statistic(Stock_price,Trading_date) Nodelocation: 328,248,1 Nodesize: 48,24 Chance Va4 Definition: random(Normal(0,1),over:stock) Nodelocation: 72,304,1 Nodesize: 48,24 Valuestate: 2,267,242,416,303,0,MIDM Close Historical_data Chance X Title: X Definition: lognormal(mean:5,stddev:3) Nodelocation: 208,48,1 Nodesize: 48,24 Valuestate: 2,551,37,405,457,0,PDFP Graphsetup: Statsselect:[1, 1, 1, 1, 1, 1, 1, 1 ] Variable Mean_x Title: mean x Definition: mean(X) Nodelocation: 328,48,1 Nodesize: 48,24 Valuestate: 2,72,291,416,303,0,SMPL Variable Y Title: Y Definition: X+1 Nodelocation: 200,120,1 Nodesize: 48,24 Valuestate: 2,136,146,416,303,0,SAMP Variable Variance_x Title: variance x Definition: variance(X) Nodelocation: 328,112,1 Nodesize: 48,24 Valuestate: 2,152,242,416,303,0,MIDM Variable Sample_x Title: sample x Definition: sample(X) Nodelocation: 328,176,1 Nodesize: 48,24 Valuestate: 2,270,191,416,303,0,MIDM Variable Min_x Title: min x Definition: Min( Sample(X), Run ) Nodelocation: 328,240,1 Nodesize: 48,24 Valuestate: 2,466,46,416,303,0,MIDM Variable Average_x Title: average x Definition: average( Sample(x), Run ) Nodelocation: 440,48,1 Nodesize: 48,24 Valuestate: 2,517,150,416,303,0,MIDM Variable Histo_x Title: histo x Definition: Pdf(X) Nodelocation: 208,192,1 Nodesize: 48,24 Valuestate: 2,87,115,560,494,1,MIDM Reformval: [Sys_localindex('STEP'),Densityindex] {!40000|Att_coordinateindex: Densityindex} Chance Z Title: Z Definition: X^2 + normal(0,10) Nodelocation: 72,120,1 Nodesize: 48,24 Valuestate: 2,156,274,524,303,1,PDFP Variable Correl_z_vs_x Title: correl z vs x Definition: correlation(x,z) Nodelocation: 72,184,1 Nodesize: 48,24 Variable Cov Title: cov Definition: covariance(x,z) Nodelocation: 72,240,1 Nodesize: 48,24 Valuestate: 2,246,229,416,303,0,MIDM Variable Va1 Definition: Some_statistic(Z) Nodelocation: 192,256,1 Nodesize: 48,24 Module Discrete_vs_continuo Title: Discrete vs continuous Defaultsize: 48,24 Nodelocation: 448,144,1 Nodesize: 48,32 Diagstate: 1,94,64,550,300,17 Chance Count Title: count Definition: poisson(100) Nodelocation: 88,64,1 Nodesize: 48,24 Valuestate: 2,94,66,762,303,1,PDFP Domain: Domcontinuous Variable Histo_count Title: histo count Definition: pdf(Count,discrete:true) Nodelocation: 232,64,1 Nodesize: 48,24 Valuestate: 2,366,45,523,453,0,SMPL Reformval: [Sys_localindex('STEP'),Densityindex] Chance A Title: A Definition: Probtable(Self)(~ 0.3,0.2,0.5) Nodelocation: 88,144,1 Nodesize: 48,24 Valuestate: 2,449,123,366,455,0,SAMP Domain: ['item 1','item 2','item 3'] Variable Va3 Definition: frequency( A, poss_A ) Nodelocation: 216,144,1 Nodesize: 48,24 Valuestate: 2,435,240,416,303,0,MIDM Index Poss_a Title: Poss A Definition: ['item 1','item 2','item 3'] Nodelocation: 88,208,1 Nodesize: 48,24 Close Discrete_vs_continuo Module Weighting_of_samples Title: Weighting of samples Defaultsize: 48,24 Nodelocation: 432,240,1 Nodesize: 48,24 Diagstate: 1,156,94,741,445,17 Chance U Title: U Definition: uniform(-1,1) Nodelocation: 104,64,1 Nodesize: 48,24 Chance V Title: V Definition: uniform(-1,1) Nodelocation: 104,136,1 Nodesize: 48,24 Valuestate: 2,168,178,416,303,1,SAMP Xyexpr: U Variable V1 Title: V Definition: (U + V) / (abs(U - V) + 1) Nodelocation: 224,96,1 Nodesize: 48,24 Valuestate: 2,217,157,650,431,1,PDFP Graphsetup: {!40000|Att_contlinestyle Graph_pdf_valdim:1} Reformval: [Undefined,Result_type,Undefined,Undefined,1] Variable Wt Title: wt Definition: Table(Result_type)(1, U<=0 or V <=0) Nodelocation: 224,168,1 Nodesize: 48,24 Valuestate: 2,184,194,279,400,0,SAMP Variable Posterior_mean Title: posterior mean Definition: Mean(V1, w:Wt ) Nodelocation: 344,168,1 Nodesize: 48,24 Variable Posterior_variance Title: posterior variance Definition: variance(V1, w:Wt) Nodelocation: 344,224,1 Nodesize: 48,24 Decision Result_type Title: Result type Definition: Choice( Self, 0 ) Nodelocation: 96,208,1 Nodesize: 48,24 Domain: ['Prior','Posterior'] {!40000|Att_previndexvalue: ['Prior','Posterior']} Chance Ch1 Definition: Normal( sm, ssd, over:Pass ) Nodelocation: 456,136,1 Nodesize: 48,24 Valuestate: 2,284,256,416,303,1,PDFP Reformval: [Undefined,Pass,Undefined,Undefined,1] Objective Cost Title: Cost Definition: exp(Ch1/10) Nodelocation: 456,208,1 Nodesize: 48,24 Valuestate: 2,90,292,416,303,1,STAT Graphsetup: Statsselect:[1, 1, 1, 1, 1, 1, 0, 0 ] Reformval: [Undefined,Sys_localindex('STATISTICS'),Undefined,0] Xyexpr: Ch1 Variable Adj_wt Title: adj wt Definition: Dens_Normal(Ch1,10,5) / Dens_Normal(Ch1,sm,ssd) Nodelocation: 576,136,1 Nodesize: 48,24 Valuestate: 2,120,130,416,303,1,SAMP Xyexpr: Ch1 Library Distribution_densiti Title: Distribution Densities Library Description: The functions in this library return the probability dens~~ ities (for continuous distributions) and probabilities (for discrete ~~ distributions) for the standard distribution functions that are built~~ into Analytica.~ ~ These densities are useful for importance sampling. In importance sa~~ mpling, you can sample from a distribution different from your target~~ distribution, and then weight each point by f_target(x) / f_sample(x~~ ), where f_target is the density (or prob) of your target distributio~~ n, f_sample the density (or prob) of your sample distribution. Author: Lonnie Chrisman, Ph.D.~ Lumina Decision Systems Date: Fri, Nov 17, 2006 8:19 AM Saveauthor: Lonnie Savedate: Thu, Mar 29, 2007 9:21 PM Defaultsize: 48,24 Nodelocation: 336,40,0 Nodesize: 60,32 Nodeinfo: 1,1,1,1,1,1,0,0,0,0 Diagstate: 1,20,25,557,391,17 Windstate: 2,102,90,582,409 Fontstyle: Arial, 15 Function Dens_normal(x,m,sd : numeric) Title: Dens_Normal(x,m,sd) Description: The density of a uniform distribution Definition: 1/(sd*sqrt(2*Pi) ) * exp( - 0.5 * ( (x-m)/sd)^2 ) Nodelocation: 96,120,1 Nodesize: 60,24 Windstate: 2,105,359,476,224 Paramnames: x,m,sd Function Dens_uniform_(x,min,max:Numeric ; integer : optional boolean ~~ = false) Title: Dens_Uniform~ (x,min,max) Description: The probability density of x in a uniform distribution. ~~ If the parameter integer is supplied and specified as false, then the~~ probability of a discrete uniform distribution is returned. Definition: if integer then 1/(floor(max)-ceil(min)+1)~ else 1/(max-min) Nodelocation: 224,120,1 Nodesize: 60,24 Paramnames: x,min,max,integer Function Dens_beta(x,a,b : numeric ; lower : optional=0, upper : optio~~ nal = 1) Title: Dens_Beta~ (x,a,b) Description: The density of a beta distribution at x. Definition: x := (x-lower) / (upper-lower);~ 1/Betafn( a,b) * x^(a-1) * (1-x)^(b-1) / (upper-lower) Nodelocation: 224,56,1 Nodesize: 60,24 Paramnames: x,a,b,lower,upper Function Prob_bernoulli(x ; p : NonNegative) Title: Prob_Bernoulli~ (x,p) Description: The probability of a Bernoulli distribution with paramete~~ r p at x. Since a Bernoulli sample consists of 0s and 1s only, the p~~ robability is zero everywhere except at x=0 and x=1. Definition: if x=0 then (1-p)~ else if x=1 then p~ else 0 Nodelocation: 96,56,1 Nodesize: 60,24 Paramnames: x,p Function Prob_binomial(x, n,p : NonNegative) Title: Prob_Binomial(x,n,p) Description: The probability that x positive events occur in a Binomia~~ l sample of size n drawn, where the independent probability of drawin~~ g a positive sample in each draw is p. Definition: if x<0 or x>n then 0 ~ else~ Combinations(x,n) * p^x * (1-p)^(n-x) Nodelocation: 352,56,1 Nodesize: 60,24 Paramnames: x,n,p Function Prob_chancedist(x ; p:NonNegative[I] ; A : Array[I] ; I) Title: Prob_ChanceDist~ (x,P,A,I) Description: Returns the probability that a sample from ChanceDist(p,A~~ ,I) is x. Definition: var j := subIndex(A,x,I);~ if IsUndef(j) then 0~ else p[I=j] Nodelocation: 360,120,1 Nodesize: 72,24 Paramnames: x,p,A,I Function Dens_chisquared(x ; dof : positive) Title: Dens_ChiSquared~ (x,dof) Description: Returns the probability at x of a chi-squared distributio~~ n with dof degrees of freedom. Definition: 0.5^(dof/2) / Gammafn( dof/2 ) * x^(dof/2-1) * exp(-0.5 * ~~ x) Nodelocation: 112,184,1 Nodesize: 72,24 Paramnames: x,dof Function Dens_exponential(x,rate : numeric) Title: Dens_Exponential~ (x,rate) Description: The density of an exponential distribution with the given~~ rate parameter at x. Definition: rate * exp(-rate * x) Nodelocation: 264,184,1 Nodesize: 72,24 Paramnames: x,rate Function Dens_gamma(x : Nonnegative ; alpha : positive ; beta : option~~ al = 1 ) Title: Dens_Gamma~ (x,a,b) Description: The probability density of a gamma(alpha,beta) distributi~~ on at x. Definition: beta^(-alpha) * x^(alpha-1) * exp(-x/beta) / gammafn(alph~~ a) Nodelocation: 112,248,1 Nodesize: 72,24 Windstate: 2,473,89,476,218 Paramnames: x,alpha,beta Close Distribution_densiti Variable Vc Title: vc Definition: Variance(Cost) Nodelocation: 456,288,1 Nodesize: 48,24 Valuestate: 2,44,129,416,303,0,MIDM Reformval: [Pass,Dist_to_use] Index Year Title: Year Definition: [2006,2007] Nodelocation: 96,288,1 Nodesize: 48,24 Index Quarter Title: Quarter Definition: ['2006 Q1','2006 Q2','2006 Q3','2006 Q4','2007 Q1','2007 Q~~ 2','2007 Q3'] Nodelocation: 200,288,1 Nodesize: 48,24 {!40000|Att_previndexvalue: ['2006 Q1','2006 Q2','2006 Q3','2006 Q4','~~ 2007 Q1','2007 Q2','2007 Q3']} Variable Revenue_by_quarter Title: Revenue by Quarter Definition: Table(Quarter)(~ 33,44,55,66,77,55,33) Nodelocation: 192,344,1 Nodesize: 48,24 Variable Qtoy Title: QtoY Definition: Table(Quarter)(~ 2006,2006,2006,2006,2007,2007,2007) Nodelocation: 328,288,1 Nodesize: 48,24 Variable Revenue_by_year Title: Revenue by Year Definition: Sum( Revenue_by_quarter * ( Year=Qtoy ), Quarter ) Nodelocation: 304,344,1 Nodesize: 48,24 Variable Revenue_by_year1 Title: revenue by year Definition: Frequency( Qtoy, Year, Quarter, w: Revenue_by_quarter ) Nodelocation: 304,400,1 Nodesize: 48,24 Index Pass Title: pass Definition: 1..10 Nodelocation: 568,208,1 Nodesize: 48,24 {!40000|Att_previndexvalue: [1,2,3,4,5,6,7,8,9,10]} Variable Precision_of_vc Title: precision of vc Definition: sdeviation(vc,pass) Nodelocation: 576,288,1 Nodesize: 48,24 Decision Dist_to_use Title: Dist to use Definition: Choice(Self,0) Nodelocation: 456,56,1 Nodesize: 48,24 Domain: ['target','sample dist'] {!40000|Att_previndexvalue: ['target','sample dist']} Variable Sm Title: sm Definition: determTable(Dist_to_use)(~ 10,15) Nodelocation: 568,56,1 Nodesize: 48,24 Variable Ssd Title: ssd Definition: Determtable(Dist_to_use)(~ 5,7) Nodelocation: 664,56,1 Nodesize: 48,24 Close Weighting_of_samples Close Statistical_function