Skip to content

Commit

Permalink
Add ntrt option to frem
Browse files Browse the repository at this point in the history
  • Loading branch information
rikardn committed Feb 8, 2024
1 parent 4ed0bdb commit f0b11b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
9 changes: 9 additions & 0 deletions bin/frem
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ my %optional_options = (
'categorical:s' => undef,
'deriv2_nocommon_maxeta:i' => undef,
"mceta:i"=>'',
'ntrt:s' => undef,
'log:s' => undef,
'rse:f' => undef,
'run_sir!' => undef,
Expand Down Expand Up @@ -221,6 +222,13 @@ $help_text{-mu} = <<'EOF';
so that any skipped omegas come first.
EOF

$help_text{-ntrt} = <<'EOF';
-ntrt
Column name for number of individuals in aggregate data. Default not used.
EOF


$help_text{-rescale} = <<'EOF';
-rescale
Expand Down Expand Up @@ -327,6 +335,7 @@ my $frem = tool::frem->new(
bipp => $options{'bipp'},
force_posdef_covmatrix => $options{'force_posdef_covmatrix'},
force_posdef_samples => $options{'force_posdef_samples'},
ntrt => $options{'ntrt'},
);

$frem->print_options(
Expand Down
20 changes: 15 additions & 5 deletions lib/tool/frem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ has 'tool_options' => ( is => 'rw', isa => 'HashRef' ); # tool options hash
has 'bipp' => ( is => 'rw', isa => 'Bool', default => 0 );
has 'force_posdef_covmatrix' => ( is => 'rw', isa => 'Bool', default => 0 );
has 'force_posdef_samples' => ( is => 'rw', isa => 'Int', default => 500 );
has 'ntrt' => ( is => 'rw', isa => 'Str' );


has '_intermediate_models_path' => ( is => 'rw', isa => 'Str' );
Expand Down Expand Up @@ -1444,6 +1445,7 @@ sub get_pred_error_pk_code
likelihood => { isa => 'Bool', default => 0},
loglikelihood => { isa => 'Bool', default => 0},
have_fflag => { isa => 'Bool', default => 0},
ntrt => { isa => 'Maybe[Str]' },
);
my $covariates = $parm{'covariates'};
my $maxeta = $parm{'maxeta'};
Expand All @@ -1460,6 +1462,7 @@ sub get_pred_error_pk_code
my $likelihood = $parm{'likelihood'};
my $loglikelihood = $parm{'loglikelihood'};
my $have_fflag = $parm{'have_fflag'};
my $ntrt = $parm{'ntrt'};

my @pkcode;
my @pred_error_code = (';;;FREM CODE BEGIN COMPACT',';;;DO NOT MODIFY');
Expand All @@ -1482,6 +1485,12 @@ sub get_pred_error_pk_code
my @rescale_strings;
my @rescale_factors;

if (defined $ntrt) {
$ntrt = '/SQRT(' . $ntrt . ')';
} else {
$ntrt = '';
}

for (my $j = 0; $j < scalar(@{$covariates}); $j++) {
my $label = 'BSV_' . $covariates->[$j];
my $etanum = ($maxeta + 1 + $j);
Expand Down Expand Up @@ -1529,11 +1538,11 @@ sub get_pred_error_pk_code
for (my $j = 0; $j < scalar(@{$covariates}); $j++) {
my $etanum = ($maxeta + 1 + $j);
if ($rescale) {
push(@mucode, $indent.'MU_'.$etanum.' = '.$theta_strings[$j].'/SDC'.$etanum);
push(@mucode, $indent.'COV'.$etanum.' = (MU_'.$etanum.' + '.$eta_strings[$j]->[0].')*SDC'.$etanum);
push(@mucode, $indent . 'MU_' . $etanum . ' = ' . $theta_strings[$j] . '/SDC' . $etanum);
push(@mucode, $indent . 'COV' . $etanum . ' = (MU_' . $etanum . ' + ' . $eta_strings[$j]->[0] . $ntrt . ')*SDC' . $etanum);
} else {
push(@mucode,$indent.'MU_'.$etanum.' = '.$theta_strings[$j]);
push(@mucode,$indent.'COV'.$etanum.' = MU_'.$etanum.' + '.$eta_strings[$j]->[0]);
push(@mucode, $indent . 'MU_' . $etanum . ' = ' . $theta_strings[$j]);
push(@mucode, $indent . 'COV' . $etanum . ' = MU_' . $etanum . ' + ' . $eta_strings[$j]->[0] . $ntrt);
}
}
push(@code,@mucode);
Expand All @@ -1552,7 +1561,7 @@ sub get_pred_error_pk_code
$ipred = 'COV'.($maxeta+1+$i);
}else{
my $rescale_expr = $rescale ? '*'.$rescale_strings[$i] : '';
$ipred = $theta_strings[$i].' + '.$eta_strings[$i]->[$j].$rescale_expr;
$ipred = $theta_strings[$i] . ' + ' . $eta_strings[$i]->[$j] . $rescale_expr . $ntrt;
}
if ($N_parameter_blocks > 1){
$comment .= ' occasion '.($j+1);
Expand Down Expand Up @@ -1625,6 +1634,7 @@ sub prepare_model2
likelihood => $self->_likelihood,
loglikelihood => $self->_loglikelihood,
have_fflag => $self->_have_fflag,
ntrt => $self->ntrt,
);

cleanup_outdated_model(modelname => File::Spec->catfile($self->_intermediate_models_path, $name_model),
Expand Down

0 comments on commit f0b11b4

Please sign in to comment.