Solved – one sample t-tests applied to each row – ‘data are essentially constant’ error

I have three replicates of an experiment which gives me ratios of the abundance of different peptides.

If I take the data for one peptide:

pep1 <- c(4.3, 5.7, 6.3) 

I can use a one-sample t-test to test the hypothesis that the ratio is different from 1:

t.test(pep1,         alternative=c("greater"),        mu=1,        paired=FALSE,        var.equal=FALSE,        conf.level=0.95) 

output:

data:  pep1 t = 7.4818, df = 2, p-value = 0.0087 alternative hypothesis: true mean is greater than 1 95 percent confidence interval:  3.703107      Inf sample estimates: mean of x   5.433333  

However if I try and apply this to the rows of a dataframe called peptides, where each row is a separate peptide, with three ratios:

t_test <- function(x) p_val =  t.test(x,                                        alternative=c("greater"),                                       mu=1,                                       paired=FALSE,                                       var.equal=FALSE,                                       conf.level=0.95)$p.value  apply(peptides, 1, t_test) 

I get the data are essentially constant error.

I don't understand! I think apply is doing what I want because if I substitute 't-test' for 'mean' then it does the correct calculations.

My aim is to get the p-values for each peptide and then adjust these for multiple comparisons.

I'm relatively new to R, and any advice would be very much appreciated!

I found the problem in my data – There's one peptide where the ratios are identical in the three replicates. Of course this then means that it's not possible to estimate confidence intervals and perform t-tests. Removing this value allows the code to run fine.

Many thanks to everyone who's had a look at the problem.

Similar Posts:

Rate this post

Leave a Comment