SURVO MM Help System (web edition)

Matrix files in VAR operation

Either constants or data values saved as vectors or matrices in
matrix files (with extension .MAT) can be referred to in the VAR
operation. This is done by MAT_A(i,j) functions giving the value
of the element on the i'th row and j'th column of a matrix A
saved as A.MAT before the VAR operation is activated.
Name `A' can be replaced by any other of max. 8 characters.
In one VAR operation 20 different matrices can be used simultaneously
in this way. Each matrix is loaded in the memory when it is called
for the first time by any of the MAT_ functions.
If the matrix consists of one column or row, a MAT_ function can
be written with only one argument as MAT_A(i).

Example 1: Sampling with replacement
Assume that we have a `population' of 10000 observations
described by 3 variables X1,X2,X3 in a Survo data file DATA3
and we want to have a sample with replacement of 500 observations
as a new data file SAMPLE3.

MAT SAVE DATA DATA3 TO D3  / Saving data to a matrix file D3
................................................................................
FILE CREATE SAMPLE3,12,3    / Creating a new file for the sample
FIELDS:
1 N 4 X1
2 N 4 X2
3 N 4 X3
END
FILE INIT SAMPLE3,500       / 500 missing observations
................................................................................
VAR X1,X2,X3 TO SAMPLE3    / Making the sample
i=int(10000*rand(1998))+1  / Random integer 1,2,...,10000
X1=MAT_D3(i,1) X2=MAT_D3(i,2) X3=MAT_D3(i,3)

Another example on the next pages!

Example 2:
Variable S is defined as a function of x as a sum
  S=a1*exp(-b1*x)+a2*exp(-b2*x)+...+a20*exp(-b20*x)
where a's and b's are constants and x a variable in a Survo data D.
Assume that constants a1,...,a20 are saved in a matrix file A and
constants b1,...,b20 in matrix file B.
................................................................................
Then S will be computed by
VAR S=for(i=1)to(20)sum(a(i)*exp(-b(i)*x)) TO D
a(i):=MAT_A(i)
b(i):=MAT_B(i) .
Definition of temporary functions a() and b() enables writing the formula
in a more readable form.
Numerical example on the next page!
................................................................................
An alternative:
If a's and b's are the two (first) coulumns in a matrix C,
the temporary functions a() and b() would be expressed as
a(i):=MAT_C(i,1) b(i):=MAT_C(i,2) .
................................................................................

   Numerical example (with coefficients selected at random):
MAT A=ZER(20,1)
MAT B=ZER(20,1)
MAT #TRANSFORM A BY 10*rand(1998)   / a's uniform in (0,10)
MAT #TRANSFORM B BY rand(1999)      / b's uniform  in (0,1)
a(i):=MAT_A(i) b(i):=MAT_B(i)
VAR S=for(i=1)to(20)sum(a(i)*exp(-b(i)*x)) TO D

DATA D,A,A+5,A-1,A-2
 11  11.11111
  x     S
  1  46.76749
  2  29.58383
  3  20.09316
  4  14.53685
  5  11.09308
  6   8.84248

     V = More information on VAR operation 


More information on Survo from www.survo.fi
Copyright © Survo Systems 2001-2012.
webmaster'at'survo.fi