여기에 PDL::Stats 모듈을 같이 사용하면 오픈소스 통계패키지인 R같이 여러가지 통계계산도 할 수 있다.
다음은 어떤 데이터의 평균, 분산, 표준편차, 어떤 두 데이터간의 공분산과 상관계수를 구하는 예제 코드이다.
#!/usr/bin/env perl
use 5.010;
use PDL;
use PDL::Stats;
use PDL::Graphics::PGPLOT::Window;
my $data = pdl( [1,1,5,6,7,3,3,9,4,10,8,6,6,2,6,15] );
say "data: ",$data;
say "average: ",$data->average;
say "variance: ",$data->var;
say "standard deviation: ",$data->stdv;
my $x = pdl( [1,2,3,4,5,6] );
my $y = pdl( [1,1.5,2,2.25,2.5,3] );
my $y2 = pdl( [6,5,4,3,2,1] );
say "x:", $x;
say "y:", $y;
say "y2:", $y2;
say "covariance x,y: ",$x->cov($y);
say "correlation x,y: ",$x->corr($y);
say "covariance x,y2: ",$x->cov($y2);
say "correlation: x,y2: ",$x->corr($y2);
my $win = pgwin();
$win->hold();
$win->env(0,10,0,10);
$win->points($x,$y, {SYMBOL=>'SQUARE', COLOR=>'BLUE'});
$win->points($x,$y2, {SYMBOL=>'PLUS', COLOR=>'CYAN'});
<결과>
data: [1 1 5 6 7 3 3 9 4 10 8 6 6 2 6 15] average: 5.75 variance: 12.4375 standard deviation: 3.52668399491647 x:[1 2 3 4 5 6] y:[1 1.5 2 2.25 2.5 3] y2:[6 5 4 3 2 1] covariance x,y: 1.10416666666667 correlation x,y: 0.991332701357794 covariance x,y2: -2.91666666666667 correlation: x,y2: -1
차후에는 여러가지 확률분포에 대해 테스트해보고자 한다.

댓글 없음:
댓글 쓰기