C:/programs/etirm/src/ItemParamPriorLogNormal.cpp

Go to the documentation of this file.
00001 /*! \file ItemParamPriorLogNormal.cpp
00002  
00003   \brief
00004   Class derived from ItemParamPrior representing a lognormal prior distribution
00005   of item parameters for use in Bayes modal estimation.
00006  
00007   mParameter[0] = mean parameter of lognormal distribution
00008   mParameter[1] = standard deviation parameter of lognormal distribution.
00009   
00010   Note the second parameter is the standard deviation, NOT the variance.
00011 
00012   Estimation Toolkit for Item Response Models (ETIRM)
00013   http://www.smallwaters.com/software/cpp/etirm.html
00014 
00015   Author(s): 
00016   Werner Wothke, maintenance (http://www.smallwaters.com)
00017   Brad Hanson (http://www.b-a-h.com/)
00018   See the file LICENSE for information on usage and redistribution.
00019 
00020   Copyright (C) 2008, Werner Wothke
00021   Copyright (c) 2000-2001, Bradley A. Hanson
00022  */
00023 
00024 #ifdef ETIRM_NO_DIR_PREFIX
00025 #include "ItemParamPriorLogNormal.h"
00026 #else
00027 #include "etirm/ItemParamPriorLogNormal.h"
00028 #endif
00029 
00030 #include <cmath> // for log
00031 // for compilers which do not put C library functions in std namespace
00032 #ifdef BOOST_NO_STDC_NAMESPACE
00033 namespace std
00034 { using ::log;}
00035 #endif
00036 
00037 namespace etirm
00038 {
00039 
00040   /*!
00041     \brief
00042     Constructor taking vector of parameters.
00043     
00044     \param[in] &param Parameter vector describing log-Normal prior: param[0] - prior mean, param[1] - prior standard deviation. 
00045 
00046     Note: The second element of param is the standard deviation, NOT the variance.
00047    */
00048   ItemParamPriorLogNormal::ItemParamPriorLogNormal(RealVector &param) :
00049     ItemParamPrior(param)
00050   {
00051     variance = param(2) * param(2);
00052   }
00053 
00054   /*!
00055     \brief
00056     Constructor taking prior mean and standard deviation as arguments.
00057     
00058     \param[in] mean Prior mean
00059     \param[in] sd Prior standard deviation
00060     
00061     Note: The second parameter is the standard deviation, NOT the variance.
00062    */ 
00063   ItemParamPriorLogNormal::ItemParamPriorLogNormal(Real mean, Real sd) :
00064     ItemParamPrior(2)
00065   {
00066     if (sd <= 0.0)
00067       throw RuntimeError("Invalid s.d. for lognormal prior",
00068           "ItemParamPriorLogNormal::ItemParamPriorLogNormal");
00069 
00070     mParameters[0] = mean;
00071     mParameters[1] = sd;
00072 
00073     variance = sd * sd;
00074   }
00075 
00076   /*!
00077     \brief
00078     Default constructor - assigns uniform distribution.
00079    */
00080   ItemParamPriorLogNormal::ItemParamPriorLogNormal() :
00081     ItemParamPrior(2)
00082   {
00083     mParameters[0] = 0.0;
00084     mParameters[1] = 1.0;
00085 
00086     variance = 1.0;
00087   }
00088 
00089   /*!
00090     \brief
00091     Returns log-density of p.
00092     
00093     \param[in] p  Argument of log density function (an item parameter value).
00094     
00095     Note: Returns only the part of the log of the density that depends on the parameter.
00096    */
00097   Real ItemParamPriorLogNormal::LogDensity(Real p)
00098   {
00099     /* Check for value outside limits of distribution */
00100     if (ItemParamPriorLogNormal::ZeroDensity(p))
00101     {
00102       return std::log(0.0);
00103     }
00104 
00105     Real value = std::log(p) - mParameters[0];
00106     value *= value;
00107     value /= -2.0 * variance;
00108     value -= std::log(p);
00109 
00110     return value;
00111   }
00112 
00113   /*!
00114     \brief
00115     Returns first derivative of log density.
00116 
00117     \param[in] p  Argument of log density function (an item parameter value).
00118   
00119     Note: Returns only the part of the log of the density that depends on the parameter.
00120    */
00121   Real ItemParamPriorLogNormal::DerivLogDensity1(Real p)
00122   {
00123     /* Outside limits of distribution density does not change,
00124      so derivative is zero */
00125     if (ItemParamPriorLogNormal::ZeroDensity(p))
00126       return 0.0;
00127 
00128     Real value = std::log(p) - mParameters[0] + variance;
00129     value /= variance * p;
00130 
00131     return -value;
00132   }
00133 
00134   /*!
00135     \brief
00136     Returns second derivative of log density.
00137 
00138     \param[in] p  Argument of log density function (an item parameter value).
00139 
00140     Note: Returns 0nly the part of the log of the density that depends on the parameter.
00141    */
00142   Real ItemParamPriorLogNormal::DerivLogDensity2(Real p)
00143   {
00144     /* Outside limits of distribution density does not change,
00145      so derivative is zero */
00146     if (ItemParamPriorLogNormal::ZeroDensity(p))
00147       return 0.0;
00148 
00149     Real value = std::log(p) - mParameters[0] + variance - 1.0;
00150     value /= p * p * variance;
00151 
00152     return value;
00153   }
00154 
00155 } // namespace etirm

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