Skip to content

Commit 4b29adf

Browse files
committed
extend cor() and cov() to support correlation/covariance matrices
1 parent b9cdfbc commit 4b29adf

7 files changed

Lines changed: 580 additions & 239 deletions

File tree

EidosScribe/EidosHelpFunctions.rtf

Lines changed: 124 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -857,18 +857,33 @@
857857
\pard\pardeftab720\li720\fi-446\ri720\sb180\sa60\partightenfactor0
858858
859859
\f1\b0\fs18 \cf2 \expnd0\expndtw0\kerning0
860-
(float$)cor(numeric\'a0x, numeric\'a0y)\
860+
(float)cor(numeric\'a0x, \kerning1\expnd0\expndtw0 [Nif\'a0y\'a0=\'a0NULL]\expnd0\expndtw0\kerning0
861+
)\
861862
\pard\pardeftab720\li547\ri720\sb60\sa60\partightenfactor0
862863

863-
\f3\fs20 \cf2 Returns the
864+
\f3\fs20 \cf2 \kerning1\expnd0\expndtw0 Returns the
864865
\f0\b sample Pearson\'92s correlation coefficient
865-
\f3\b0 between
866+
\f3\b0 between vectors
866867
\f1\fs18 x
867868
\f3\fs20 and
868869
\f1\fs18 y
869870
\f3\fs20 , usually denoted
870871
\f7\i r
871-
\f3\i0 . The sizes of
872+
\f3\i0 . If
873+
\f1\fs18 y
874+
\f3\fs20 is
875+
\f1\fs18 NULL
876+
\f3\fs20 , it is considered to have the same value as
877+
\f1\fs18 x
878+
\f3\fs20 ; for vector
879+
\f1\fs18 x
880+
\f3\fs20 this is not very useful (since the correlation of
881+
\f1\fs18 x
882+
\f3\fs20 with itself is
883+
\f1\fs18 1.0
884+
\f3\fs20 by definition), but it is more useful for calculating a correlation matrix using the columns of
885+
\f1\fs18 x
886+
\f3\fs20 (see below). The sizes of
872887
\f1\fs18 x
873888
\f3\fs20 and
874889
\f1\fs18 y
@@ -880,23 +895,68 @@
880895
\f1\fs18 0
881896
\f3\fs20 or
882897
\f1\fs18 1
883-
\f3\fs20 , the return value will be
898+
\f3\fs20 , an error will be raised (a change in behavior from Eidos 4.0; it used to return
884899
\f1\fs18 NULL
885-
\f3\fs20 . At present it is illegal to call
900+
\f3\fs20 ). The return value will be a singleton
901+
\f1\fs18 float
902+
\f3\fs20 .\
903+
It is also legal to call
886904
\f1\fs18 cor()
887-
\f3\fs20 with a matrix or array argument, because the desired behavior in that case has not yet been implemented.\
905+
\f3\fs20 with matrix
906+
\f1\fs18 x
907+
\f3\fs20 and/or
908+
\f1\fs18 y
909+
\f3\fs20 . In this case the return value will be a correlation matrix between x and y. Each column of
910+
\f1\fs18 x
911+
\f3\fs20 will be represented by one row of the result (or if
912+
\f1\fs18 x
913+
\f3\fs20 is a vector, the result will simply have one row representing
914+
\f1\fs18 x
915+
\f3\fs20 ), and each column of
916+
\f1\fs18 y
917+
\f3\fs20 will be represented by one column of the result (or if
918+
\f1\fs18 y
919+
\f3\fs20 is a vector, the result will simply have one column representing
920+
\f1\fs18 y
921+
\f3\fs20 ). Each element in the result matrix will therefore represent the correlation between a column of matrix
922+
\f1\fs18 x
923+
\f3\fs20 (or the entirety of vector
924+
\f1\fs18 x
925+
\f3\fs20 ) and a column of matrix
926+
\f1\fs18 y
927+
\f3\fs20 (or the entirety of vector y). Calling
928+
\f1\fs18 cor(x, x)
929+
\f3\fs20 , or equivalently
930+
\f1\fs18 cor(x)
931+
\f3\fs20 , thus produces a symmetric correlation matrix among the columns of
932+
\f1\fs18 x
933+
\f3\fs20 .\
888934
\pard\pardeftab720\li720\fi-446\ri720\sb180\sa60\partightenfactor0
889935

890-
\f1\fs18 \cf2 (float$)cov(numeric\'a0x, numeric\'a0y)\
936+
\f1\fs18 \cf2 \expnd0\expndtw0\kerning0
937+
(float)cov(numeric\'a0x, \kerning1\expnd0\expndtw0 [Nif\'a0y\'a0=\'a0NULL]\expnd0\expndtw0\kerning0
938+
)\
891939
\pard\pardeftab720\li547\ri720\sb60\sa60\partightenfactor0
892940

893-
\f3\fs20 \cf2 Returns the
941+
\f3\fs20 \cf2 \kerning1\expnd0\expndtw0 Returns the
894942
\f0\b corrected sample covariance
895-
\f3\b0 between
943+
\f3\b0 between vectors
896944
\f1\fs18 x
897945
\f3\fs20 and
898946
\f1\fs18 y
899-
\f3\fs20 . The sizes of
947+
\f3\fs20 . If
948+
\f1\fs18 y
949+
\f3\fs20 is
950+
\f1\fs18 NULL
951+
\f3\fs20 , it is considered to have the same value as
952+
\f1\fs18 x
953+
\f3\fs20 ; for vector
954+
\f1\fs18 x
955+
\f3\fs20 this is equivalent to calling
956+
\f1\fs18 var(x)
957+
\f3\fs20 , but it is more useful for calculating a variance-covariance matrix using the columns of
958+
\f1\fs18 x
959+
\f3\fs20 (see below). The sizes of
900960
\f1\fs18 x
901961
\f3\fs20 and
902962
\f1\fs18 y
@@ -908,14 +968,45 @@
908968
\f1\fs18 0
909969
\f3\fs20 or
910970
\f1\fs18 1
911-
\f3\fs20 , the return value will be
971+
\f3\fs20 , an error will be raised (a change in behavior from Eidos 4.0; it used to return
912972
\f1\fs18 NULL
913-
\f3\fs20 . At present it is illegal to call
973+
\f3\fs20 ). The return value will be a singleton
974+
\f1\fs18 float
975+
\f3\fs20 .\
976+
It is also legal to call
914977
\f1\fs18 cov()
915-
\f3\fs20 with a matrix or array argument, because the desired behavior in that case has not yet been implemented.\
978+
\f3\fs20 with matrix
979+
\f1\fs18 x
980+
\f3\fs20 and/or
981+
\f1\fs18 y
982+
\f3\fs20 . In this case the return value will be a covariance matrix between x and y. Each column of
983+
\f1\fs18 x
984+
\f3\fs20 will be represented by one row of the result (or if
985+
\f1\fs18 x
986+
\f3\fs20 is a vector, the result will simply have one row representing
987+
\f1\fs18 x
988+
\f3\fs20 ), and each column of
989+
\f1\fs18 y
990+
\f3\fs20 will be represented by one column of the result (or if
991+
\f1\fs18 y
992+
\f3\fs20 is a vector, the result will simply have one column representing
993+
\f1\fs18 y
994+
\f3\fs20 ). Each element in the result matrix will therefore represent the covariance between a column of matrix
995+
\f1\fs18 x
996+
\f3\fs20 (or the entirety of vector
997+
\f1\fs18 x
998+
\f3\fs20 ) and a column of matrix
999+
\f1\fs18 y
1000+
\f3\fs20 (or the entirety of vector y). Calling
1001+
\f1\fs18 cov(x, x)
1002+
\f3\fs20 , or equivalently
1003+
\f1\fs18 cov(x)
1004+
\f3\fs20 , thus produces a symmetric variance-covariance matrix among the columns of
1005+
\f1\fs18 x
1006+
\f3\fs20 .\
9161007
\pard\pardeftab720\li720\fi-446\ri720\sb180\sa60\partightenfactor0
9171008

918-
\f1\fs18 \cf2 \kerning1\expnd0\expndtw0 (float)filter(numeric\'a0x, float\'a0filter, [lif$\'a0outside\'a0=\'a0F])\
1009+
\f1\fs18 \cf2 (float)filter(numeric\'a0x, float\'a0filter, [lif$\'a0outside\'a0=\'a0F])\
9191010
\pard\pardeftab720\li547\ri720\sb60\sa60\partightenfactor0
9201011

9211012
\f3\fs20 \cf2 Returns the result of convolving
@@ -1338,23 +1429,25 @@ The result for all of these
13381429
\f1\fs18 \cf0 (float$)sd(numeric
13391430
\f2 \'a0
13401431
\f1 x)\
1341-
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
1432+
\pard\pardeftab543\li547\ri720\sb60\sa60\partightenfactor0
13421433

1343-
\f3\fs20 \cf0 Returns the
1434+
\f3\fs20 \cf2 Returns the
13441435
\f0\b corrected sample standard deviation
13451436
\f3\b0 of
13461437
\f1\fs18 x
1347-
\f2\fs20 .
1348-
\f3 If
1438+
\f3\fs20 . If
13491439
\f1\fs18 x
13501440
\f3\fs20 has a size of
13511441
\f1\fs18 0
13521442
\f3\fs20 or
13531443
\f1\fs18 1
1354-
\f2\fs20 ,
1355-
\f3 the return value will be
1444+
\f3\fs20 , an error will be raised (a change in behavior from Eidos 4.0; it used to return
13561445
\f1\fs18 NULL
1357-
\f2\fs20 .\
1446+
\f3\fs20 ). Matrix/array dimensions are ignored by
1447+
\f1\fs18 sd()
1448+
\f3\fs20 ; it simply uses all of the elements of
1449+
\f1\fs18 x
1450+
\f3\fs20 for its calculation.\
13581451
\pard\pardeftab543\li720\fi-446\ri720\sb180\sa60\partightenfactor0
13591452

13601453
\f1\fs18 \cf0 (float$)ttest(float
@@ -1412,7 +1505,7 @@ The result for all of these
14121505
(float$)var(numeric\'a0x)\
14131506
\pard\pardeftab543\li547\ri720\sb60\sa60\partightenfactor0
14141507

1415-
\f3\fs20 \cf2 Returns the
1508+
\f3\fs20 \cf2 \kerning1\expnd0\expndtw0 Returns the
14161509
\f0\b corrected sample variance
14171510
\f3\b0 of
14181511
\f1\fs18 x
@@ -1422,16 +1515,18 @@ The result for all of these
14221515
\f1\fs18 0
14231516
\f3\fs20 or
14241517
\f1\fs18 1
1425-
\f3\fs20 , the return value will be
1518+
\f3\fs20 , an error will be raised (a change in behavior from Eidos 4.0; it used to return
14261519
\f1\fs18 NULL
1427-
\f3\fs20 . This is the square of the standard deviation calculated by
1520+
\f3\fs20 ). This is the square of the standard deviation calculated by
14281521
\f1\fs18 sd()
1429-
\f3\fs20 . At present it is illegal to call
1522+
\f3\fs20 . It is illegal to call
14301523
\f1\fs18 var()
1431-
\f3\fs20 with a matrix or array argument, because the desired behavior in that case has not yet been implemented.\
1524+
\f3\fs20 with a matrix or array argument; use
1525+
\f1\fs18 cov()
1526+
\f3\fs20 to calculate a variance-covariance matrix.\
14321527
\pard\pardeftab397\ri720\sb360\sa60\partightenfactor0
14331528

1434-
\f0\b\fs22 \cf0 \kerning1\expnd0\expndtw0 3.3. Distribution drawing and density functions\
1529+
\f0\b\fs22 \cf0 3.3. Distribution drawing and density functions\
14351530
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0
14361531
14371532
\f1\b0\fs18 \cf2 \expnd0\expndtw0\kerning0
@@ -5406,6 +5501,7 @@ See
54065501
\f3\fs20 will be returned; if not,
54075502
\f1\fs18 F
54085503
\f3\fs20 will be returned (but at present, an error will result instead).\cf0 \
5504+
\pard\pardeftab543\li547\ri720\sb60\sa60\partightenfactor0
54095505
\cf2 If
54105506
\f1\fs18 compress
54115507
\f3\fs20 is

0 commit comments

Comments
 (0)