0
$\begingroup$

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.

someone help me please

thanks the line is not right, the dots are {data quantiles, inverse gaussian quantiles

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ Commented Jan 27, 2021 at 16:02

1 Answer 1

2
$\begingroup$

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))

enter image description here

$\endgroup$
2
  • $\begingroup$ 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 $\endgroup$ Commented Jan 27, 2021 at 15:32
  • $\begingroup$ 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? $\endgroup$ Commented Jan 27, 2021 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.