I am doing some data science on the commandline and discovered J as handy tool for basic analysis (statistics) tasks. After gaining some initial feeling for the language some years ago, I have to restart as total noob. It would be great to get some help for where I am stuck now.
I have a set of measured attribute and want to display the correlation visually. The view is often called scatterplot matrix, a good example is here. I would think a similar figure can be created in J using its great plot library.
What I have done so far:
NB. For sake of brevity, my test data is simulated here comprising 4 attributes with 7 measurements:
]A=:i. 7 4
0 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
NB. With the aid of a sparse matrix I created the index matrix of the multiplot matrix/layout
]Idx=: 4 $. $. 4 4$1
0 0
0 1
0 2
0 3
1 0
1 1
1 2
1 3
2 0
2 1
2 2
2 3
3 0
3 1
3 2
3 3
NB. Creating a single plot work fine with this sentence, here showing attribute 1 vs 3.
'TYPE marker' plot 1 1 <;.1 |: 3 1 {"1 A
NB. And here is my failed approach for creating a (multiplot) scatterplot matrix
pd 'multi 4 4'
3 : 0''
for_ijk. Idx do.
pd 1 1 <;.1 |: ijk {"1 A
end.
)
pd 'show'
First of all, doing this via a loop feels wrong in J. Is there a better way to inject the index for each plot element?
Second, the loop does not correctly feed data to plot (pd) but I could not find a way to append all the results to big matrix and feed only this to pd.
Any ideas are highly welcome! Many thanks in advance.
Your approach is fine, except that pd-multi needs, as far as I know, all data at once as a boxed list of 2-elements-lists:
(options1;data1) ; (options2;data2) ; ...
One possible way to do this is:
options =: 'type marker'
pd'reset'
pd'multi 4 4'
pd (options; <)"1 (A&({"1~)) &.> Idx
pd 'show'
assuming options is common for all plots.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With