Patterns in static

Apophenia

Functions
apop_bootstrap.c File Reference

Functions

gsl_rng * apop_rng_alloc (int seed)
 
apop_dataapop_jackknife_cov (apop_data *in, apop_model *model)
 
apop_dataapop_bootstrap_cov (apop_data *data, apop_model *model, gsl_rng *rng, int iterations, char keep_boots, char ignore_nans)
 

Detailed Description

Copyright (c) 2006–2007 by Ben Klemens. Licensed under the modified GNU GPL v2; see COPYING and COPYING2.

Function Documentation

apop_data* apop_bootstrap_cov ( apop_data data,
apop_model model,
gsl_rng *  rng,
int  iterations,
char  keep_boots,
char  ignore_nans 
)

Give me a data set and a model, and I'll give you the bootstrapped covariance matrix of the parameter estimates.

Parameters
dataThe data set. An apop_data set where each row is a single data point. (No default)
modelAn apop_model, whose estimate method will be used here. (No default)
iterationsHow many bootstrap draws should I make? (default: 1,000)
rngAn RNG that you have initialized, probably with apop_rng_alloc. (Default: an RNG from apop_rng_get_thread)
keep_bootsIf 'y', then add a page to the output apop_data set with the statistics calculated for each bootstrap iteration. They are packed via apop_data_pack, so use apop_data_unpack if needed. (Default: 'n')
1 apop_data *boot_output = apop_bootstrap_cov(your_data, your_model, .keep_boots='y');
2 apop_data *boot_stats = apop_data_get_page(boot_output, "<bootstrapped statistics>");
3 
4 Apop_matrix_row(boot_stats->matrix, 27, row_27)
5 //If the output statistic is not just a vector, you'll need to use apop_data_unpack to put
6 //it into the right shape. Let's assume for now that it's just a vector:
7 printf("The statistics calculated on the 28th iteration:\n");
8 apop_vector_print(row_27);
ignore_nansIf 'y' and any of the elements in the estimation return NaN, then I will throw out that draw and try again. If 'n', then I will write that set of statistics to the list, NaN and all. I keep count of throw-aways; if there are more than iterations elements thrown out, then I throw an error and return with estimates using data I have so far. That is, I assume that NaNs are rare edge cases; if they are as common as good data, you might want to rethink how you are using the bootstrap mechanism. (Default: 'n')
Returns
An apop_data set whose matrix element is the estimated covariance matrix of the parameters.
Exceptions
out->error=='n'NULL input data.
out->error=='N'too many Nans.
See also
apop_jackknife_cov
apop_data* apop_jackknife_cov ( apop_data in,
apop_model model 
)

Give me a data set and a model, and I'll give you the jackknifed covariance matrix of the model parameters.

The basic algorithm for the jackknife (with many details glossed over): create a sequence of data sets, each with exactly one observation removed, and then produce a new set of parameter estimates using that slightly shortened data set. Then, find the covariance matrix of the derived parameters.

Jackknife or bootstrap? As a broad rule of thumb, the jackknife works best on models that are closer to linear. The worse a linear approximation does (at the given data), the worse the jackknife approximates the variance.

Sample usage:

1 apop_data_show(apop_jackknife_cov(your_data, your_model));
Parameters
inThe data set. An apop_data set where each row is a single data point.
modelAn apop_model, that will be used internally by apop_estimate.
Exceptions
out->error=='n'NULL input data.
Returns
An apop_data set whose matrix element is the estimated covariance matrix of the parameters.
See also
apop_bootstrap_cov

Autogenerated by doxygen on Wed Oct 15 2014 (Debian 0.999b+ds3-2).