From f0b11b45b42ade73814621a5b01445e792f00ec7 Mon Sep 17 00:00:00 2001 From: Rikard Nordgren Date: Thu, 8 Feb 2024 13:14:17 +0100 Subject: [PATCH] Add ntrt option to frem --- bin/frem | 9 +++++++++ lib/tool/frem.pm | 20 +++++++++++++++----- pharmpy | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/bin/frem b/bin/frem index 005b5804d..39018301b 100755 --- a/bin/frem +++ b/bin/frem @@ -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, @@ -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 @@ -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( diff --git a/lib/tool/frem.pm b/lib/tool/frem.pm index e9c53debc..7e6355536 100644 --- a/lib/tool/frem.pm +++ b/lib/tool/frem.pm @@ -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' ); @@ -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'}; @@ -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'); @@ -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); @@ -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); @@ -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); @@ -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), diff --git a/pharmpy b/pharmpy index a32ec40ac..f4c7edf80 160000 --- a/pharmpy +++ b/pharmpy @@ -1 +1 @@ -Subproject commit a32ec40acdb80f31697a5889041a08bb6ff7febf +Subproject commit f4c7edf8065efce9ad49768877f85591f655dc93