Reputation: 1506
I am creating a hypothesis test in R
as a htest
object. I have managed to create the object I want, with the required estimate, test statistic and p-value. My only remaining problem is that the statement I want to give for my alternative hypothesis does not conform to the textual structure used in the printing method for an htest
object. The setup for these objects seems to assume you have an alternative hypothesis that is a one-sided or two-sided test operating on an unknown parameter. It does not appear to accomodate more generate statements of alternative hypotheses, such as for goodness-of-fit tests. To be a bit more specific about my problem, here is the textual structure of the output print message for a htest
object:
alternative hypothesis: true [name(null.value)] is [less than/equal to/greater than] [null.value]
I would like a more general print output like this:
alternative hypothesis: [character string]
When you create a htest
object you can set name(null.value)
and null.value
to any character string you want, so it is possible to alter the start an end parts of the print message to anything you want. You can also set alternative
to NA
and this removes the middle part. However, the intermediate words "true" and "is" seem to be fixed. This means that you seem to be stuck with a message with the structure true [character string] is [character string]
.
My question: When creating a htest
object, is there any way to get a print message for the alternative hypothesis that is an arbitrary character string? If so, what is the simplest way to do this?
Upvotes: 0
Views: 147
Reputation: 20811
As long as you set x$null.value <- NULL
, it will print any string you construct for x$alternative
x <- t.test(1:10)
x$null.value <- NULL
x$alternative <- sprintf('%.2f on %s degrees of freedom, p %s',
x$statistic, x$parameter, format.pval(x$p.value, eps = 0.001))
x
# One Sample t-test
#
# data: 1:10
# t = 5.7446, df = 9, p-value = 0.0002782
# alternative hypothesis: 5.74 on 9 degrees of freedom, p < 0.001
# 95 percent confidence interval:
# 3.334149 7.665851
# sample estimates:
# mean of x
# 5.5
Upvotes: 1