00001 /*! \file ItemParamPriorNormal.cpp 00002 00003 \brief 00004 Class derived from ItemParamPrior representing a normal prior distribution 00005 of item parameters for use in Bayes modal estimation. 00006 00007 mParameter[0] = mean of normal distribution 00008 mParameter[1] = standard deviation of normal 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 "ItemParamPriorNormal.h" 00026 #else 00027 #include "etirm/ItemParamPriorNormal.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] ¶m Parameter vector of length 2: param[0] = Normal prior mean, 00045 param[1] = Normal prior standard deviation. 00046 00047 Note: The second element of param is the standard deviation, NOT the variance. 00048 */ 00049 ItemParamPriorNormal::ItemParamPriorNormal(RealVector ¶m) : 00050 ItemParamPrior(param) 00051 { 00052 variance = param(2) * param(2); 00053 } 00054 00055 /*! 00056 \brief 00057 Constructor taking mean and standard deviation as arguments. 00058 00059 \param[in] mean Normal prior mean. 00060 \param[in] sd Normal prior standard deviation. 00061 00062 Note: The second parameter is the standard deviation, NOT the variance. 00063 */ 00064 ItemParamPriorNormal::ItemParamPriorNormal(Real mean, Real sd) : 00065 ItemParamPrior(2) 00066 { 00067 if (sd <= 0.0) 00068 throw RuntimeError("Invalid s.d. for normal prior", 00069 "ItemParamPriorNormal::ItemParamPriorNormal"); 00070 00071 mParameters[0] = mean; 00072 mParameters[1] = sd; 00073 00074 variance = sd * sd; 00075 } 00076 00077 /*! 00078 \brief 00079 Default constructor - assigns uniform distribution */ 00080 ItemParamPriorNormal::ItemParamPriorNormal() : 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 ItemParamPriorNormal::LogDensity(Real p) 00098 { 00099 Real value = p - mParameters[0]; 00100 value *= value; 00101 value /= -2.0 * variance; 00102 00103 return value; 00104 } 00105 00106 /*! 00107 \brief 00108 Returns first derivative of log density. 00109 00110 \param[in] p Argument of log density function (an item parameter value). 00111 00112 Note: Returns only the part of the log of the density that depends on the parameter. 00113 */ 00114 Real ItemParamPriorNormal::DerivLogDensity1(Real p) 00115 { 00116 return -(p - mParameters[0])/variance; 00117 } 00118 00119 /*! 00120 \brief 00121 Returns second derivative of log density. 00122 00123 \param[in] p Argument of log density function (an item parameter value). 00124 00125 Note: Returns 0nly the part of the log of the density that depends on the parameter. 00126 */ 00127 Real ItemParamPriorNormal::DerivLogDensity2(Real /* p*/) 00128 { 00129 return -1.0/variance; 00130 } 00131 00132 } // namespace etirm