Python Forum
Enter Crosstab Data Directly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enter Crosstab Data Directly
#1
Hi: The best way I know to ask this is to ask if Python has a similar way of entering crosstab data directly using a count variable and use it in a crosstab analysis. Similar to the SAS "PROC FREQ" and "WEIGHT" statement. I find this useful when I only have the crosstab frequency data like from a textbook or study. Similar to below from SAS. Thanks.

data a;
input sick $ ate $ count;
cards;
yes yes 35
yes no 25
no yes 47
no no 61
;
proc freq data = a;
tables sick*ate/chisq agree;
weight count;
run;
Reply
#2
I did find this. So I'm satisfied for now. But if anyone has other suggestions, like making a nicer table, please say. Thanks.

from scipy import stats
obs = np.array([[61, 25], [47, 35]])
obs
chisq = chi2_stat, p_val, dof, ex = stats.chi2_contingency(obs, correction=False)
chisq
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to automate table creation with crosstab larryb 0 1,583 Jan-29-2020, 02:27 PM
Last Post: larryb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020