# 'Fixing' PearsonFitML to fit to a Pearson V distribution

I am using the pearsonFitML function in the PearsonDS package to do maximum likelihood estimation of parameters in R.

I am particularly interested in fitting Pearson Type 5 distributions to my data. Does anyone know how I can 'fix' this function so it only tries fitting a type 5 distribution? This may just be a straightforward issue of syntax but I've been playing round for a while and haven't got this sorted yet!

Many thanks,

Faith

-
Pearson Type V distribution is an inverse-gamma distribution therefore it is not difficult to code it in R without using this package. You can find the code in this question: Maximum Likelihood Estimation of Inverse Gamma Distribution in R or RPy (which happens to be yours!!!). –  user10525 Aug 3 '12 at 15:18
Hi Procrastinator! Thanks for your response - I have used this other method (from my previous question) but the results of the parameter estimation are poor. When the pearsonFitML fits as a type V, it works really well. –  Faith Aug 3 '12 at 15:31
Could you please clarify in what sense the parameter estimation is poor? Are you aware of the command optim? –  user10525 Aug 3 '12 at 15:32
Apologies, I'm getting mixed up (tried quite a few methods recently!). It actually doesn't seem to work with the data I use and throws out the error "Error in optim...non-finite finite-difference value [3]". I've tried varying the starting parameters and limiting the lower and upper values. Hence moving over to the pearsonFitML method. I am aware of the command optim and have played around a little with the options for this (although perhaps not in the most scientifically objective way!). Thanks again for your speedy response! –  Faith Aug 3 '12 at 15:45

Pearson Type V distribution is the inverse-gamma distribution. This question was previously answered in your question Maximum Likelihood Estimation of Inverse Gamma Distribution in R or RPy using the command fitdistr. If you do not trust this estimation, you can try direct optimisation of the likelihood function using the command optim.

The folowing code shows how to do this using simulated data. If you post your sample, I can adjust the code and perhaps we can see what is causing trouble in the optimisation step.

rm(list=ls())
# Required packages
library(MCMCpack)

# Simulated data
set.seed(1)
data = rinvgamma(n=250, shape = 5, scale = 2) + 2

hist(data)

# log-likelihood
ll = function(par){
if(par[1]>0 & par[2]>0 & par[3]<min(data)) return( -sum(log(dinvgamma(data-    par[3],par[1],par[2]))) )
else return(Inf)
}

# MLE
mle = optim(c(5,2,2),ll)
params = mle\$par

# Fit
hist(data,probability=T,ylim=c(0,2.5))
points(seq(2,4.5,0.001),dinvgamma(seq(2,4.5,0.001)-params[3],params[1],params[2]),type="l",col="red")


I hope this helps.

-
Wow thanks Procrastinator- you're fast!The only problem is that I'm using three parameters (shape = 1.4, scale = 0.00128 and location = -0.000132). You can simulate this data in R by generating from a two parameter inverse gamma and adding the location to each value. Is there a way of adjusting your code to take this into account. Thanks again! –  Faith Aug 3 '12 at 15:50
@Faith I have modified the code to include a location parameter. Please, have a look. –  user10525 Aug 3 '12 at 16:01
Thanks, will be away from my computer for the next hour or so but will check it upon return. Thanks again! :) –  Faith Aug 3 '12 at 16:13
+1 for Procrastinator's. Whenever i see a question with a fixed methodology in mnd without any discussion of the data I am curious as to why the restriction to a Pearson V distribution makes sense. I did a simulation study where I used only Pearson VII multivariate distributions. My justification was that they have elliptic shaped contours of constant probability (like the multivariate Gaussian) and have a single parameter that controls tail behavior. This makes it easy to modify the tail shape in the simulations to compare (in my case) classification error rate estimators. –  Michael Chernick Aug 3 '12 at 17:40
Huge thanks Procrastinator, code works like a charm! I want to fit a Pearson V as I'm looking at landslide areas which are thought to follow and inverse gamma pdf. I'm now investigating whether other features of landslides do the same. So, although other distributions may be appropriate, it's good to start out comparing like for like . I didn't immediately share my data as this is unpublished work and I couldn't even do a fit to synthetic data. Also, I was originally just looking for a solution to fixing pearsonFitML (which is probably a simple syntax thing!) although I got a better answer!:) –  Faith Aug 6 '12 at 9:33