From: Tony Plate <tplate_at_acm.org>

Date: Tue, 12 Feb 2008 14:59:37 -0700

*>
*

> make your data not constant

*>
*

*>
*

> increase number of observations

*>
*

*>
*

*>
*

> Well, the procedure is complaining that you do not give it correct data.

*> You shall be gratefull for a great software which prevent you from making
*

*> silly things as try to compute t.test when data have zero variantion or
*

*> number of observations is 1.
*

> my.t.test.p.value(numeric(0))

[1] NA

[1] NA

> my.t.test.p.value(c(1,1,1))

[1] NA

>

> http://www.R-project.org/posting-guide.html

*>
*

> ______________________________________________

*> 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 Tue 12 Feb 2008 - 22:38:40 GMT

Date: Tue, 12 Feb 2008 14:59:37 -0700

Petr PIKAL wrote:

*> Hi
**>
*

> r-help-bounces@r-project.org napsal dne 12.02.2008 09:09:23:

*>
*

>> Hi, >> >> First problem: >>> test <- matrix(c(1,1,2,1), 2,2) >>> apply(test, 1, function(x) { t.test(x) $p.value }) >> Error in t.test.default(x) : data are essentially constant

> make your data not constant

>> Second problem: >>> test <- matrix(c(1,0,NA,1), 2,2) >>> apply(test, 1, function(x) { t.test(x) $p.value }) >> Error in t.test.default(x) : not enough 'x' observations

> increase number of observations

>> How to make t-test ignores this errors ?

> Well, the procedure is complaining that you do not give it correct data.

It's nice that the software recognizes situations in which a sensible answer can't be computed. At that point, there are two possible actions: (1) stop with an informative error, and (2) silently return NA. Option (1) is wonderful for interactive use, but option (2) is easier to handle in programs where one is making many calls to the function as part of some automated procedure (e.g., as part of a bootstrap procedure).

> my.t.test.p.value <- function(...) {

+ obj<-try(t.test(...), silent=TRUE) + if (is(obj, "try-error")) return(NA) else return(obj$p.value) + }

> my.t.test.p.value(numeric(0))

[1] NA

> my.t.test.p.value(1:10) [1] 0.000278196 > my.t.test.p.value(1)

[1] NA

> my.t.test.p.value(c(1,1,1))

[1] NA

> my.t.test.p.value(c(1,2,NA)) [1] 0.2048328 > my.t.test.p.value(c(1,2)) [1] 0.2048328

>

hope this helps,

Tony Plate

*>
**> Regards
**> Petr
**>
*

>> [[alternative HTML version deleted]] >> >> ______________________________________________ >> 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 Tue 12 Feb 2008 - 22:38:40 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 Tue 12 Feb 2008 - 23:30:13 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.
*