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