2

I'm having problems generating a QQ plot for a fitted distrubution. The data is fitted by

NormalFit <- fitdistr(obs, densfun="normal") 

where obs are the observations.

I thought I can just do

qqnorm(NormalFit)

I want to do the same for

LogNormalFit <- fitdistr(obs, densfun="log-normal") 
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
plzhelplol
  • 61
  • 3

1 Answers1

1

the fit only gives you the inferred parameters, so you need to sample from that, to give you the qqplot. See below for 3 examples on how to do it.

library(MASS)
set.seed(999)
par(mfrow=c(1,3))
#simulate data
obs = rnegbin(500, mu = 5, theta = 4)
#fit data 
NormalFit <- fitdistr(obs, densfun="normal") 

#plot
qqnorm(obs,main="qqnorm")
# generate theoretical quantiles
Theo_Quantile = qnorm(ppoints(length(obs)))
qqplot(Theo_Quantile,obs,main="ppoint")
# it's also similar to if you just sample from the fitted distribution
Fitted = rnorm(length(obs),NormalFit$estimate[1],NormalFit$estimate[2])
qqplot(Fitted,obs,main="Sampled from fitted")

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72