6 # Don't edit the line below, it must look exactly like this.
7 # Everything above this line will be replaced #
19 my $cmd_line = $0 . " " . join( " ", @ARGV );
21 ## Configure the command line parsing
22 Getopt::Long::config("auto_abbrev");
24 ## Declare the options
27 my %required_options = ();
28 my %optional_options = ("bca"=>'',
34 "skip_minimization_terminated"=>'',
35 "skip_covariance_step_terminated"=>'',
36 "skip_with_covstep_warnings"=>'',
37 "skip_estimate_near_boundary"=>'',
38 "minimization_successful_limit:f"=>'',
39 "covariance_step_successful_limit:f"=>'',
40 "covariance_step_warnings_limit:f"=>'',
41 "estimate_near_boundary_limit:f"=>'',
42 "estimate_near_boundary_limit:f"=>'',
43 "se_confidence_intervals_level:f"=>'',
44 "percentile_confidence_intervals_level:f"=>'',
45 "bca_confidence_intervals_level:f"=>'',
46 "se_confidence_intervals_check:f"=>'',
47 "percentile_confidence_intervals_check:f"=>'',
48 "bca_confidence_intervals_check:f"=>'',
49 "large_bias_limit:f"=>'' );
51 my $res = GetOptions( \%options,
52 @common_options::get_opt_strings,
53 keys(%required_options),
54 keys(%optional_options) );
58 common_options::set_globals( \%options );
59 common_options::get_defaults( \%options, 'bootstrap' );
62 $help_text{Pre_help_message} = <<'EOF';
63 <h3 class="heading1">bootstrap</h3>
65 Perl script for non-parametric boostrap of NONMEM runs.
67 <h3 class="heading1">Usage:</h3>
70 $help_text{Description
} = <<'EOF';
71 <h3 class="heading1">Description:</h3>
73 The Bootstrap can be used to calculate bias, standard errors and
74 confidence intervals. It does so by resampling with replacement
75 from the data, see Efron B, An Introduction to the Bootstrap,
76 Chap. & Hall, London UK, 1993. To compute standard errors for
77 all parameters of a model using the non-parametric bootstrap
78 implemented here, roughly 200 model fits are necessary. To assess
79 95% confidence intervals approximatly 2000 runs will suffice.
81 $help_text{Examples
} = <<'EOF';
82 <h3 class="heading1">Example:</h3>
84 <p class="style2">bootstrap -samples=200 run89.mod</p>
86 This will run a non-parametric bootstrap of 200 samples and give
87 you good estimates of the standard errors of the parameter
88 estimates. You may get some estimates for the confidence
89 intervals too, but they will generally not be of high quality.
92 <p class="style2">bootstrap -samples=2000 -bca run89.mod</p>
94 This will run a non-parametric bootstrap using the BCa technique
95 (See An introduction to the bootstrap, Efron, 1993). The BCa is
96 intended for caclulation of second-order correct confidence
100 <p class="style2">bootstrap -samples=2000 -bca -stratify_on=5 run89.mod </p>
102 This is the same BCa approach as above but with stratification
103 on the factors of column five.
106 $help_text{Options
} = <<'EOF';
107 <h3 class="heading1">Options:</h3>
109 The options are given here in their long form. Any option may be
110 abbreviated to any nonconflicting prefix. The -threads option
111 may be abbreviated to <span class="style2">-t</span> (or even <span class="style2">-thr</span>) but -<span class="style2">debug</span> may not be
112 abbreviated to <span class="style2">-d</span> because it conflicts with <span class="style2">-debug_packages</span> and
113 <span class="style2">-debug_subroutines</span>.
115 The following options are valid:
118 $help_text{-samples
} = <<'EOF';
119 <p class="style2">-samples</p>
121 The number of bootstrap samples.
124 $help_text{-sample_size
} = <<'EOF';
125 <p class="style2">-sample_size</p>
127 The number of subjects in each bootstrap data set. The default
128 value is set to the number of individuals in the original data
131 When the resampling is stratified, the sample_size option can be
132 used to specify the exact number of samples that should be drawn
133 from each strata. Below follows an example of the syntax that
134 should be used in such a case. Stratification is here done based
135 on the study number, STUD, with the values 1001, 1002 and 1003.
137 -sample_size='1001=>12,1002=>24,1003=>10'
139 This example specifies that the bootstrap should use 12 samples
140 from study 1001, 24 samples from 1002 and 10 from study 1003.
142 If only one sample size is used together with stratified
143 resampling (the default case; sample_size=number of individuals
144 in the data set), the strata are assigned samples in proportion
145 to their size in the data set. Please note that this usage of
146 the sample_size option does not guarantee that the sum of the
147 samples of the strata is equal to the given sample_size since
148 PsN needs to round the figures to the closest integer. For a
149 sample size equal to the number of individuals in the data set,
150 the sum will however always be correct.
154 $help_text{-bca
} = <<'EOF';
155 <p class="style2">-bca</p>
157 Using the <span class="style2">-bca </span>option, the bootstrap
158 utility will calculate the confidence intervals through the BCa
159 method. The default approach however, is not to use the BCa (see
160 Efron B, An introduction to the Bootstrap, 1993). The BCa is
161 intended for calculation of second-order correct confidence
165 $help_text{-stratify_on
} = <<'EOF';
166 <p class="style2">-stratify_on=integer|string</p>
168 It may be necessary to use stratification in the resampling
169 procedure. For example, if the original data consists of two
170 groups of patients - say 10 patients with full pharmacokinetic
171 profiles and 90 patients with sparse steady state concentration
172 measurements - it may be wise to restrict the resampling
173 procedure to resample within the two groups, producing bootstrap
174 data sets that all contain 10 rich + 90 sparse data patients but
175 with different compositions. The default is not to use
176 stratification. Set <span class="style2">-stratify_on</span> to
177 the column that defines the two groups. If a string is used with
178 stratify_on the header in the datafile is used to map the string
181 Note that the option sample_size has a different behavior when
182 stratified resampling is used.
185 $help_text{-skip_covariance_step_terminated
} = <<'EOF';
186 <p class="style2">-skip_covariance_step_terminated</p>
188 With this option enabled, the bootstrap will skip all samples
189 where the NONMEM run terminated the covariance step.
192 $help_text{-skip_with_covstep_warnings
} = <<'EOF';
193 <p class="style2">-skip_with_covstep_warnings</p>
195 With this option enabled, the bootstrap will skip all samples
196 where the NONMEM run had warnings from the covariance step.
199 $help_text{-skip_minimization_terminated
} = <<'EOF';
200 <p class="style2">-skip_minimization_terminated</p>
202 With this option enabled, the bootstrap will skip all samples
203 where the NONMEM run terminated the minimization step.
206 $help_text{-skip_estimate_near_boundary
} = <<'EOF';
207 <p class="style2">-skip_estimate_near_boundary</p>
209 With this option enabled, the bootstrap will skip all samples
210 where the NONMEM run signal that some estimates are near its
214 $help_text{-estimate_near_boundary_limit
} = <<'EOF';
215 <p class="style2">-estimate_near_boundary_limit='number'</p>
217 If the <span class="style2">-summarize</span> or <span class="style2">-summary</span> options are set, the bootstrap
218 will do a set of diagnostics checks. Among other things it
219 checks the ratio between runs with estimates near their
220 boundaries and those without. If the ratio is to high ( by
221 default 20% ) a warning is printed to the screen. You can change
222 the ratio with <span class="style2">-estimate_near_boundary_limit</span>.
225 $help_text{-covariance_step_successful_limit
} = <<'EOF';
226 <p class="style2">-covariance_step_successful_limit='number'</p>
228 If the <span class="style2">-summarize</span> or <span class="style2">-summary</span> options are set, the bootstrap
229 will do a set of diagnostics checks. Among other things it
230 checks the ratio between runs with covariance step succesful and
231 those without. If the ratio is to high ( by default 80% ) a
232 warning is printed to the screen. You can change the ratio with
233 <span class="style2">-covariance_step_successful_limit</span>.
236 $help_text{-covariance_step_warnings_limit
} = <<'EOF';
237 <p class="style2">-covariance_step_warnings_limit='number'</p>
239 If the <span class="style2">-summarize</span> or <span class="style2">-summary</span> options are set, the bootstrap
240 will do a set of diagnostics checks. Among other things it
241 checks the ratio between runs with warnings in the covariance
242 step and those without. If the ratio is to high (by default 20%)
243 a warning is printed to the screen. You can change the ratio
244 with <span class="style2">-covariance_step_warnings_limit</span>.
247 $help_text{-minimization_successful_limit
} = <<'EOF';
248 <p class="style2">-minimization_successful_limit='number'</p>
250 If the <span class="style2">-summarize</span> or <span class="style2">-summary</span> options are set, the bootstrap
251 will do a set of diagnostics checks. Among other things it
252 checks the ratio between runs with successful minimizations and
253 those without. If the ratio is to high (by default 80%) a
254 warning is printed to the screen. You can change the ratio with
255 <span class="style2">-minimization_successful_limit</span>.
258 $help_text{-mplots
} = <<'EOF';
259 <p class="style2">-mplots</p>
261 Generate matlab scripts for making various plots of the result.
264 $help_text{-rplots
} = <<'EOF';
265 <p class="style2">-rplots</p>
267 Generate R scripts for making various plots of the result.
269 $help_text{Post_help_message
} = <<'EOF';
270 Also see 'execute -help' for a description of common options.
273 common_options
::online_help
('bootstrap',\
%options, \
%help_text, \
%required_options, \
%optional_options);
275 debug
-> level
( $options{'debug'} );
276 debug
-> package( $options{'debug_package'} );
277 debug
-> subroutine
( $options{'debug_subroutine'} );
278 debug
-> warn_with_trace
( $options{'warn_with_trace'} );
280 ## Check that we do have a model file
281 if ( scalar(@ARGV) < 1 ) {
282 print "A model file must be specified. Use 'bootstrap -h' for help.\n";
286 if( scalar(@ARGV) > 1 ){
287 print "Bootstrap can only handle one modelfile. Use 'boostrap -h' for help.\n";
291 'ui' -> category
( 'bootstrap' );
292 'ui' -> silent
(1) if $options{'silent'};
294 my $eval_string = common_options
::model_parameters
(\
%options);
296 my $model = model
-> new
( eval( $eval_string ),
297 filename
=> @ARGV[0],
298 ignore_missing_output_files
=> 1 );
300 if( $options{'shrinkage'} ) {
301 $model -> shrinkage_stats
( enabled
=> 1 );
304 my $type = defined $options{'bca'} ?
'bca' : undef;
307 if( defined $options{'sample_size'} ) {
308 $options{'sample_size'} = 'default=>'.$options{'sample_size'} if( $options{'sample_size'} =~ /^\d+$/ );
310 $options{'sample_size'} = 'default=>'.$model -> datas
() -> [0] -> count_ind
();
312 my %subj_hash = eval($options{'sample_size'});
314 die $@
."\nThe sample_size option must be either a single digit or of the format 'strata1=>12,strata2=>34, ...' etc" ;
317 ## Create new Bootstrap object:
318 my $bs = tool
::bootstrap
->
319 new
( eval( $common_options::parameters
),
321 models
=> [ $model ],
322 samples
=> $options{'samples'},
323 subjects
=> \
%subj_hash,
325 stratify_on
=> $options{'stratify_on'},
326 skip_minimization_terminated
=> $options{'skip_minimization_terminated'},
327 skip_covariance_step_terminated
=> $options{'skip_covariance_step_terminated'},
328 skip_with_covstep_warnings
=> $options{'skip_with_covstep_warnings'},
329 skip_estimate_near_boundary
=> $options{'skip_estimate_near_boundary'},
330 minimization_successful_limit
=> $options{'minimization_successful_limit'},
331 covariance_step_successful_limit
=> $options{'covariance_step_successful_limit'},
332 covariance_step_warnings_limit
=> $options{'covariance_step_warnings_limit'},
333 estimate_near_boundary_limit
=> $options{'estimate_near_boundary_limit'},
334 estimate_near_boundary_limit
=> $options{'estimate_near_boundary_limit'},
335 se_confidence_intervals_level
=> $options{'se_confidence_intervals_level'},
336 percentile_confidence_intervals_level
=> $options{'percentile_confidence_intervals_level'},
337 bca_confidence_intervals_level
=> $options{'bca_confidence_intervals_level'},
338 se_confidence_intervals_check
=> $options{'se_confidence_intervals_check'},
339 percentile_confidence_intervals_check
=> $options{'percentile_confidence_intervals_check'},
340 bca_confidence_intervals_check
=> $options{'bca_confidence_intervals_check'},
341 large_bias_limit
=> $options{'large_bias_limit'} );
343 open(CMD
, ">", $bs -> directory
. "/command.txt");
344 print CMD
$cmd_line, "\n";
347 if ( $options{'summarize'} ) {
348 $bs -> prepare_results
();
349 $bs -> print_results
();
350 $bs -> print_summary
();
353 $bs -> prepare_results
();
354 $bs -> print_results
();
355 # $bs -> print_summary();
358 if( $options{'mplots'} ){
359 $bs -> create_matlab_scripts
();
362 if( $options{'rplots'} ){
363 $bs -> create_R_scripts
();
366 ui
-> print( category
=> 'bootstrap',
367 message
=> "Boostrap done.");