Skip to content

Commit

Permalink
vpc: add option refcorr_table
Browse files Browse the repository at this point in the history
  • Loading branch information
rikardn committed Mar 7, 2024
1 parent 836d8e1 commit 99e3939
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
9 changes: 9 additions & 0 deletions bin/vpc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ my %optional_options = ( 'idv:s' => undef,
'so!' => undef,
'mix!' => undef,
'refcorr:s' => undef,
'refcorr_table:s' => undef,
);

my $res = GetOptions( \%options,
Expand Down Expand Up @@ -511,6 +512,13 @@ $help_text{-refcorr} = <<'EOF';
Cannot be used together with -predcorr or -varcorr.
EOF

$help_text{-refcorr_table} = <<'EOF';
-refcorr_table=filename
Perform reference correction on dependent variable. Same as the refcorr option, but instead
of letting PsN create the reference simulations the user will provide them in a separate file.
EOF

$help_text{-refstrat} = <<'EOF';
-refstrat=number
Expand Down Expand Up @@ -740,6 +748,7 @@ my $vpc =
directory_name_prefix => 'vpc',
mix => $options{'mix'},
refcorr => \%refcorr,
refcorr_table => $options{'refcorr_table'},
);

$vpc-> print_options (cmd_line => $cmd_line,
Expand Down
19 changes: 14 additions & 5 deletions lib/tool/npc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ has 'results_file' => ( is => 'rw', isa => 'Str', default => 'npc_results.csv' )
has 'nca' => ( is => 'rw', isa => 'Bool', default => 0 );
has 'mix' => ( is => 'rw', isa => 'Bool', default => 0 );
has 'refcorr' => ( is => 'rw', isa => 'Maybe[HashRef]' );
has 'refcorr_table' => ( is => 'rw', isa => 'Maybe[Str]' );

sub BUILD
{
Expand All @@ -117,6 +118,9 @@ sub BUILD
if (defined $self->refcorr and not keys %{$self->refcorr}) {
$self->refcorr(undef);
}
if (defined $self->refcorr_table) {
$self->refcorr({});
}
if (defined $self->auto_bin_mode) {
unless ($self->auto_bin_mode eq 'auto' or $self->auto_bin_mode eq 'minmax' or $self->auto_bin_mode eq 'auto_equal_count') {
croak("There are only three possible auto_bin modes: auto, minmax and auto_equal_count\n");
Expand Down Expand Up @@ -1599,7 +1603,7 @@ sub modelfit_setup
problem_numbers => [$self->simprobnum()]);
$model_sims[$i] -> _write(relative_data_path => $self->copy_data);

if (defined $self->refcorr) {
if (defined $self->refcorr and not defined $self->refcorr_table) {
my %refcorr = %{$self->refcorr};
if (%refcorr) {
my $num = $i + 1;
Expand Down Expand Up @@ -3473,10 +3477,15 @@ sub create_mirror_and_plot_data

if (defined $self->refcorr) {
# Read in reference predictions from the first sample of the refcorr simulation data
my $reftab_path = $self->original_model->directory() . 'vpc_simulation_refcorr.1.' .
$self->original_model->get_option_value(record_name => 'table',
option_name => 'FILE',
problem_index => ($self->origprobnum()-1));
my $reftab_path;
if (not defined $self->refcorr_table) {
$reftab_path = $self->original_model->directory() . 'vpc_simulation_refcorr.1.' .
$self->original_model->get_option_value(record_name => 'table',
option_name => 'FILE',
problem_index => ($self->origprobnum()-1));
} else {
$reftab_path = $self->directory . '../' . $self->refcorr_table;
}
my $reftab = data->new(filename => $reftab_path, ignoresign => '@', idcolumn => 1);
my $pred_ref = $reftab->column_to_array('column'=>'PRED', 'filter'=>$filter);
my $npreds = scalar(@$pred_ref);
Expand Down

0 comments on commit 99e3939

Please sign in to comment.