Skip to content

Goodness fit test HELP!

3 messages · Amit Kabiri, Martin Maechler, Charles Annis, P.E.

#
If I have a Uniform distribution to check, How can I use visual fits? Can I
also use in some way the qqnorm?

Thanks 


-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Elizabeth Lawson
Sent: Friday, November 18, 2005 8:06 PM
To: David Zhao
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Goodness fit test HELP!

What about trying a qqplot to see how the distribution fits...
   
  For the normal distribution thta is very stright forward, use qqnorm.
   
  To test gamma distribtution (or any other) do some thing like this 
   
  n<-length(data)
  for(i in 1:n){
  prob<-(i-1/3)/(n1/3)
  }
 
quantiles<-qgamma(prob,shape=mean(data)/var(data),scale=var(data)/mean(data)
}
   
  qqplot(data,quantiles)
   
  If the distribution is a good for, you should a stright line, like wiht a
qqnorm plot!
   
  Good luck!!
   
  Elizbaeth Lawson
David Zhao <wzhao6898 at gmail.com> wrote:
Hi there,

I'm a newbie, plesae bear with me.
I have a dataset with about 10000 ~ 30000 data points. Would like fit to
both Gamma and Normal distribution to see which one fits better. How do I do
this in R? Or I could do a normality test of the data, if it's normal, I
then will do a normal fit, otherwise, a gamma fit. But again, I don't know
how to do this either.
Please help!

David


______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
  


		
---------------------------------


______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
#
Amit> If I have a Uniform distribution to check, How can I
    Amit> use visual fits? Can I also use in some way the
    Amit> qqnorm?

yes, in *some* way:

U <- runif(100)

plot(sort(U))                                     # is already sufficient visually

plot(ppoints(U), sort(U)) ; abline(1,1, lty = 3)  # is a bit nicer

    Amit> Thanks


    Amit> -----Original Message----- From:
    Amit> r-help-bounces at stat.math.ethz.ch
    Amit> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
    Amit> Elizabeth Lawson Sent: Friday, November 18, 2005 8:06
    Amit> PM To: David Zhao Cc: r-help at stat.math.ethz.ch
    Amit> Subject: Re: [R] Goodness fit test HELP!

    Amit> What about trying a qqplot to see how the distribution
    Amit> fits...
   
    Amit>   For the normal distribution thta is very stright
    Amit> forward, use qqnorm.
   
    Amit>   To test gamma distribtution (or any other) do some
    Amit> thing like this
   
    Amit>   n<-length(data) for(i in 1:n){ prob<-(i-1/3)/(n1/3)
    Amit> }
 
    Amit> quantiles<-qgamma(prob,shape=mean(data)/var(data),scale=var(data)/mean(data)
    Amit> }
   
    Amit>   qqplot(data,quantiles)
   
    Amit>   If the distribution is a good for, you should a
    Amit> stright line, like wiht a qqnorm plot!
   
    Amit>   Good luck!!
   
    Amit>   Elizbaeth Lawson

    Amit> David Zhao <wzhao6898 at gmail.com> wrote: Hi there,

    Amit> I'm a newbie, plesae bear with me.  I have a dataset
    Amit> with about 10000 ~ 30000 data points. Would like fit
    Amit> to both Gamma and Normal distribution to see which one
    Amit> fits better. How do I do this in R? Or I could do a
    Amit> normality test of the data, if it's normal, I then
    Amit> will do a normal fit, otherwise, a gamma fit. But
    Amit> again, I don't know how to do this either.  Please
    Amit> help!

    Amit> David

    Amit> [[alternative HTML version deleted]]

    Amit> ______________________________________________
    Amit> R-help at stat.math.ethz.ch mailing list
    Amit> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
    Amit> read the posting guide!
    Amit> http://www.R-project.org/posting-guide.html
  


		
    Amit> ---------------------------------

    Amit> 	[[alternative HTML version deleted]]

    Amit> ______________________________________________
    Amit> R-help at stat.math.ethz.ch mailing list
    Amit> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
    Amit> read the posting guide!
    Amit> http://www.R-project.org/posting-guide.html

    Amit> ______________________________________________
    Amit> R-help at stat.math.ethz.ch mailing list
    Amit> https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
    Amit> read the posting guide!
    Amit> http://www.R-project.org/posting-guide.html
#
The nice thing about the uniform density is that it's easy to know what the
expected pdf(pmf) should look like, namely each observation should have
probability 1/n.  That means you can use "qqplot."  See ?qqplot


Here's an example, using "my.data."

my.data <- runif(100)
n.points <- length(my.data)
expected.cdf <- ((1:n.points)-0.5)/(n.points)
qqplot(my.data, expected.cdf, las=1)
# Use the "interocular trauma test" for goodness-of-fit:
my.lm <- lm(expected.cdf ~ sort(my.data))
abline(coef=coef(my.lm), lty=2)





Charles Annis, P.E.

Charles.Annis at StatisticalEngineering.com
phone: 561-352-9699
eFax:  614-455-3265
http://www.StatisticalEngineering.com
 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Amit Kabiri
Sent: Saturday, December 03, 2005 11:43 AM
To: 'Elizabeth Lawson'; 'David Zhao'
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Goodness fit test HELP!

If I have a Uniform distribution to check, How can I use visual fits? Can I
also use in some way the qqnorm?

Thanks 


-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Elizabeth Lawson
Sent: Friday, November 18, 2005 8:06 PM
To: David Zhao
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Goodness fit test HELP!

What about trying a qqplot to see how the distribution fits...
   
  For the normal distribution thta is very stright forward, use qqnorm.
   
  To test gamma distribtution (or any other) do some thing like this 
   
  n<-length(data)
  for(i in 1:n){
  prob<-(i-1/3)/(n1/3)
  }
 
quantiles<-qgamma(prob,shape=mean(data)/var(data),scale=var(data)/mean(data)
}
   
  qqplot(data,quantiles)
   
  If the distribution is a good for, you should a stright line, like wiht a
qqnorm plot!
   
  Good luck!!
   
  Elizbaeth Lawson
David Zhao <wzhao6898 at gmail.com> wrote:
Hi there,

I'm a newbie, plesae bear with me.
I have a dataset with about 10000 ~ 30000 data points. Would like fit to
both Gamma and Normal distribution to see which one fits better. How do I do
this in R? Or I could do a normality test of the data, if it's normal, I
then will do a normal fit, otherwise, a gamma fit. But again, I don't know
how to do this either.
Please help!

David


______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
  


		
---------------------------------


______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html