Error In T.test.default Data Are Essentially Constant
Contents |
Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings r catch error and policies of this site About Us Learn more about Stack Overflow
R Try Catch
the company Business Learn more about hiring developers or posting ads with us Cross Validated Questions Tags Users Badges Unanswered Ask Question _ Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top t.test returns an error “data are essentially constant” up vote 6 down vote favorite 1 R version 3.1.1 (2014-07-10) -- "Sock it to Me" > bl <- c(140, 138, 150, 148, 135) > fu <- c(138, 136, 148, 146, 133) > t.test(fu, bl, alternative = "two.sided", paired = TRUE) Error in t.test.default(fu, bl, alternative = "two.sided", paired = TRUE) : data are essentially constant Then I change just a single character in my fu dataset: > fu <- c(138, 136, 148, 146, 132) and it runs... > t.test(fu, bl, alternative = "two.sided", paired = TRUE) Paired t-test What am I missing here? r t-test share|improve this question asked Aug 23 '14 at 5:33 ihadanny 310211 3 Type bl-fu. Now sd(bl-fu). If it's not obvious, yet, do these: dif=bl-fu then n=length(dif) then mean(dif)/(sd(dif)/sqrt(n))... do you see now? –Glen_b♦ Aug 23 '14 at 5:35 whoops, thanks :) agree with me that the error message could have been more newbie-friendly. So this means that as far as statistics go, there's no need for fancy t.test and its a certainty that for each subject there would be a -2 reduction in the fu compared to the bl? –ihadanny Aug 23 '14 at 5:46 add a comment| 1 Answer 1 active oldest votes up vote 5 down vote
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. http://stats.stackexchange.com/questions/112972/t-test-returns-an-error-data-are-essentially-constant Join them; it only takes a minute: Sign up paired t-test crashes apply-loop (edited) up vote 1 down vote favorite 3 In response to the helpful comments, I have edited the original question (where I had assumed that a for-loop and an apply-loop give different results). I am using R to run a large number of 2-group t-tests, http://stackoverflow.com/questions/9480855/paired-t-test-crashes-apply-loop-edited using input from a delimited table. Following recommendations from here and elsewhere, I tried either 'for-loops' and 'apply' to accomplish that. For 'normal' t.test, both work nicely and give the same results. However, for a paired t-test, the for-look appears to works while the apply-loop does not. Later, i found out that both loops suffer from the same problem (see below) but the for-loops deals more gracefully with the situation (only one cycle of the loop returns an invalid result) while the apply-loop fails altogether. My input file looks like this: (the first line is a header line, the data lines have a name, 4 datapoints for group 1 and 4 datapoints for group 2): header g1.1 g1.2 g1.3 g1.4 g2.1 g2.2 g2.3 g2.4 name1 0 0.5 -0.2 -0.2 -0.1 0.4 -0.3 -0.3 name2 23.2 24.4 24.5 27.2 15.5 16.5 17.7 20.0 name3 ..... and so on (overall ~50000 lines). The first data line (starting with name19 turned out to be the culprit. This is the for-loop version that works better (failes on t
was scrubbed...Name: not availableUrl: https://stat.ethz.ch/pipermail/r-help/attachments/20080212/d6620f42/attachment.pl reply Tweet Search Discussions Search http://grokbase.com/t/r/r-help/082cgh273a/r-how-to-make-t-test-handle-na-and-essentially-constant-values All Groups r-help 8 responses Oldest Nested Petr PIKAL Hi http://www.talkstats.com/showthread.php/50664-Problem-with-t-test-(unequal-sample-sizes) r-help-bounces at r-project.org napsal dne 12.02.2008 09:09:23: 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 error in silly things as try to compute t.test when data have zero variantion or number of observations is 1. Regards Petr Petr PIKAL at Feb 12, 2008 at 8:42 am ⇧ Hir-help-bounces at 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 error in t.test.default t.test.default(x) : data are essentially constantmake your data not constantSecond 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' observationsincrease number of observationsHow to make t-test ignores this errors ?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 makingsilly things as try to compute t.test when data have zero variantion ornumber of observations is 1.RegardsPetr[[alternative HTML version deleted]]______________________________________________R-help at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guidehttp://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. reply | permalink Ng Stanley An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20080212/c5bcfe17/attachment.pl Ng Stanley at Feb 12, 2008 at 10:56 am ⇧ An embedded and charset-unspecified text was scrubbed...Name: not availableUrl: https://stat.ethz.ch/pipermail/r-help/attachments/20080212/c5bcfe17/attachment.pl reply | permalink ONKELINX, Thierry Have a loo
t-test (unequal sample sizes) Tweet Welcome to Talk Stats! Join the discussion today by registering your FREE account. Membership benefits: • Get your questions answered by community gurus and expert researchers. • Exchange your learning and research experience among peers and get advice and insight. Join Today! + Reply to Thread Results 1 to 3 of 3 Thread: Problem with t-test (unequal sample sizes) Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 10-27-201303:05 PM #1 tamtam View Profile View Forum Posts Give Away Points Posts 2 Thanks 0 Thanked 0 Times in 0 Posts Problem with t-test (unequal sample sizes) Hello I am trying to run a t-test on a data set with unequal sample sizes. According to this tutorial here http://personality-project.org/r/basics.t.html, it should work without problems. However, I get the following error message: "Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentially constant") : missing value where TRUE/FALSE needed In addition: Warning message: In mean.default(y) : argument is not numeric or logical: returning NA" The second option (data strung out) does not work either, R just doesn't finish the calculations. My script so far: library(psych) setwd() #path getwd() df4 = read.csv("unequalT_Test.csv") #read csv table df4 #show table with(df4, t.test(Placebo,Drug,equal.var=TRUE) ) Any idea how to solve this problem? Is there something wrong with my script? Help would be much appreciated! Regards Reply With Quote 10-27-201303:35 PM #2 Dason View Profile View Forum Posts Visit Homepage Beep Awards: Location Ames, IA Posts 12,589 Thanks 297 Thanked 2,542 Times in 2,168 Posts Re: Problem with t-test (unequal sample sizes) Seems like it's an issue with your data. The error message makes it sound like the data in each group is essentially constant. Is that the case? I don't have emotions and sometimes that makes me very sad. Reply With Quote 10-27-201304:39 PM #3 tamtam View Profile View Forum Posts Posts 2 Thanks 0 Thanked 0 Times in 0 Posts Re: Problem with t-test (unequal sample sizes) So far, I used the data ftom the tutorial, saved as a .csv file. Placebo Drug 24 24 25 29 27 26 26 23 26 25 22 28 21 27 22 24 23