%INVGAMMAPARMS—Compute parameters for inverse gamma

Use this forum to post complete RATS "procedures". Please be sure to include instructions on using the procedure and detailed references where applicable.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

%INVGAMMAPARMS—Compute parameters for inverse gamma

Unread post by TomDoan »

This function returns a 2-vector (shape and scale in that order) with the two parameters for an inverse Gamma distribution which has a requested mean and standard deviation. The inverse gamma is commonly used as the prior for a model parameter which has support on the positive reals (such as a variance).
invgammaparms.src
Function file
(1.05 KiB) Downloaded 1100 times
Because it's a function (not a procedure), you need to do a SOURCE instruction on the file before you can use it in a RATS program.

target VECTOR=%InvGammaParms(mean,sd)

If the s.d. is %NA (infinite), it returns a shape parameter of 2, which is the largest value for which the variance is undefined.

Example
source invgammaparms.src (needs to be done once)
compute igparms=%invgammaparms(2.0,1.0)
set test 1 1000 = igparms(2)/%rangamma(igparms(1))
set logg 1 1000 = -2.0*log(test)+$
%loggammadensity(1.0/test,igparms(1),1.0/igparms(2))

will create a series named TEST with inverse gammas with (population) mean 2 and standard deviation 1 and the log density (in LOGG) at each drawn value.
Post Reply