Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2x2 table and generating p-value for Chi-squared test?

    Hi, I am trying to create a table 1 for my research project. How do I generate a p-value for EACH of the rows (ie within each category, comparing the proportion of event 0 to proportion of event 1)? I am only able to generate the p-value for the chi-squared value for the entire table. Any guidance in this matter is appreciated. Thank you in advance.
    Click image for larger version

Name:	Chi Squared.PNG
Views:	1
Size:	9.8 KB
ID:	1472298



  • #2
    What's the test going to be? Of a null hypothesis of equal frequencies?

    Comment


    • #3
      Originally posted by Nick Cox View Post
      What's the test going to be? Of a null hypothesis of equal frequencies?
      Equal frequencies

      Comment


      • #4
        Is this what you want to do?

        Code:
        clear *
        input byte(cat event) N
        1 0 163
        1 1 10
        2 0 475
        2 1 59
        3 0 17
        3 1 1
        4 0 9
        4 1 1
        5 0 664
        5 1 71
        end
        
        * Overall cross-tab with row percentages
        expand N
        tabulate cat event if cat < 5, chi2 row
        * For each row (and the Total) perform a binomial test
        * and a Chi-square test of H0:  p(event)=0.5.
        forvalues c = 1/5 {
         bitest event == 0.5 if cat==`c'
         prtest event == 0.5 if cat==`c'
        }
        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 19.5 (Windows)

        Comment


        • #5
          Originally posted by Bruce Weaver View Post
          Is this what you want to do?
          I don't think so, because I'm not trying to compare them to a 50% chance. I am trying to compare them to each other with the null hypothesis of equal frequencies.

          Comment


          • #6
            Originally posted by Reza Zonozi View Post

            I don't think so, because I'm not trying to compare them to a 50% chance. I am trying to compare them to each other with the null hypothesis of equal frequencies.
            Let's take category 4 as an example. There are 10 observations in total. Under a null hypothesis of equal (expected) frequencies, there would be 5 events and 5 non-events. Under a null hypothesis stating p(event) = 0.5, there would also be 5 events and 5 non-events. They're the same. HTH.
            --
            Bruce Weaver
            Email: [email protected]
            Version: Stata/MP 19.5 (Windows)

            Comment


            • #7
              If you have only one category, you may "test" the proportion of, say, event = 1, against an "expected" proportion (in a given population, for example). Is this what you want?
              Best regards,

              Marcos

              Comment


              • #8
                To be honest, your hypothesis, as you stated in the original post, seems odd.

                How do I generate a p-value for EACH of the rows (ie within each category, comparing the proportion of event 0 to proportion of event 1)?
                This is not how chi-square tests are usually set up. You usually see them set up in two by two tables. They can be set up in n-by-two, or even n-by-m tables. You seem to be talking about something like a 1-by-2 table. This seems odd to me. Maybe others have seen this...

                Originally posted by Reza Zonozi View Post

                I don't think so, because I'm not trying to compare them to a 50% chance. I am trying to compare them to each other with the null hypothesis of equal frequencies.
                It seems like there may be some communication difficulty here, because elsewhere, Nick asked you:

                What's the test going to be? Of a null hypothesis of equal frequencies?
                ANd you replied

                Equal frequencies
                Either way, please clarify what you're trying to do. It is completely legitimate to run a chi-square test on a 4x2 table. IIRC, the null there is that the row variable and the column variable are independent. That would imply equal proportions of the event in each category of your first variable (equal within the bounds of sampling variation).

                A side note is that with some sparse cells (you have <5 cases with the event in categories 3 and 4), I think most people would recommend using Fisher's exact test.
                Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

                When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

                Comment

                Working...
                X