Skip to content

Commit

Permalink
move two similar tests together, anova_rptd input more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jan 25, 2025
1 parent 7a7fe14 commit a53afb6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/PDL/Stats/GLM.pd
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ sub _ols_common {

my $Y = $ivs x $y2->dummy(0);

my $C = inv( $ivs x $ivs->xchg(0,1) );
my $C = inv( $ivs x $ivs->t );

# Fitted coefficients vector
my $coeff = PDL::squeeze( $C x $Y );
Expand Down Expand Up @@ -1082,7 +1082,7 @@ sub PDL::anova_rptd {
my $b_full = $y->ols_t( $ivs, {CONST=>0} );

$ret{ss_total} = $y->ss;
$ret{ss_residual} = $y->sse( sumover( $b_full * $ivs->xchg(0,1) ) );
$ret{ss_residual} = $y->sse( sumover( $b_full * $ivs->t ) );

if (defined $subj) {
my @full = (@$ivs_ref, @$err_ref);
Expand Down
35 changes: 16 additions & 19 deletions t/glm.t
Original file line number Diff line number Diff line change
Expand Up @@ -411,25 +411,6 @@ my %anova_bad_a = (
});
}

{ # anova_rptd mixed
my $d = pdl qw( 3 2 1 5 2 1 5 3 1 4 1 2 3 5 5 3 4 2 1 5 4 3 2 2);
my $s = sequence(4)->dummy(1,6)->flat;
# [0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3]
my $a = qsort sequence(24) % 3;
# [0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2]
my $b = (sequence(8) > 3)->dummy(1,3)->flat;
# [0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1]
my %m = $d->anova_rptd($s, $a, $b, {ivnm=>['a','b'],btwn=>[1],plot=>0, v=>0});
test_stats_cmp(\%m, {
'| a | F' => 0.0775862068965517,
'| a | ms' => 0.125,
'| a ~ b | F' => 1.88793103448276,
'| b | F' => 0.585657370517928,
'| b || err ms' => 3.48611111111111,
'# a ~ b # se' => ones(3,2) * 0.63464776,
});
}

sub test_stats_cmp {
local $Test::Builder::Level = $Test::Builder::Level + 1;
my ($m, $ans, $eps) = @_;
Expand Down Expand Up @@ -538,6 +519,22 @@ if (0) { # FIXME
test_stats_cmp(\%m, \%anova_ans_l3_common);
}

{ # anova_rptd mixed
my $d = pdl '[3 2 1 5 2 1 5 3 1 4 1 2 3 5 5 3 4 2 1 5 4 3 2 2]';
my $s = pdl '[0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3]';
my $a = pdl '[0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2]';
my $b = pdl '[0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1]';
my %m = $d->anova_rptd($s, $a, $b, {ivnm=>['a','b'],btwn=>[1],plot=>0, v=>0});
test_stats_cmp(\%m, {
'| a | F' => 0.0775862068965517,
'| a | ms' => 0.125,
'| a ~ b | F' => 1.88793103448276,
'| b | F' => 0.585657370517928,
'| b || err ms' => 3.48611111111111,
'# a ~ b # se' => ones(3,2) * 0.63464776,
});
}

{ # anova_rptd mixed bad
my $d = pdl '[3 2 1 5 2 1 5 3 1 4 1 2 3 5 5 3 4 2 1 5 4 3 2 2 1 1 1 1]';
my $s = pdl '[0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 4 4 4 4]';
Expand Down

0 comments on commit a53afb6

Please sign in to comment.