سؤال

I have a table with columns a, b, c. Can I calculate the correlation matrix of cor[a;a], cor[a;b], cor[a;c] using functional form somehow?

?[table; (); 0b; (`aa`ab`ac)!((cor; `a; `a); (cor; `a; `b);(cor; `a; `b));

How can i generate the list of the last argument? (cor; a;b)

هل كانت مفيدة؟

المحلول 2

So manually typed out form:

q)t:([] a:10?10; b:10?10; c:10?10)
q)?[t;();0b;`aa`ab`ac!((cor;`a;`a);(cor;`a;`b);(cor;`a;`c))]
   aa ab         ac
   -----------------------
   1  -0.2530506 0.7966834

If you wanted to generate the last argument, assuming you wanted all permutations of first column combined with all columns:

q)a:{(`$raze'[string x])!(cor),/:x}{x[0],/:x}cols t;
q)?[t;();0b;a]
   aa ab         ac
   -----------------------
   1  -0.2530506 0.7966834

If you wanted all column permutations:

q)a:{(`$raze'[string x])!(cor),/:x}{x cross x}cols t
q)?[t;();0b;a]
   aa ab         ac        ba         bb bc        ca        cb        cc
   ----------------------------------------------------------------------
   1  -0.2530506 0.7966834 -0.2530506 1  -0.268787 0.7966834 -0.268787 1

نصائح أخرى

q)show t:([]a:5?1.0;b:5?1.0;c:5?1.0)
a          b         c
------------------------------
0.389056   0.949975  0.6919531
0.391543   0.439081  0.4707883
0.08123546 0.5759051 0.6346716
0.9367503  0.5919004 0.9672398
0.2782122  0.8481567 0.2306385

q)u cor/:\:u:flip t
 | a          b          c
-| --------------------------------
a| 1          -0.1328262 0.6671159
b| -0.1328262 1          -0.1830702
c| 0.6671159  -0.1830702 1
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top