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
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. >
David Bickel 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. > >Just take the p-value itself as the test statistic and use dunif. I think doing this may also show you that you have a conceptual problem.... (What would you do with the likelihood?) -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Dear David, no, distrTEst won't help. It has a different intention. We are currently working on a new package "distrMod" (cf. https://r-forge.r-project.org/projects/distrmod/) which sometime might have such a functionality. Best, Matthias David Bickel 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. >