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

Go to the documentation of this file.
00001 /*! \file Examinee.h
00002  
00003   \brief 
00004   Class to store an item response pattern, the posterior LV distribution, 
00005   and the marginal likelihood of the pattern.  
00006  
00007   The Examinee class stores item responses for an examinee and a
00008   count to weight the examinee in the case an Examinee object represents
00009   multiple examinees with the same response pattern.
00010   Optionally, a posterior discrete latent variable distribution can
00011   be stored, and the marginal likelihood of the response pattern for the
00012   examinee.
00013  
00014   Estimation Toolkit for Item Response Models (ETIRM)
00015   http://www.smallwaters.com/software/cpp/etirm.html
00016 
00017   Author(s): 
00018   Werner Wothke, maintenance (http://www.smallwaters.com)
00019   Brad Hanson (http://www.b-a-h.com/)
00020   See the file LICENSE for information on usage and redistribution.
00021 
00022   Copyright (C) 2008, Werner Wothke
00023   Copyright (c) 2000-2001, Bradley A. Hanson
00024  */
00025 
00026 #ifndef ETIRM_EXAMINEE_H_
00027 #define ETIRM_EXAMINEE_H_
00028 
00029 #ifdef ETIRM_NO_DIR_PREFIX
00030 #include "etirmtypes.h"
00031 #else
00032 #include "etirm/etirmtypes.h"
00033 #endif
00034 
00035 namespace etirm
00036 {
00037 
00038   /*!
00039     \brief
00040     Class to store a response pattern, its frequency, 
00041     the posterior distribution of the ability parameter and the 
00042     marginal likelihood of the pattern.
00043    
00044     \section template_args Template Parameters
00045    
00046     \param P  Type for storing vector of posterior probabilities.
00047     \param R  Type for storing vector of item responses.
00048    */
00049   template <class R, class P> class Examinee
00050   {
00051 
00052 public:
00053 
00054     typedef R response_vector; //!< Response vector type.
00055     
00056     typedef P posterior_vector; //!< Type for vector of posterior probabilities. 
00057     
00058     typedef typename R::value_type response_type; //!< Response type.
00059     
00060     typedef typename R::iterator response_iterator; //!< Iterator over item responses.
00061 
00062     //! Constructor
00063     Examinee(int nitems = 0) :
00064       mCount(1.0), mResponses(nitems), mPosterior(0), mMarginalResponseLikelihood(0.0)
00065     {
00066     }
00067 
00068     //! Destructor.
00069     virtual ~Examinee();
00070 
00071     /*! 
00072       \brief
00073       Assigns the examinee's item responses (copies response vector).
00074       
00075       \section function_args Function Parameters
00076    
00077       \param[in]  &responses  Address of examinee's response vector.
00078      */
00079     void SetResponses(response_vector &responses)
00080     {
00081       mResponses = responses;
00082     }
00083 
00084     //! Iterator to first response.
00085     response_iterator responses_begin()
00086     {
00087       return mResponses.begin();
00088     }
00089 
00090     //! Iterator to one past last response
00091     response_iterator responses_end()
00092     {
00093       return mResponses.end();
00094     }
00095 
00096     //! Returns the number of times to count the pattern of item responses for this examinee.
00097     Real Count()
00098     {
00099       return mCount;
00100     }
00101 
00102     /*!
00103       \brief
00104       Assigns the number of times to count the pattern of item responses for this examinee.
00105       
00106       \section function_args Function Parameters
00107    
00108       \param[in]  count Weight for counting the examinee's item response vector.
00109      */
00110     void SetCount(Real count)
00111     {
00112       mCount = count;
00113     }
00114 
00115     //! Number of items in examinee response vector
00116     int NumItems()
00117     {
00118       return mResponses.size();
00119     }
00120 
00121     /*!
00122       \brief
00123       Assigns posterior latent variable probabilities for examinee.
00124       
00125       \section function_args Function Parameters
00126    
00127       \param[in]  &posterior Address of posterior probability vector for examinee.
00128      */
00129     void SetPosterior(posterior_vector &posterior);
00130 
00131     /*!
00132       \brief
00133       Assigns iterator to first element of the examinee's posterior probability vector.
00134       
00135       Note: This function is defined within the class definition so that
00136       it compiles with Microsoft Visual C++ 6.
00137      */
00138     typename P::iterator posterior_begin()
00139     {
00140       if (!mPosterior)
00141         throw RuntimeError("No posterior distribution for examinee", "Examinee::posterior_begin");
00142       return mPosterior->begin();
00143     }
00144 
00145     //! Number of categories in discrete latent variable distribution.
00146     int NumLatentVarCat()
00147     {
00148       return (mPosterior ? mPosterior->size() : 0);
00149     }
00150 
00151     /*! 
00152       \brief
00153       Assigns marginal likelihood of examinee's response pattern.
00154       
00155       \section function_args Function Parameters
00156    
00157       \param[in]  likelihood Value of marginal likelihood of examinee's response pattern.
00158      */ 
00159     void SetMarginalRespLikelihood(Real likelihood)
00160     {
00161       mMarginalResponseLikelihood = likelihood;
00162     }
00163     
00164     /*!
00165       \brief
00166       Returns marginal likelihood of examinee's response pattern.
00167      */
00168     Real GetMarginalRespLikelihood()
00169     {
00170       return mMarginalResponseLikelihood;
00171     }
00172 
00173 protected:
00174 
00175     Real mCount;
00176     //!< Number of examinees with the pattern of item responses in mResponses.
00177 
00178     response_vector mResponses;
00179     //!< Responses to items. Includes responses to items not presented to the examinee.
00180 
00181     posterior_vector *mPosterior;
00182     //!< Posterior latent variable probabilities for examinee.
00183 
00184     Real mMarginalResponseLikelihood;
00185     //!< Marginal likelihood of examinee's response pattern.
00186   };
00187 
00188   /*! Destructor */
00189   template <class R, class P> Examinee<R, P>::~Examinee()
00190   {
00191     if (mPosterior)
00192       delete mPosterior;
00193   }
00194 
00195   /* Set posterior latent variable probabilities for examinee */
00196   template <class R, class P> void Examinee<R, P>::SetPosterior(posterior_vector &posterior)
00197   {
00198     if (mPosterior)
00199     {
00200       *mPosterior = posterior;
00201     }
00202     else
00203     {
00204       mPosterior = new posterior_vector(posterior);
00205     }
00206   }
00207 
00208 } // namespace etirm
00209 
00210 #endif // ETIRM_EXAMINEE_H_

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