Re: [R] likelihood from test result

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed, 9 Jan 2008 11:22:54 -0500

You could create an S3 generic that does it. That is not initially any less work than the if statement but if you add new distribution no existing code need be modified. Just add a new method for each distribution to be supported:

getDistr <- function(x) {

	.Class <- names(x$value$statistic)
	NextMethod("getDistr")

}

# initial list of distributions supported getDistr.t <- function(x) dt
"getDistr.X-squared" <- function(x) dchisq

# test the two distributions

example(t.test)
getDistr(.Last.value)

example(prop.test)
getDistr(.Last.value)

On Jan 9, 2008 10:46 AM, David Bickel <dbickel_at_uottawa.ca> wrote:
> Is there any automatic mechanism for extracting a likelihood or test
> statistic distribution (PDF or CDF) from an object of class "htest" or
> from another object of a general class encoding a hypothesis test
> result?
>
> I would like to have a function that takes "x", an object of class
> "htest", as its only argument and that returns the likelihood or test
> statistic distribution that was used to compute the p-value. It seems
> the only way to write such a function is to manually assign each test
> its statistic's distribution, e.g., like this:
>
> FUN <- if(names(x$statistic) == "t")
> dt
> else if(names(x$statistic) == "X-squared")
> dchisq
> # etc.
>
> Is there a general S3 or S4 class other than "htest" that would better
> accommodate such extraction of distributions or likelihoods? I would
> also appreciate any suggestions for strategies or contributed packages
> that may facilitate automation. For example, would the "distrTEst"
> package help?
>
> David
>
> ______________________________
> David R. Bickel
> Ottawa Institute of Systems Biology
> http://www.oisb.ca/members.htm
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 Jan 2008 - 16:27:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Jan 2008 - 17:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive