Chi-square test code

Hi, I have being trying to do the Pearson's Chisquare on my research data i have failed, anyone to help me run the test?

Please give examples of your data, what you have tried and what happened. You can post data using the output of the dput() function. For example

dput(head(MyData, 20))

will provide output of the first 20 elements or rows of MyData. Post that output here between lines with three back ticks, like this
```
Output of dput()
```

I want to do the Chi-square test on this data

> dput(head(Questionnaire, 20))
structure(list(Sex = structure(c(1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 
1, 2, 1, 1, 1, 1, 1, 1, 1, 1), label = "Sex of HH head", format.spss = "F8.0", labels = c(Male = 1, 
Female = 2), class = c("haven_labelled", "vctrs_vctr", "double"
)), Occupation = structure(c(2, 1, 1, 1, 1, 4, 4, 1, 3, 1, 1, 
1, 1, 2, 1, 1, 1, 1, 1, 1), label = "Occupation of HH head", format.spss = "F8.0", labels = c(Farming = 1, 
Fishing = 2, Other = 3, Formal = 4), class = c("haven_labelled", 
"vctrs_vctr", "double")), Age = structure(c(57, 56, 41, 30, 32, 
60, 32, 45, 30, 36, 67, 70, 42, 45, 20, 24, 37, 65, 55, 30), label = "Age", format.spss = "F8.0", labels = c(`no response` = 999), class = c("haven_labelled", 
"vctrs_vctr", "double")), Marito_status = structure(c(1, 1, 1, 
1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1), label = "Marital status?", format.spss = "F8.0", labels = c(Married = 1, 
Single = 2, Other = 3), class = c("haven_labelled", "vctrs_vctr", 
"double")), Education = structure(c("4", "7", "5", "4", "3", 
"12", "0", "4", "4", "7", "2", "0", "6", "3", "7", "3", "7", 
"5", "5", "2"), label = "Level of education?", format.spss = "A2"), 
    No_persons = structure(c(12, 9, 9, 6, 9, 6, 3, 7, 8, 10, 
    9, 1, 5, 8, 4, 3, 5, 8, 10, 6), label = "Number of persons?", format.spss = "F8.0"), 
    D_hse = structure(c(1, 1, 1, 4, 4, 4, 1, 1, 4, 1, 1, 1, 1, 
    1, 1, 1, 1, 4, 1, 1), label = "Main dwelling house?", format.spss = "F8.0", labels = c(`Ordinary hut` = 1, 
    `Iron roofed mud and wattle` = 2, Others = 3, `Brick house with iron roof` = 4
    ), class = c("haven_labelled", "vctrs_vctr", "double")), 
    lat_important = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1), label = "Is construction of a latrine important?", format.spss = "F8.0", labels = c(Yes = 1, 
    No = 2), class = c("haven_labelled", "vctrs_vctr", "double"
    )), bene_lat = structure(c(1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1), label = "Benefits of using a toilet?", format.spss = "F8.0", labels = c(`Prevent diseases` = 1, 
    `Good hygiene` = 2, Other = 3, Privacy = 4, None = 5), class = c("haven_labelled", 
    "vctrs_vctr", "double")), no_lat = structure(c(1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), label = "Do you think not having a toilet can cause disease?", format.spss = "F8.0", labels = c(Yes = 1, 
    No = 2, Other = 3), class = c("haven_labelled", "vctrs_vctr", 
    "double")), toilet = structure(c(1, 1, 1, 1, 1, 1, 2, 1, 
    2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1), label = "Do you have a toilet?", format.spss = "F8.0", labels = c(Yes = 1, 
    No = 2), class = c("haven_labelled", "vctrs_vctr", "double"
    )), if_yes = structure(c("prevention of disease", "prevention of disease", 
    "prevention of disease", "to prevent diseases and avoidance of dirty", 
    "to prevent diseases", "to prevent diseases", NA, " for putting rubbish", 
    NA, "to prevent diseases", "to prevent diseases", "to prevent diseases", 
    "to prevent diseases", "to live healthy", NA, "to prevent different diseases", 
    "to prevent diseases", "to prevent cholera", "to prevent diseases", 
    "to prevent cholera"), label = "If yes, what made you construct one?", format.spss = "A53", display_width = 14L, labels = c(`Not applicable` = "888                                     rxw\fÝ5"), class = c("haven_labelled", 
    "vctrs_vctr", "character")), why_not = structure(c(NA, NA, 
    NA, NA, NA, NA, "no space to construct another", NA, "it is full", 
    NA, NA, NA, NA, NA, "it collapsed", NA, NA, NA, NA, NA), label = "why dont you have a toilet?", format.spss = "A29"), 
    use = structure(c(NA, NA, NA, NA, NA, NA, "neighbour", NA, 
    "neighbour", NA, NA, NA, NA, NA, "neighbour", NA, NA, NA, 
    NA, NA), label = "What then do you use?", format.spss = "A9", labels = c(`Not applicable` = "888"), class = c("haven_labelled", 
    "vctrs_vctr", "character")), adequacy = structure(c(3, 2, 
    5, 5, 5, 5, NA, 5, NA, 5, 5, 4, 4, 4, NA, 4, 4, 4, 4, 4), label = "Does your toilet have adequacy?", format.spss = "F8.0", labels = c(`Yes 1/4` = 1, 
    `Yes 2/4` = 2, `Yes 3/4` = 3, `Yes 4/4` = 4, None = 5, `Not applicable` = 888
    ), class = c("haven_labelled", "vctrs_vctr", "double")), 
    use_toilet = structure(c(1, 1, 1, 1, 1, 1, NA, 1, NA, 1, 
    1, 1, 1, 1, NA, 1, 1, 1, 1, 1), label = "Is your toilet in use?", format.spss = "F8.0", labels = c(Yes = 1, 
    No = 2, Other = 3, `Not applicable` = 888), class = c("haven_labelled", 
    "vctrs_vctr", "double")), comf_use = structure(c(1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), label = "Do you feel comfortable using a toilet?", format.spss = "F8.0", labels = c(Yes = 1, 
    No = 2, Other = 3), class = c("haven_labelled", "vctrs_vctr", 
    "double")), who_build = structure(c(1, 1, 1, 1, 1, 1, 1, 
    5, 1, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5), label = "Who do you think should build you a toilet?", format.spss = "F8.0", labels = c(Self = 1, 
    Government = 2, Other = 3, Community = 4, `Don't know` = 5
    ), class = c("haven_labelled", "vctrs_vctr", "double")), 
    nec_pro = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, 1), label = "Do you think it is necessary to have a program?", format.spss = "F8.0", labels = c(Yes = 1, 
    No = 2, Other = 3), class = c("haven_labelled", "vctrs_vctr", 
    "double")), heard_clts = structure(c(1, 1, 1, 1, 1, 1, 2, 
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1), label = "Have you heard about CLTS?", format.spss = "F8.0", labels = c(Yes = 1, 
    No = 2, Other = 3), class = c("haven_labelled", "vctrs_vctr", 
    "double")), what_clts = structure(c("proper sanitation", 
    "what we know is that a household can have diseases", "people defecate anywhere", 
    "having toilets is good", "none", "prevention of diseases", 
    NA, "after using the toilet we should wash ha", "washing of hands after using the toilet", 
    "no answer", "clts is very important", "cleanliness is good", 
    "sanitation is good", "sanitation is good for prevention of diseases", 
    "proper sanitation thru construction of toilets", "clts is very important to people", 
    "clts is very important to people", "clts is very important", 
    NA, "no answer"), label = "What do you know about CLTS", format.spss = "A56"), 
    who_clts = structure(c(2, 2, 1, 2, 4, 2, NA, 2, 4, 4, 2, 
    2, 2, 2, 4, 4, 4, 4, NA, 4), label = "Who told you about CLTS?", format.spss = "F8.0", labels = c(`Traditional leader` = 1, 
    `Health worker` = 2, Other = 3, `Community champion` = 4, 
    `Not applicable` = 888), class = c("haven_labelled", "vctrs_vctr", 
    "double")), how_long = structure(c("6 years", "3 years", 
    "4 years", "2 months", "unknown", "unknown", NA, "2 years", 
    "2 years", "unknown", "3 months", "2 months", "5 years", 
    "6 years", "3 years", "3 years", "1 year", "2 years", NA, 
    "3 years"), label = "For how long have you heard about CLTS?", format.spss = "A8", labels = c(`Not applicable` = "888"), class = c("haven_labelled", 
    "vctrs_vctr", "character")), des_pro = structure(c(3, 3, 
    3, 3, 3, 2, NA, 2, 2, 2, 3, 2, 3, 2, 2, 2, 2, 2, NA, 2), label = "Describe the way the program is working?", format.spss = "F8.0", labels = c(Bad = 1, 
    Fair = 2, Good = 3, `Not applicable` = 888), class = c("haven_labelled", 
    "vctrs_vctr", "double")), any_term = structure(c(2, 1, 1, 
    1, 2, 1, NA, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, NA, 2), label = "Any concerns with the terms used in CLTS?", format.spss = "F8.0", labels = c(Yes = 1, 
    No = 2, Other = 3, `Not applicable` = 888), class = c("haven_labelled", 
    "vctrs_vctr", "double")), any_imp = structure(c(1, 2, 2, 
    1, 2, 1, NA, 2, 2, 1, 1, 1, 2, 2, 2, 1, 2, 2, NA, 2), label = "Any concerns with program implementation?", format.spss = "F8.0", labels = c(Yes = 1, 
    No = 2, Other = 3, `Not applicable` = 888), class = c("haven_labelled", 
    "vctrs_vctr", "double")), gra_pro = structure(c(2, 3, 2, 
    1, 2, 1, NA, 1, 1, 1, 3, 1, 3, 1, 1, 2, 2, 3, NA, 3), label = "Grade the program?", format.spss = "F8.0", labels = c(`1 - 2` = 1, 
    `3 - 4` = 2, `5 - 6` = 3, `7 - 8` = 4, `9 - 10` = 5, `Not applicable` = 888
    ), class = c("haven_labelled", "vctrs_vctr", "double")), 
    wud_pro = structure(c("involvement of CCs and members", "involvement of traditional leaders", 
    "members of community working with headman", "involvement of headmen and the members", 
    "traditional leaders working with community", "involvement of CCs and members", 
    NA, "members and headmen working together", "involvement of chiefs and headmen, ehts", 
    "a house without sanitation will have diseases", "involvement of traditional leader and member", 
    "no answer", "involvement of member working traditional leaders", 
    "involvement of headmen and CCs", "involvement of traditional leaders", 
    "headmen and community members working together", "involvement of the president working with health worker", 
    "community members", NA, "CCs and members working together"
    ), label = "What would you like the program to improve on?", format.spss = "A55", display_width = 14L), 
    what_made = structure(c(2, 1, 1, 2, 2, 2, NA, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 1, 1, NA, 1), label = "What made you decide to start using a latrine?", format.spss = "F8.0", labels = c(`To avoid disease` = 1, 
    `Good hygiene` = 2, `Was advised to` = 3, `Don't know` = 4, 
    `Not applicable` = 888), class = c("haven_labelled", "vctrs_vctr", 
    "double")), how_lon = structure(c(1, 1, 2, 2, 1, 1, NA, 1, 
    2, 1, 1, 1, 1, 1, 2, 2, 2, 2, NA, 2), label = "How long to you intend to use your latrine?", format.spss = "F8.0", labels = c(`Short term` = 1, 
    `Long term` = 2, `Not sure` = 3, `Not applicable` = 888), class = c("haven_labelled", 
    "vctrs_vctr", "double")), use_when = structure(c(1, 1, 1, 
    1, 1, 1, NA, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, NA, 2), label = "What will you use when your toilet collapses or is full?", format.spss = "F8.0", labels = c(`Construct another one` = 1, 
    `Use neighbours` = 2, `Use the bush` = 3, `Don't know` = 4, 
    `Not applicable` = 888), class = c("haven_labelled", "vctrs_vctr", 
    "double")), not_chan = structure(c("things have changed unlike in the past", 
    "reduction in going to the bush and diseases", "reduction of diseases", 
    "breathing of fresh air", "we should all have toilets", "a house with toilet doesn't have diseases", 
    NA, "no toilets result in unsanitary condition", "children don't defecate anyhow", 
    "no unsanitary conditions at households", "we used to get snake bites and diseases", 
    "a house without toilet will have disease", "flies don't sit on food as much", 
    "if we don't have toilets we get difficulties", "no diseases when you have a toilet", 
    "no answer", "no answer", "no answer", NA, "no answer"), label = "Have you noticed any changes?", format.spss = "A48", display_width = 14L), 
    res_sex = structure(c(1, 1, 1, 2, 1, 2, 2, 2, 2, 1, 2, 2, 
    2, 1, 2, 2, 1, 1, 1, 2), label = "Sex of respondent?", format.spss = "F8.0", labels = c(Male = 1, 
    Female = 2), class = c("haven_labelled", "vctrs_vctr", "double"
    )), CLTS_adequacy = structure(c(0, 0, 0, 0, 0, 0, 888, 0, 
    888, 0, 0, 1, 1, 1, 888, 1, 1, 1, 1, 1), label = "CLTS adequacy", format.spss = "F8.0", display_width = 15L)), row.names = c(NA, 
-20L), class = c("tbl_df", "tbl", "data.frame"))

This topic was automatically closed 21 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.