0

I'm trying to run a t-test in R Studio and I keep coming back with this error -->

Error in t.test.default(x = subset(mydata$InfMort, subset = mydata$SubSahCountryvariable == : not enough 'x' observations

Here's the code -->

with(mydata, 
  t.test(x = subset(mydata$InfMort, subset = mydata$SubSahCountryvariable == 1), 
         y = subset(mydata$InfMort, subset = mydata$ArabCountryvariable == 1), 
         alternative = "two.sided"))

Anyone have any idea what's going on? I'm a beginner level in R.

camille
  • 16,432
  • 18
  • 38
  • 60
Fat Tiger
  • 27
  • 1
  • 7
  • Try `with(mydata, t.test(x = InfMort[SubSahCountryvariable == 1], y = InfMort[ArabCountryvariable == 1]))` it is possible that the one of them have different `length` compared to other – akrun Feb 25 '21 at 20:34
  • It's hard to know without having any of your data and thereby being able to run your code. [See here](https://stackoverflow.com/q/5963269/5325862) on making a reproducible example that is easier for folks to help with. – camille Feb 25 '21 at 20:36
  • If you just calculate the `x` value, i.e. `subset(mydata$InfMort, subset = mydata$SubSahCountryvariable == 1)`, what do you get? Similarly, what do you get for `y`? – user2554330 Feb 25 '21 at 20:38

1 Answers1

1

This is because you have less than the minimum number of observations in the first group, which is 2 observations. For example:

> t.test(c(1), c(3,4))
Error in t.test.default(c(1), c(3, 4)) : not enough 'x' observations
Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47