1
votes

I am testing to use one of perl's modules, Statistics :: Sequences :: Runs. I tried to run the example in the path below, but I get an error. https://metacpan.org/pod/Statistics::Sequences::Runs

The code below is example code, and the last line is an error message that is output when this code is executed.

use Statistics::Sequences::Runs;
use Statistics::Data::Dichotomize;
my @targets = (qw/p c p w s p r w p c r c r s s s s r w p r w c w c/);
my @responses = (qw/p c s c s s p r w r w c c s s r w s w p c r w p r/);

# Test for runs of matches between targets and responses:
my $runs = Statistics::Sequences::Runs->new();
my $ddat = Statistics::Data::Dichotomize->new();
$runs->load($ddat->match(data => [\@targets, \@responses]));
$runs->dump_data(delim => ' '); # have a look at the match sequence; prints "1 1 0 0 1 0 0 0 0 0 0 1 0 1 1 0 0 0 1 1 0 0 0 0 0\n"
print "Probability of these many runs vs expectation: ", $runs->test(), "\n"; # 0.51436
# or test for runs in matching when responses are matched to targets one trial behind:
print $runs->test(data => $ddat->match(data => [\@targets, \@responses], lag => -1)), "\n"; # 0.73766

Can't locate object method "dump_data" via package "Statistics::Sequences::Runs" at example.pl line 10.

Does anyone know how to fix this error?

1
Difficult to say, since that method is in the package. Either it's an old version which didn't have it, or $runs, for some reason, does not have valid information. - jjmerelo
Statistics::Sequences::Runs has no dump_data anywhere in its inheritance tree (contrary to what the docs suggest and what @jjmerelo said). There's a dump_vals method (in Statistics::Data, the base class of the base class of Statistics::Sequences::Runs) that takes a delims option. Is that the method you want? - ikegami

1 Answers

2
votes
  • ->dump_data should be ->dump_vals.
  • ->tests should be ->p_value (both instances).

While not relevant with the above changes, I came across yet another bug. In Statistics::Sequences's test,

my $statname = $args->{'stat'} || q{};
my $class    = __PACKAGE__ . q{::} . ucfirst($statname);
eval {require $class};
if ($@) {
    croak __PACKAGE__, " error: Requested sequences module '$class' is not available";
}

should be

my $statname = $args->{'stat'} || croak("Required stat argument missing");
my $class    = __PACKAGE__ . q{::} . ucfirst($statname);
my $pkg      = $class =~ s{::}{/}gr . '.pm';
eval {require $pkg };
if ($@) {
    croak __PACKAGE__, " error: Requested sequences module '$class' is not available";
}