C:/programs/etirm/src/BootstrapSample.h

Go to the documentation of this file.
00001 /*! \file BootstrapSample.h
00002 
00003   \brief Defines function for creating a bootstrap sample.
00004  
00005   Estimation Toolkit for Item Response Models (ETIRM)
00006   http://www.smallwaters.com/software/cpp/etirm.html
00007 
00008   Author(s): 
00009   Werner Wothke, maintenance (http://www.smallwaters.com)
00010   Brad Hanson (http://www.b-a-h.com/)
00011   See the file LICENSE for information on usage and redistribution.
00012 
00013   Copyright (C) 2008, Werner Wothke
00014   Copyright (c) 2001, Bradley A. Hanson
00015  */
00016 
00017 #ifndef ETIRM_BOOTSTRAPSAMPLE_H_
00018 #define ETIRM_BOOTSTRAPSAMPLE_H_
00019 
00020 #ifdef ETIRM_NO_DIR_PREFIX
00021 #include "etirmtypes.h"
00022 #else
00023 #include "etirm/etirmtypes.h"
00024 #endif
00025 
00026 #include <iterator>
00027 
00028 namespace etirm
00029 {
00030 
00031   /*!
00032 
00033    \brief Generate a bootstrap sample for a group of examinees.
00034    
00035    Template parameters
00036    
00037    \param URNG  Type of function object returning uniform random numbers over the integers 1 to 
00038    the number of examines. An example of a type that meets the requirements for this function
00039    is the uniform_int class from the boost library (http://www.boost.org).
00040    
00041    \param EI  Type of iterator over pointers to examinee objects.
00042 
00043    Arguments
00044    
00045    \param  examinees_begin Iterator to pointer to first examinee.
00046    \param examinees_end - Iterator to one past pointer to last examinee.
00047    */
00048   template <class URNG, class EI> void BootstrapSample(EI examinees_begin, EI examinees_end,
00049       URNG &rand)
00050   {
00051     // Number of examinees
00052     std::iterator_traits<EI>::difference_type n = std::distance(examinees_begin, examinees_end);
00053 
00054     if (rand.min() != 1 || rand.max() != n)
00055     {
00056       throw InvalidArgument("Invalid range for random number generator",
00057           "SCPPNT::BootstrapSample");
00058     }
00059 
00060     // Create vector to hold counts for each examinee from bootstrap sample - initially zero
00061     std::vector<int> counts(n, 0);
00062 
00063     // generate bootstrap counts
00064     for (int i=0; i<n; ++i)
00065     {
00066       ++counts[rand()-1];
00067     }
00068 
00069     // Assign counts to examinees
00070     for (std::vector<int>::iterator ic = counts.begin(); examinees_begin != examinees_end; ++ic,
00071         ++examinees_begin)
00072     {
00073       (*examinees_begin)->SetCount(*ic);
00074     }
00075   }
00076 
00077 } // namespace etirm
00078 
00079 #endif // ETIRM_BOOTSTRAPSAMPLE_H_

Generated on Sat Mar 1 21:40:15 2008 for ETIRM by  doxygen 1.5.4