[R] printing all htest class members

David Winsemius dwinsemius at comcast.net
Thu Dec 15 20:04:29 CET 2011


On Dec 15, 2011, at 12:26 PM, Rui Barradas wrote:

> Hello,
>
> I've posted a question about this subject yesterday, but since there  
> was no
> R code to comment,
> no one did.
>
> I'm trying to have the print method for class 'htest' print some extra
> information common in some test, like the time series linearity  
> related
> tests. Many of them have an 'order' parameter, representing a lag or
> embedding dimension, and it would be a nice feature to pass a vector  
> of
> orders and have all corresponding tests run.
>
> It's easy to do this, but the print method doesn't print those extra  
> values.
> Here the code  goes:
>
> #Some values from the McLeod-Li test, with x <- rnorm(100)
> res <- data.frame(ord=2:4, df=ord, Q=c(0.0129, 0.049, 0.0684),
>                    p=c(0.9936, 0.9972, 0.9994))
> attach(res)
> nr <- nrow(res)
>

My problem reading this is that you are using the attach function  
which generally confuses discussions and then you are not actually  
creating any object with a class of htest. Print methods are  
dispatched by class value.

> # print.htest prints everything but 'all.orders'
> # but when it's named 'null.value' it works and it's easier to make
> # it work, all what's needed is 'null.value=res', whithout the need
> # for a second 'structure()'

You seem to be transcribing a conversation inside your head. Most of  
the four lines above has no connection to what you typed earlier.

> structure(

This does nothing. No object is created.

> 	list(statistic=c(Q=Q[1]),
> 		p.value=p[1],
> 		parameter=c(df=df[1]),
> 		alternative="It doesn't print 'all.orders' and I find 'null.value'
> misleading",
> 		method="Test the 'print.htest' method using McLeod-Li test values.",
> 		data.name=deparse(substitute(x)),
> 		all.orders=structure(
> 			list(order=ord, df=df, Q=Q, p.value=p),
> 			.Names=c("order", "df", "Q", "p.value"),
> 			row.names=c(NA,-nr),
> 			class="data.frame"
> 		)
> 	),
> 	.Names=c("statistic","p.value","parameter","alternative",
> 			"method","data.name","all.orders"),
> 	class="htest"
> )
>
> Is there a way to have 'all.orders' printed by 'print.htest' ?
> The problem is NOT the return values, at least the time wasn't wasted,
> I can use them for whatever I'll do next.
>
> If not, anyone has any suggestions?

Yes. Give the code you are actually using!

>

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list