# qqplot of inverse Gaussian distribution in r

I wanted to draw a qqline of my data with the inverse Gaussian distribution, however, the line printed does not seem to be right, for details see the picture attached.

thanks

• Problem solved, I qqplot my data with normal inverse Gaussian instead of the wanted one, I just did not know how to declare a special inverse Gaussian distribution. Commented Jan 27, 2021 at 16:02

I'm guessing what you are trying to do... You want to assess how your data fits to a theoretical inverse Guassian distribution. For example, your data may be y:

library(statmod)
set.seed(1234)
y <- rinvgauss(100, mean= 5, dispersion= 0.1) # Obesrved data


Assuming you don't have some fixed expectation for the parameters mean and dispersion, you could estimate them from the data y by finding the paramater values that make the invgaussian PDF most likely:

fn <- function(par= c(mean, dispersion), data) {
ll <- -sum(dinvgauss(data, mean= par[1], dispersion= par[2], log= TRUE))
return(ll)
}

pp <- optim(par= c(mean= 1, dispersion= 1), fn, data= y)

m <- pp$$par['mean'] # 4.85 disp <- pp$$par['dispersion'] # 0.1


Alternatively, pick values for mean and dispersion that you think are appropriate.

Now you can compare the distribution of the data y to the theoretical invgaussian distribution with given mean and dispersion parameters:

x <- qinvgauss(seq(0, 1, length.out= length(y)), mean= m, dispersion= disp)
qqplot(x, y, xlab = "Theoretical Quantiles", ylab = "Sample Quantiles")
qqline(y, distribution= function(p) qinvgauss(p, mean= m, dispersion= disp))


• Wow, thanks so much, your code is very inspiring, you r definitely a great statistician. given my question has so many unknown factors and you still get it lol Commented Jan 27, 2021 at 15:32
• Problem solved, I'm new to R so I actually did not know how to declare "function(p) qinvgauss(p, mean= m, dispersion= disp))" in the qq plot, so I was qqplot my data with normal inverse gaussian all the time. Thank you again, could you recommend me some book or website for R? Commented Jan 27, 2021 at 15:50