NCL Home > Documentation > Functions > Statistics, Bootstrap


Bootstrap estimates of a user specified statistic derived from a variable.

Available in version 6.4.0 and later.


	function bootstrap_stat (
		z         : numeric,  
		stat  [1] : integer,  
		nBoot [1] : integer,  
		nDim  [*] : integer,  
		opt   [1] : logical   

	return_val [ variable of type 'list' containing multiple estimates] 



A numeric array of up to four dimensions: z(N), z(N,:), Z(N,:,:), Z(N,:,:,:). 'N' represents the original sample size.


An integer which specifies the statistic to be bootstrapped. Currently:

  • =0 is for the 'mean' ('average')
  • =1 is for the 'standard deviation'
  • =2 is for the 'variance'
  • =3 is for the 'median'
  • =4 is for the 'min'
  • =5 is for the 'max'
  • =6 is for the 'sum'


An integer specifying the number of bootstrap data samples to be generated.


The dimension(s) of z on which to calculate the statistic. Must be consecutive and monotonically increasing.


A logical scalar to which optional attributes may be attached. If opt=False, default values are used. If opt=True and no optional attributes are present, default values will be used. If opt=True then:

  • opt@sample_size: specifies the size of the resampled array to be used for the bootstrapped statistics.
  • opt@sample_size=N is the default.
  • opt@sample_size=n where (n.le.N). Most commonly, when this option is used, n=toint(f*N) where 'f' represents (say) 0.10 to 0.20.

  • opt@sample_method: specifies the sampling method to use.
  • opt@sample_method=1 specifies sampling-with-replacement. This is the default.
  • opt@sample_method=0 specifies sampling-without-replacement.

  • opt@rseed1=rseed1: allows user to set the first random seed integer value. Default is to use the system initial random seed. (See: random_setallseed)
  • opt@rseed2=rseed2: allows user to set the second random seed integer value. Default is to use the system initial random seed. (See: random_setallseed)
  • optrseed3="clock": tells NCL to use the 'date' clock to set the two random seeds. (See: random_setallseed)

Return value

A variable of type 'list'. Members of a list can be accessed directly. However, it is clearer if the members are explicity extracted and given meaningful names.

                                    ; typeof(Bootstrap) is 'list'
   BootStrap  = bootstrap_stat(z, stat, nBoot, 0, opt)
                                    ; For clarity; extract variables from 'list'
   zBoot      = BootStrap[0]        ; bootstrapped values in ascending order
   zAvg       = BootStrap[1]        ; Calculated Mean(s) of the original sample
   zStd       = BootStrap[2]        ; Calculated Sample Standard Deviation(s) of the 
   delete(BootStrap)                ; no longer needed


Bootstrapping is a statistical method that uses data resampling with replacement (see: generate_sample_indices) to estimate the properties of nearly any statistic. It is particularly useful when dealing with small sample sizes. A key feature is that bootstrapping makes no apriori assumption about the distribution of the sample data.


Computer Intensive Methods in Statistics 
   P. Diaconis and B. Efron 
   Scientific American (1983), 248:116-130  
An Introduction to the Bootstrap 
   B. Efron and R.J. Tibshirani, Chapman and Hall (1993) 
Bootstrap Methods and Permutation Tests: Companion Chapter 18 to the Practice of Business Statistics
   Hesterberg, T. et al (2003)

Climate Time Series Analysis: Classical Statistical and Bootstrap Methods
   M. Mudelsee (2014) Second edition. Springer, Cham Heidelberg New York Dordrecht London
   ISBN: 978-3-319-04449-1, e-ISBN: 978-3-319-04450-7
   doi: 10.1007/978-3-319-04450-7
   xxxii + 454 pp; Atmospheric and Oceanographic Sciences Library, Vol. 51

See Also

bootstrap_diff, bootstrap_correl, bootstrap_regcoef, bootstrap_estimate generate_sample_indices, ListIndexFromName


Please see the Bootstrap and Resampling application page.

Example 1: Let x(N); N=100

   nBoot      = 1000          ; user set
   stat=      = 0             ; mean
   nDim       = 0             ; dimenion identifier (since x is one-dimensional)
   opt        = False         ; all defaults are being used

   BootStrap  = bootstrap_stat(x, stat, nBoot, nDim, opt)
                          ; for clarity, explicitly extract the variables from the 'lit'
   xBoot      = BootStrap[0]  ; bootstrapped values in ascending order
   xAvg       = BootStrap[1]  ; Mean of the bootstrapped values
   xStd       = BootStrap[2]  ; Sample Standard Deviation of bootstrapped values 
   delete(BootStrap)          ; no longer needed

   xBootLow   = bootstrap_estimate(xBoot, 0.025, False)   ;  2.5% lower confidence bound 
   xBootMed   = bootstrap_estimate(xBoot, 0.500, False)   ; 50.0% median of bootstrapped estimates
   xBootHi    = bootstrap_estimate(xBoot, 0.975, False)   ; 97.5% upper confidence bound

   printVarSummary(xBoot)        ; information only
   printVarSummary(xBootMed)     ; examine meta data