Chi square_check code

I am new to R and made this code earlier using janitor package but it seems janitor package does not work now and below code is not working. Is there alternate ways to run chisquare?

table1 <- DF %>%
select (final_included, caco, smoking) %>%
filter(final_included == 1, !is.na(smoking))%>%
tabyl(smoking, caco, sort = TRUE) #tabyl does not work as it works from janitor package
chisq.test(table1)

Thanks,

Best,
S

My general advice for you when requesting help in future, is to be specific as you can about 'how' things 'dont work' , error messages ? they should be quoted explicitly.
As you are a self-declared newbie to R, I have to ask whether you have remembered to load the janitor package before making use of its functions. This would look like

library(janitor)

I cannot install janitor package now. thats why tabyl function does not work. There might be other ways to create crosstab so that I can run chi-square test.

The documentation for tabyl gives an example where two options are selected from mtcars.
I've used this to see if the same chisq can be calculated without tably, but using base R only. it can

orig <- janitor::tabyl(mtcars, cyl, gear)

new <- table(subset(mtcars,select=c("cyl","gear")))

orig_chi <- janitor::chisq.test(orig)
new_chi <- stats::chisq.test(new)

orig_chi$statistic
new_chi$statistic 

identical(orig_chi$statistic,
          new_chi$statistic)

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.