Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #
- #
- # Messing around doing PCA analyses with Perl
- #
- #
- use Statistics::PCA;
- # Create new Statistics::PCA object.
- my $pca = Statistics::PCA->new;
- # Var1 Var2 Var3 Var4...
- my @Obs1 = (qw/ 2 4 3 1 /);
- my @Obs2 = (qw/ 5 10 6 2/);
- my @Obs3 = (qw/ 4 2 1 5/);
- my @Obs4 = (qw/ 3 6 7 3/);
- # my @Obs5 = (qw/ 63 35 34 2/);
- # Load data. Data is loaded as a LIST-of-LISTS (LoL) pointed to by a named argument 'data'. Requires argument for format (see METHODS).
- $pca->load_data ( { format => 'table', data => [ \@Obs1, \@Obs2, \@Obs3, \@Obs4], } ) ;
- # Perform the PCA analysis. Takes optional argument 'eigen' (see METHODS).
- #$pca->pca( { eigen => 'C' } );
- $pca->pca();
- @list = $pca->results('full');
- for my $i (@list) {
- print qq{\nPC rank: $i->[0]}
- . qq{\nPC stdev $i->[1]}
- . qq{\nPC proportion of variance $i->[2]}
- . qq{\nPC cumulative variance $i->[3]}
- . qq{\nPC eigenvalue $i->[4]}
- }
- @list = $pca->results('transformed');
- print qq{\nThe transformed data for 'the' principal component (first PC): @{$list[0]}\n };
- print qq{\nnThe transformed data for 'the' principal component (second PC): @{$list[1]}\n };
- print qq{\nnThe transformed data for 'the' principal component (third PC): @{$list[2]}\n };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement