 # X and Y definition in t-test

Hello, I did an independent T-test with the variable of "sex and "Pknowledge". While the result is significant. I need to figure out which gender has higher Pknowledge.

While the t-test already showed the mean of x and y. I have no idea the definition of x and y is. I only knew male is defined as 1 and female is defined as 0.

The original data is imported from SPSS. So how do I know the definition of x and y in R?

Hi!

If you run `?t.test`, you will get to the documentation for t.test, there you will see that the first argument is `x` and the second argument is `y`. If you are in doubt, you can also always specify which one is which by using something like this: `t.test(x=group1, y=group2) `.

Besides this, it also seems like your are not using the function correctly. When using `t.test(x,y)`, you are comparing the mean of group x with the mean of group y. In your example, that means that you are comparing the mean of the variable `sex` with the mean `Pknowledge`, which is in no way a meaningful comparison.
In your second attempt you are doing it almost correct, the only mistake here is that you have the formula such as `variable ~ group`, in your case that would be `t.test(Pknowledge ~ Sex, data=nes200)`. If you use this form, the output will even be coded according to your grouping variable.

Many thanks for the clarification.
Can you elaborate about the part of t.test(x=group1, y=group2)? With this command, I can only rename t.test(x=sex,y=pknowledge) right? I can't rename the sex column with x=1,y=2 right?

It’s not really about renaming anything. In your example, you want to compare the political knowledge between the political knowledge between males and females and there are two ways to use the `t.test` function for such a comparison. The first way is to specify the two groups as `x` and ` y`. For this, you would need two vectors, one with the ´Pknowledge ´ Values for all males and one with all the values for the females. Assuming that those vectors are named `male` and `female`, you could use `t.test(x=male,y=female)`. This is what I meant when I gave the more generic example `t.test(x=group1, y=group2)`.

Does this make sense to you?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.