4

I did a distribution fit and was taking a look at the Q-Q-Plot and was wondering if there is an easy way to get the corresponding values from the graphic.

library("fitdistrplus")
data <- c(1050000, 1100000, 1230000, 1300000, 1450000, 1459785, 1654000, 1888000)
lognormalfit <- fitdist(data, "lnorm")
qqcomp(lognormalfit)

With the last line of code I receive the Q-Q-Plot without calculating the values. But I am also interested in the values. How can I obtain them?

Best regards Norbi

makeyourownmaker
  • 1,558
  • 2
  • 13
  • 33
Norbi
  • 69
  • 4
  • You can list the code in the qqcomp() function by typing qqcomp in an R session with the fitdistrplus package loaded. It should then be possible to find the code that calculates the theoretical and empirical quantiles. You could even edit the code to return the values instead of the plot. – makeyourownmaker Sep 29 '18 at 20:50

2 Answers2

0

To elaborate a little on my comment above, you can edit a function within R like this:

qqcompValues <- edit(qqcomp)

Within the editor, replace line 111 with the following:

return(data.frame(x=fittedquant, y=sdata))

Note, that the above edit assumes you are using the default plotstyle="graphics" function parameter.

You can then get QQ values like this:

qqValues <- qqcompValues(lognormalfit)
qqValues
        x       y
1 1026674 1050000
2 1158492 1100000
3 1247944 1230000
4 1327616 1300000
5 1407939 1450000
6 1497825 1459785
7 1613479 1654000
8 1820639 1888000
makeyourownmaker
  • 1,558
  • 2
  • 13
  • 33
0

qqcomp has an option to produce the plot using ggplot2: this type of plot returns an object with the data. So you can grab the plot and data with

plotData <- qqcomp(lognormalfit, plotstyle = "ggplot") 

and then you can grab the relevant data from the plot object using

plotData$data
#   values   ind   sdata
#1 1026674 lnorm 1050000
#2 1158492 lnorm 1100000
#3 1247944 lnorm 1230000
#4 1327616 lnorm 1300000
#5 1407939 lnorm 1450000
#6 1497825 lnorm 1459785
#7 1613479 lnorm 1654000
#8 1820639 lnorm 1888000
user20650
  • 24,654
  • 5
  • 56
  • 91