Sponsored Content
Top Forums Shell Programming and Scripting 3 column .csv --> correlation matrix; awk, perl? Post 302669315 by bakunin on Tuesday 10th of July 2012 11:20:20 PM
Old 07-11-2012
Quote:
Originally Posted by R3353
I have a 3 column csv file with ~13 million rows and I would like to generate a correlation matrix.
Let us first have some rough estimations about sizes:

How many rows/columns will this matrix have? Will there be empty matrix elements? The background is: there are some limitations which may or may not affect the solution: Unix files have maximum line lengths because text processing utilities like "sed", "awk", etc. can't handle longer ones (see MAXLINE in sys/limits.h. Shell arrays cannot have more than 1024 elements.

Then some questions: How to deal with multiple entries with the same indexes - add together, generate error, other?

My take would be to first put the lines in "normal form": the lines are of the form

Code:
keyA, keyB, value

As all keys are interchangeable, so that the following two entries would in effect be the same

Code:
x, y, value
y, x, value

and the matrix you are constructing is symetrical along the main diagonal the first step should be to sort the keys within the lines by some criteria, so that the first key in the line is consistently "lower or equal" or "higher or equal" than the second key in the line.

Than a simple sort over the first two fields will reduce the problem to a simple sort-of group-change: all lines with a given keyA will represent one row AND - because the matrix is symetrical - also one column.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

correlation coefficient - Awk

Hi guys I have an input file with multiple columns and and rows. Is it possible to calculate correlation of certain value of certain No (For example x of S1 = 112) with all other values (for example start with x 112 corr a 3 of S1 = x-a 0.2 ) INPUT ******* No S1 S2 S3 S4 Sn a 3 ... (2 Replies)
Discussion started by: quincyjones
2 Replies

2. UNIX for Dummies Questions & Answers

How to extract one column from csv file in perl?

Hi everyone, i am new to perl programming, i have a problem in extracting single column from csv file. the column is the 20th column, please help me.. at present i use this code #!C:/perl/bin use warnings; use strict; my $file1 = $ARGV; open FILE1, "<$file1" or die "Can't... (13 Replies)
Discussion started by: kvth
13 Replies

3. Shell Programming and Scripting

two-column data to matrix in AWK

Howdy, I need to convert an association data matrix, currently in a two-column format, into a matrix with numbers indicating the number of associations. I've been looking around for AWK code in the list, but could not find anything. Here's an example of what I want to perform: original... (10 Replies)
Discussion started by: sramirez
10 Replies

4. Shell Programming and Scripting

awk? adjacency matrix to adjacency list / correlation matrix to list

Hi everyone I am very new at awk but think that that might be the best strategy for this. I have a matrix very similar to a correlation matrix and in practical terms I need to convert it into a list containing the values from the matrix (one value per line) with the first field of the line (row... (5 Replies)
Discussion started by: stonemonkey
5 Replies

5. Shell Programming and Scripting

awk: Transpose csv row to column.

Hello, am I new to awk, and I am tryint to: INPUT FILE: "73423555","73423556","73423557","73423558","73423559" OUTPUT FILE: 73423555 73423556 73423557 73423558 73423559 My useless code so far: #!/bin/awk -F ',' BEGIN { i=0; } (8 Replies)
Discussion started by: drbiloukos
8 Replies

6. Shell Programming and Scripting

awk read column csv and search in other csv

hi, someone to know how can i read a specific column of csv file and search the value in other csv columns if exist the value in the second csv copy entire row with all field in a new csv file. i suppose that its possible using awk but i m not expertise thanks in advance (8 Replies)
Discussion started by: giankan
8 Replies

7. Shell Programming and Scripting

Perl code to grep a particular column in CSV format

Hi I want to grep a column 6 & column 7 from a CSV Format file & then i have to find the difference between these columns as these both columns contains date & time in 7/7/2012 9:20 this format . So kindly help me out ASAP. But please kindly dis xls has to be converted in csv format as may... (5 Replies)
Discussion started by: Prateek@123
5 Replies

8. Shell Programming and Scripting

Perl- creating a matrix from a 3 column file

Dear all, I'm new in perl scripting and I'm trying to creating a matrix from a 3 column file sorting data in a particular manner. In the final matrix I need to have the first column "IDs" on the header of the columns and the second column values on the header of each row. And the value fo the... (2 Replies)
Discussion started by: gabrysfe
2 Replies

9. Shell Programming and Scripting

Transpose matrix based on second column using awk

Hi, Is it possible to transpose the matrix like this using awk ? Many thanks in advance Input abc Name_1 0 abc Name_2 1 abc Name_3 2 abc Name_4 0.4 def Name_1 0 def Name_2 9 def Name_3 78 def Name_4 1 Output abc def Name_1 0 ... (4 Replies)
Discussion started by: quincyjones
4 Replies

10. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies
Statistics::Basic::Correlation(3pm)			User Contributed Perl Documentation		       Statistics::Basic::Correlation(3pm)

NAME
Statistics::Basic::Correlation - find the correlation between two lists SYNOPSIS
Invoke it this way: my $correlation = correlation( [1,2,3], [1,2,3] ); Or this way: my $v1 = vector(1,2,3); my $v2 = vector(1,2,3); my $cor = corr($v1,$v2); And then either query the values or print them like so: print "The correlation between $v1 and $v2: $correlation "; my $cq = $cor->query; my $c0 = 0+$correlation; Create a 20 point "moving" correlation like so: use Statistics::Basic qw(:all nofill); my $sth = $dbh->prepare("select col1,col2 from data where something"); my $len = 20; my $cor = corr()->set_size($len); $sth->execute or die $dbh->errstr; $sth->bind_columns( my ($lhs, $rhs) ) or die $dbh->errstr; my $count = $len; while( $sth->fetch ) { $cor->insert( $lhs, $rhs ); if( defined( my $c = $cor->query ) ) { print "Correlation: $c "; } # This would also work: # print "Correlation: $cor " if $cor->query_filled; } METHODS
This list of methods skips the methods inherited from Statistics::Basic::_TwoVectorBase (things like query(), insert(), and ginsert()). new() Create a new Statistics::Basic::Correlation object. This function takes two arguments -- which can either be arrayrefs or Statistics::Basic::Vector objects. This function is called when the correlation() shortcut-function is called. query_covariance() Returns the Statistics::Basic::Covariance object used to calculate the correlation. query_vector1() Return the Statistics::Basic::Vector for the first vector. query_vector2() Return the Statistics::Basic::Vector object for the second vector. query_mean1() Returns the Statistics::Basic::Mean object for the first vector. query_mean2() Returns the Statistics::Basic::Mean object for the second vector. OVERLOADS
This object is overloaded. It tries to return an appropriate string for the calculation or the value of the computation in numeric context. In boolean context, this object is always true (even when empty). AUTHOR
Paul Miller "<jettero@cpan.org>" COPYRIGHT
Copyright 2012 Paul Miller -- Licensed under the LGPL SEE ALSO
perl(1), Statistics::Basic, Statistics::Basic::_TwoVectorBase, Statistics::Basic::Vector perl v5.14.2 2012-01-23 Statistics::Basic::Correlation(3pm)
All times are GMT -4. The time now is 11:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy