-1

In my dataset I have 14 columnes and originally 48 rows. I reduced row size to 2, because working on problems on R is much easier for me, like this. The first column consists of a participants number, the 14th column is an already aggregated mean of each participant called "dprime_mean".

names(signal_table)
 [1] "vpn"         "t_hit"       "t_miss"      "t_correj"    "t_false"    
 [6] "at_hit"      "at_miss"     "at_correj"   "at_false"    "t_dprime"   
[11] "t_crit"      "at_dprime"   "at_crit"     "dprime_mean" 

I want to perform an one-sample, one sided t-test on each participants "dprime_mean" against mu = .15 and alternative = "greater". Without typing the same test down 48 (well for the moment twice) times.

I already tried:

pValues <- apply(signal_table, 1, function(x) t.test(x[14],
                            mu=0.15, alternative = "greater")$p.value)

But get the following error:

Error in t.test.default(x[14], mu = 0.15, alternative = "greater") : 
  not enough 'x' observations

What can I do? Can someone please help me and please be kind, I tried my best with this post :)

1 Answers1

1

When this runs:

pValues <- apply(signal_table, 1, function(x) t.test(x[14],
                            mu=0.15, alternative = "greater")$p.value)

the apply is going over rows and so x is a single row. You are picking out the 14th value of that row and running t.test on it. So it boils down to:

> t.test(1.2345,mu=0.15,alternative="greater")
Error in t.test.default(1.2345, mu = 0.15, alternative = "greater") : 
  not enough 'x' observations

To run a t-test you need a number of observations. You can't tell if 1.234 is greater than 0.15 without a number of observations in order to fit a distribution.

R can work with two numbers in a t-test, for example, if my measurements are 0.23 and 0.21, is this from a distribution with mean greater than 0.15?

> t.test(c(0.23,0.21), mu=0.15, alt="greater")

    One Sample t-test

data:  c(0.23, 0.21)
t = 7, df = 1, p-value = 0.04517
alternative hypothesis: true mean is greater than 0.15
95 percent confidence interval:
 0.1568625       Inf
sample estimates:
mean of x 
     0.22 

Yup, looks like it is. How about if my data is 0.14 and 0.16?

> t.test(c(0.14,0.16), mu=0.15, alt="greater")

    One Sample t-test

data:  c(0.14, 0.16)
t = 2.7756e-15, df = 1, p-value = 0.5
alternative hypothesis: true mean is greater than 0.15
95 percent confidence interval:
 0.08686248        Inf
sample estimates:
mean of x 
     0.15 

Hmmm maybe not, looking at those 95 percent confidence intervals.

In summary, the error is because you are feeding t.test with one single value, and I don't know why you think that is meaningful or what you really want to test...

Spacedman
  • 92,590
  • 12
  • 140
  • 224
  • Thank you so much! I calculated the mean of the observations per participant already for some other analysis. And thought I could use this in t.test. Apparently I just have to use my raw data instead of the already calculated mean. I think problem ist fixed :) – Lyra Hey Dec 29 '19 at 16:10