[R] likelihood from test result

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jan 9 17:22:54 CET 2008


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




More information about the R-help mailing list